Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#931 from michaelheyvaert/fix-cronj…
Browse files Browse the repository at this point in the history
…ob-projected-volume-namerefs

fix configmap/secret name references for cronjobs with projected volumes
  • Loading branch information
k8s-ci-robot authored Mar 29, 2019
2 parents c3700e0 + 4848987 commit 42d9287
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/transformers/config/defaultconfig/namereference.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ nameReference:
kind: Job
- path: spec/jobTemplate/spec/template/spec/volumes/configMap/name
kind: CronJob
- path: spec/jobTemplate/spec/template/spec/volumes/projected/sources/configMap/name
kind: CronJob
- path: spec/jobTemplate/spec/template/spec/containers/env/valueFrom/configMapKeyRef/name
kind: CronJob
- path: spec/jobTemplate/spec/template/spec/initContainers/env/valueFrom/configMapKeyRef/name
Expand Down Expand Up @@ -204,6 +206,8 @@ nameReference:
kind: Job
- path: spec/jobTemplate/spec/template/spec/volumes/secret/secretName
kind: CronJob
- path: spec/jobTemplate/spec/template/spec/volumes/projected/sources/secret/name
kind: CronJob
- path: spec/jobTemplate/spec/template/spec/containers/env/valueFrom/secretKeyRef/name
kind: CronJob
- path: spec/jobTemplate/spec/template/spec/initContainers/env/valueFrom/secretKeyRef/name
Expand Down
74 changes: 74 additions & 0 deletions pkg/transformers/namereference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,43 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
}),
resid.NewResId(cronjob, "cronjob1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "batch/v1beta1",
"kind": "CronJob",
"metadata": map[string]interface{}{
"name": "cronjob1",
},
"spec": map[string]interface{}{
"schedule": "0 14 * * *",
"jobTemplate": map[string]interface{}{
"spec": map[string]interface{}{
"template": map[string]interface{}{
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"name": "main",
"image": "myimage",
},
},
"volumes": map[string]interface{}{
"projected": map[string]interface{}{
"sources": map[string]interface{}{
"configMap": map[string]interface{}{
"name": "cm2",
},
"secret": map[string]interface{}{
"name": "secret1",
},
},
},
},
},
},
},
},
},
}),
}

expected := resmap.ResMap{}
Expand Down Expand Up @@ -417,6 +454,43 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
})
expected[resid.NewResId(cronjob, "cronjob1")] = rf.FromMap(
map[string]interface{}{
"apiVersion": "batch/v1beta1",
"kind": "CronJob",
"metadata": map[string]interface{}{
"name": "cronjob1",
},
"spec": map[string]interface{}{
"schedule": "0 14 * * *",
"jobTemplate": map[string]interface{}{
"spec": map[string]interface{}{
"template": map[string]interface{}{
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"name": "main",
"image": "myimage",
},
},
"volumes": map[string]interface{}{
"projected": map[string]interface{}{
"sources": map[string]interface{}{
"configMap": map[string]interface{}{
"name": "someprefix-cm2-somehash",
},
"secret": map[string]interface{}{
"name": "someprefix-secret1-somehash",
},
},
},
},
},
},
},
},
},
})
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
err := nrt.Transform(m)
if err != nil {
Expand Down

0 comments on commit 42d9287

Please sign in to comment.