Skip to content

Commit

Permalink
Add support for docker registry secret
Browse files Browse the repository at this point in the history
This allows OCI registries to inherit configuration from the configured docker-registry secret

Signed-off-by: Shaun Becker <[email protected]>
  • Loading branch information
smbecker authored and brandond committed Jun 28, 2023
1 parent fcb8db8 commit 9f2eeec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/apis/helm.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ type HelmChartSpec struct {
FailurePolicy string `json:"failurePolicy,omitempty"`
AuthSecret *corev1.LocalObjectReference `json:"authSecret,omitempty"`

AuthPassCredentials bool `json:"authPassCredentials,omitempty"`
AuthPassCredentials bool `json:"authPassCredentials,omitempty"`
DockerRegistrySecret *corev1.LocalObjectReference `json:"dockerRegistrySecret,omitempty"`
}

type HelmChartStatus struct {
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/helm.cattle.io/v1/zz_generated_deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions pkg/controllers/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ func job(chart *v1.HelmChart) (*batch.Job, *corev1.Secret, *corev1.ConfigMap) {

setProxyEnv(job)
setAuthSecret(job, chart)
setDockerRegistrySecret(job, chart)
setRepoCAConfigMap(job, chart)
valuesSecret := setValuesSecret(job, chart)
contentConfigMap := setContentConfigMap(job, chart)
Expand Down Expand Up @@ -746,6 +747,28 @@ func setAuthSecret(job *batch.Job, chart *v1.HelmChart) {
}
}

func setDockerRegistrySecret(job *batch.Job, chart *v1.HelmChart) {
if secret := chart.Spec.DockerRegistrySecret; secret != nil {
job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes, corev1.Volume{
Name: "dockerconfig",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: secret.Name,
Items: []corev1.KeyToPath{{
Key: ".dockerconfigjson",
Path: "config.json",
}},
},
},
})

job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
MountPath: "/home/klipper-helm/.docker",
Name: "dockerconfig",
})
}
}

func setRepoCAConfigMap(job *batch.Job, chart *v1.HelmChart) {
if cm := chart.Spec.RepoCAConfigMap; cm != nil {
job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes, corev1.Volume{
Expand Down

0 comments on commit 9f2eeec

Please sign in to comment.