Skip to content

Commit

Permalink
Fix bugs in insecure registries for kaniko
Browse files Browse the repository at this point in the history
This PR:

1. Passes in the `--insecure-registry` flag to kaniko, which allows for
insecure image pull and pushes

2. Updates the kaniko image to one that incorporates this bug fix in
kaniko: GoogleContainerTools/kaniko#685. This
bug fix is required for insecure registries to work with caching in
kaniko.
  • Loading branch information
Priya Wadhwa committed Oct 2, 2019
1 parent 8e42805 commit 1b44493
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
8 changes: 6 additions & 2 deletions pkg/skaffold/build/cluster/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (b *Builder) runKanikoBuild(ctx context.Context, out io.Writer, artifact *l
}
defer s.Cleanup(ctx)

args, err := args(artifact.KanikoArtifact, context, tag)
args, err := args(artifact.KanikoArtifact, context, tag, b.insecureRegistries)
if err != nil {
return "", errors.Wrap(err, "building args list")
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func (b *Builder) runKanikoBuild(ctx context.Context, out io.Writer, artifact *l
return docker.RemoteDigest(tag, b.insecureRegistries)
}

func args(artifact *latest.KanikoArtifact, context, tag string) ([]string, error) {
func args(artifact *latest.KanikoArtifact, context, tag string, insecureRegistries map[string]bool) ([]string, error) {
// Create pod spec
args := []string{
"--dockerfile", artifact.DockerfilePath,
Expand Down Expand Up @@ -139,5 +139,9 @@ func args(artifact *latest.KanikoArtifact, context, tag string) ([]string, error
args = append(args, "--reproducible")
}

for reg := range insecureRegistries {
args = append(args, "--insecure-registry", reg)
}

return args, nil
}
19 changes: 14 additions & 5 deletions pkg/skaffold/build/cluster/kaniko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import (

func TestArgs(t *testing.T) {
tests := []struct {
description string
artifact *latest.KanikoArtifact
shouldErr bool
expectedArgs []string
description string
artifact *latest.KanikoArtifact
insecureRegistries map[string]bool
shouldErr bool
expectedArgs []string
}{
{
description: "simple build",
Expand Down Expand Up @@ -104,12 +105,20 @@ func TestArgs(t *testing.T) {
},
shouldErr: true,
},
{
description: "insecure registries",
artifact: &latest.KanikoArtifact{
DockerfilePath: "Dockerfile",
},
insecureRegistries: map[string]bool{"localhost:4000": true, "localhost:5000": true},
expectedArgs: []string{"--insecure-registry", "localhost:4000", "--insecure-registry", "localhost:5000"},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
commonArgs := []string{"--dockerfile", "Dockerfile", "--context", "context", "--destination", "tag", "-v", "info"}

args, err := args(test.artifact, "context", "tag")
args, err := args(test.artifact, "context", "tag", test.insecureRegistries)

t.CheckError(test.shouldErr, err)
if !test.shouldErr {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (

DefaultKustomizationPath = "."

DefaultKanikoImage = "gcr.io/kaniko-project/executor:v0.10.0@sha256:78d44ec4e9cb5545d7f85c1924695c89503ded86a59f92c7ae658afa3cff5400"
DefaultKanikoImage = "gcr.io/kaniko-project/executor:4ce8b8db817047f0be7a78c0fdffab71f797e8f8@sha256:fe1b5a428273309088fb6df563f4d88ab806fe602a7b0b3e8fbe1d7ee5f9ead0"
DefaultKanikoSecretName = "kaniko-secret"
DefaultKanikoTimeout = "20m"
DefaultKanikoContainerName = "kaniko"
Expand Down

0 comments on commit 1b44493

Please sign in to comment.