From ae33ce93b8eef9c1f71ad2ea8c7372af9c35750a Mon Sep 17 00:00:00 2001 From: Raghav Date: Wed, 9 Jul 2025 16:03:56 +0530 Subject: [PATCH] feat: [CI-17953]: Add warning if base image connector is not provided (#152) * [CI-17953]: Add warning if base image connector is not provided * [CI-17953]: Add warning if base image connector is not provided * [CI-17953]: Add warning if base image connector is not provided --- cmd/kaniko-acr/main.go | 19 ++++++++++++------- cmd/kaniko-acr/main_test.go | 2 +- cmd/kaniko-docker/main.go | 4 ++++ cmd/kaniko-ecr/main.go | 3 +++ cmd/kaniko-ecr/main_test.go | 2 +- cmd/kaniko-gar/main.go | 3 +++ cmd/kaniko-gcr/main.go | 11 +++++++---- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/cmd/kaniko-acr/main.go b/cmd/kaniko-acr/main.go index cd2d5fa..72dee4d 100644 --- a/cmd/kaniko-acr/main.go +++ b/cmd/kaniko-acr/main.go @@ -711,15 +711,20 @@ func setDockerAuth(username, password, registry, dockerUsername, dockerPassword, Password: password, } - pullFromRegistryCreds := docker.RegistryCredentials{ - Registry: dockerRegistry, - Username: dockerUsername, - Password: dockerPassword, + credentials := []docker.RegistryCredentials{pushToRegistryCreds} + + if dockerRegistry != "" { + pullFromRegistryCreds := docker.RegistryCredentials{ + Registry: dockerRegistry, + Username: dockerUsername, + Password: dockerPassword, + } + credentials = append(credentials, pullFromRegistryCreds) + } else { + fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" + + "\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m") } - - credentials := []docker.RegistryCredentials{pushToRegistryCreds, pullFromRegistryCreds} return dockerConfig.CreateDockerConfig(credentials, dockerConfigPath) - } func encodeParam(s string) string { diff --git a/cmd/kaniko-acr/main_test.go b/cmd/kaniko-acr/main_test.go index e8b62e0..887afa2 100644 --- a/cmd/kaniko-acr/main_test.go +++ b/cmd/kaniko-acr/main_test.go @@ -153,4 +153,4 @@ func TestCreateDockerConfigWithoutBaseRegistry(t *testing.T) { // Check if the public Docker Hub auth is not set _, exists := config.Auths[""] assert.False(t, exists) -} \ No newline at end of file +} diff --git a/cmd/kaniko-docker/main.go b/cmd/kaniko-docker/main.go index 2abf53c..9b966fb 100644 --- a/cmd/kaniko-docker/main.go +++ b/cmd/kaniko-docker/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" "strings" @@ -508,6 +509,9 @@ func setDockerAuth(username, password, registry, baseImageUsername, baseImagePas Password: baseImagePassword, } credentials = append(credentials, pullFromRegistryCreds) + } else { + fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" + + "\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m") } // Creates docker config for both the regustries used for authentication return dockerConfig.CreateDockerConfig(credentials, dockerPath) diff --git a/cmd/kaniko-ecr/main.go b/cmd/kaniko-ecr/main.go index 1f37f8e..8693ebe 100644 --- a/cmd/kaniko-ecr/main.go +++ b/cmd/kaniko-ecr/main.go @@ -585,6 +585,9 @@ func setDockerAuth(dockerRegistry, dockerUsername, dockerPassword, accessKey, se Password: dockerPassword, } credentials = append(credentials, pullFromRegistryCreds) + } else { + fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" + + "\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m") } if assumeRole != "" && oidcToken != "" { diff --git a/cmd/kaniko-ecr/main_test.go b/cmd/kaniko-ecr/main_test.go index bc103f1..2714b2d 100644 --- a/cmd/kaniko-ecr/main_test.go +++ b/cmd/kaniko-ecr/main_test.go @@ -42,4 +42,4 @@ func TestCreateDockerConfigForECRWithBaseRegistry(t *testing.T) { expectedDockerAuth := docker.Auth{Auth: base64.StdEncoding.EncodeToString([]byte(dockerUsername + ":" + dockerPassword))} assert.Equal(t, expectedDockerAuth, config.Auths[dockerRegistry]) -} \ No newline at end of file +} diff --git a/cmd/kaniko-gar/main.go b/cmd/kaniko-gar/main.go index 9c53f55..29c8559 100644 --- a/cmd/kaniko-gar/main.go +++ b/cmd/kaniko-gar/main.go @@ -384,6 +384,9 @@ func run(c *cli.Context) error { ); err != nil { return errors.Wrap(err, "failed to create docker config") } + } else { + fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" + + "\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m") } } diff --git a/cmd/kaniko-gcr/main.go b/cmd/kaniko-gcr/main.go index 83b94c5..3eb44b7 100644 --- a/cmd/kaniko-gcr/main.go +++ b/cmd/kaniko-gcr/main.go @@ -18,8 +18,8 @@ import ( const ( dockerConfigPath string = "/kaniko/.docker" // GCR JSON key file path - gcrKeyPath string = "/kaniko/config.json" - gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS" + gcrKeyPath string = "/kaniko/config.json" + gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS" defaultDigestFile string = "/kaniko/digest-file" ) @@ -353,7 +353,7 @@ func run(c *cli.Context) error { } // setup docker config only when base image registry is specified - if c.String("base-image-registry") != ""{ + if c.String("base-image-registry") != "" { if err := setDockerAuth( c.String("base-image-username"), c.String("base-image-password"), @@ -361,6 +361,9 @@ func run(c *cli.Context) error { ); err != nil { return errors.Wrap(err, "failed to create docker config") } + } else { + fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" + + "\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m") } } @@ -439,7 +442,7 @@ func run(c *cli.Context) error { return plugin.Exec() } -func setDockerAuth(dockerUsername, dockerPassword, dockerRegistry string) (error) { +func setDockerAuth(dockerUsername, dockerPassword, dockerRegistry string) error { dockerConfig := docker.NewConfig() dockerRegistryCreds := docker.RegistryCredentials{ Registry: dockerRegistry,