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

feat: implement kaniko.imagePullSecret for pulling images from private registry w/ auth #9191

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions pkg/skaffold/build/cluster/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func (b *Builder) kanikoPodSpec(artifact *latest.KanikoArtifact, tag string, pla
addSecretVolume(pod, kaniko.DefaultSecretName, b.ClusterDetails.PullSecretMountPath, b.ClusterDetails.PullSecretName)
}

// Add secret for pulling kaniko images from a private registry
alphanota marked this conversation as resolved.
Show resolved Hide resolved
if artifact.ImagePullSecret != "" {
pod.Spec.ImagePullSecrets = []v1.LocalObjectReference{{
Name: artifact.ImagePullSecret,
}}
}

// Add host path volume for cache
if artifact.Cache != nil && artifact.Cache.HostPath != "" {
addHostPathVolume(pod, kaniko.DefaultCacheDirName, kaniko.DefaultCacheDirMountPath, artifact.Cache.HostPath)
Expand Down
10 changes: 7 additions & 3 deletions pkg/skaffold/build/cluster/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ func TestKanikoArgs(t *testing.T) {

func TestKanikoPodSpec(t *testing.T) {
artifact := &latest.KanikoArtifact{
Image: "image",
DockerfilePath: "Dockerfile",
InitImage: "init/image",
Image: "image",
DockerfilePath: "Dockerfile",
InitImage: "init/image",
ImagePullSecret: "image-pull-secret",
Destination: []string{
"gcr.io/foo/bar:test-1",
"gcr.io/foo/bar:test-2",
Expand Down Expand Up @@ -353,6 +354,9 @@ func TestKanikoPodSpec(t *testing.T) {
},
},
}},
ImagePullSecrets: []v1.LocalObjectReference{{
Name: "image-pull-secret",
}},
ServiceAccountName: "aVerySpecialSA",
SecurityContext: &v1.PodSecurityContext{
RunAsUser: &runAsUser,
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,9 @@ type KanikoArtifact struct {
// Defaults to the latest released version of `gcr.io/kaniko-project/executor`.
Image string `yaml:"image,omitempty"`

// ImagePullSecret is the name of the Kubernetes secret for pulling kaniko image and kaniko init image from a private registry
ImagePullSecret string `yaml:"imagePullSecret,omitempty"`

// Destination is additional tags to push.
Destination []string `yaml:"destination,omitempty"`

Expand Down
Loading