Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to empty secret path for Kaniko to use Workload Identity credentials #5730

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pkg/skaffold/build/cluster/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,7 @@ func (b *Builder) kanikoPodSpec(artifact *latest_v1.KanikoArtifact, tag string)
}

func (b *Builder) env(artifact *latest_v1.KanikoArtifact, httpProxy, httpsProxy string) []v1.EnvVar {
pullSecretPath := strings.Join(
[]string{b.ClusterDetails.PullSecretMountPath, b.ClusterDetails.PullSecretPath},
"/", // linux filepath separator.
)
env := []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: pullSecretPath,
}, {
// This should be same https://github.com/GoogleContainerTools/kaniko/blob/77cfb912f3483c204bfd09e1ada44fd200b15a78/pkg/executor/push.go#L49
Name: "UPSTREAM_CLIENT_TYPE",
Value: fmt.Sprintf("UpstreamClient(skaffold-%s)", version.Get().Version),
Expand All @@ -155,6 +148,18 @@ func (b *Builder) env(artifact *latest_v1.KanikoArtifact, httpProxy, httpsProxy
})
}

// if cluster.PullSecretName is non-empty populate secret path and use as GOOGLE_APPLICATION_CREDENTIALS
tejal29 marked this conversation as resolved.
Show resolved Hide resolved
// by default it is not empty, so need to
if b.ClusterDetails.PullSecretName != "" {
pullSecretPath := strings.Join(
[]string{b.ClusterDetails.PullSecretMountPath, b.ClusterDetails.PullSecretPath},
"/", // linux filepath separator.
)
env = append(env, v1.EnvVar{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: pullSecretPath,
})
}
return env
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/build/cluster/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,6 @@ func TestKanikoPodSpec(t *testing.T) {
Args: []string{"--dockerfile", "Dockerfile", "--context", "dir:///kaniko/buildcontext", "--destination", "tag", "-v", "info"},
ImagePullPolicy: v1.PullIfNotPresent,
Env: []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret.json",
}, {
Name: "UPSTREAM_CLIENT_TYPE",
Value: "UpstreamClient(skaffold-)",
}, {
Expand All @@ -297,6 +294,9 @@ func TestKanikoPodSpec(t *testing.T) {
}, {
Name: "HTTPS_PROXY",
Value: "https://proxy",
}, {
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret.json",
}},
VolumeMounts: []v1.VolumeMount{
{
Expand Down