Skip to content

Commit

Permalink
fix(substition): fix configmap and secret volume param substition
Browse files Browse the repository at this point in the history
  • Loading branch information
FogDong committed Aug 7, 2020
1 parent 3a7a693 commit 1a46f98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/reconciler/taskrun/resources/apply.go
Expand Up @@ -171,9 +171,17 @@ func ApplyReplacements(spec *v1beta1.TaskSpec, stringReplacements map[string]str
spec.Volumes[i].Name = substitution.ApplyReplacements(v.Name, stringReplacements)
if v.VolumeSource.ConfigMap != nil {
spec.Volumes[i].ConfigMap.Name = substitution.ApplyReplacements(v.ConfigMap.Name, stringReplacements)
for index, item := range v.ConfigMap.Items {
spec.Volumes[i].ConfigMap.Items[index].Key = substitution.ApplyReplacements(item.Key, stringReplacements)
spec.Volumes[i].ConfigMap.Items[index].Path = substitution.ApplyReplacements(item.Path, stringReplacements)
}
}
if v.VolumeSource.Secret != nil {
spec.Volumes[i].Secret.SecretName = substitution.ApplyReplacements(v.Secret.SecretName, stringReplacements)
for index, item := range v.Secret.Items {
spec.Volumes[i].Secret.Items[index].Key = substitution.ApplyReplacements(item.Key, stringReplacements)
spec.Volumes[i].Secret.Items[index].Path = substitution.ApplyReplacements(item.Path, stringReplacements)
}
}
if v.PersistentVolumeClaim != nil {
spec.Volumes[i].PersistentVolumeClaim.ClaimName = substitution.ApplyReplacements(v.PersistentVolumeClaim.ClaimName, stringReplacements)
Expand Down
12 changes: 12 additions & 0 deletions pkg/reconciler/taskrun/resources/apply_test.go
Expand Up @@ -143,13 +143,21 @@ var (
LocalObjectReference: corev1.LocalObjectReference{
Name: "$(inputs.params.FOO)",
},
Items: []corev1.KeyToPath{{
Key: "$(inputs.params.FOO)",
Path: "$(inputs.params.FOO)",
}},
},
},
}, {
Name: "some-secret",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "$(inputs.params.FOO)",
Items: []corev1.KeyToPath{{
Key: "$(inputs.params.FOO)",
Path: "$(inputs.params.FOO)",
}},
},
},
}, {
Expand Down Expand Up @@ -546,7 +554,11 @@ func TestApplyParameters(t *testing.T) {

spec.Volumes[0].Name = "world"
spec.Volumes[0].VolumeSource.ConfigMap.LocalObjectReference.Name = "world"
spec.Volumes[0].VolumeSource.ConfigMap.Items[0].Key = "world"
spec.Volumes[0].VolumeSource.ConfigMap.Items[0].Path = "world"
spec.Volumes[1].VolumeSource.Secret.SecretName = "world"
spec.Volumes[1].VolumeSource.Secret.Items[0].Key = "world"
spec.Volumes[1].VolumeSource.Secret.Items[0].Path = "world"
spec.Volumes[2].VolumeSource.PersistentVolumeClaim.ClaimName = "world"
spec.Volumes[3].VolumeSource.Projected.Sources[0].ConfigMap.Name = "world"
spec.Volumes[3].VolumeSource.Projected.Sources[0].Secret.Name = "world"
Expand Down

0 comments on commit 1a46f98

Please sign in to comment.