diff --git a/api/filters/imagetag/imagetag_test.go b/api/filters/imagetag/imagetag_test.go index 98051741b..a9aec8604 100644 --- a/api/filters/imagetag/imagetag_test.go +++ b/api/filters/imagetag/imagetag_test.go @@ -840,6 +840,45 @@ spec: }, }, }, + "updateimagesuffix": { + input: ` +group: apps +apiVersion: v1 +kind: Deployment +metadata: + name: deploysuffix +spec: + template: + spec: + containers: + - image: redis:6.2.6 + name: redis +`, + expectedOutput: ` +group: apps +apiVersion: v1 +kind: Deployment +metadata: + name: deploysuffix +spec: + template: + spec: + containers: + - image: redis:6.2.6-alpine + name: redis +`, + filter: Filter{ + ImageTag: types.Image{ + Name: "redis", + TagSuffix: "-alpine", + }, + }, + fsSlice: []types.FieldSpec{ + { + Path: "spec/template/spec/containers[]/image", + }, + }, + }, } for tn, tc := range testCases { diff --git a/api/filters/imagetag/updater.go b/api/filters/imagetag/updater.go index 810f20591..d2a728498 100644 --- a/api/filters/imagetag/updater.go +++ b/api/filters/imagetag/updater.go @@ -5,6 +5,7 @@ package imagetag import ( "sigs.k8s.io/kustomize/api/filters/filtersutil" + "sigs.k8s.io/kustomize/api/image" "sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/kustomize/kyaml/yaml" @@ -46,6 +47,9 @@ func (u imageTagUpdater) SetImageValue(rn *yaml.RNode) error { case u.ImageTag.Digest != "": tag = "" digest = u.ImageTag.Digest + case u.ImageTag.TagSuffix != "": + tag += u.ImageTag.TagSuffix + digest = "" } // build final image name diff --git a/api/internal/builtins/AnnotationsTransformer.go b/api/internal/builtins/AnnotationsTransformer.go index 7064fa80c..c84c0d186 100644 --- a/api/internal/builtins/AnnotationsTransformer.go +++ b/api/internal/builtins/AnnotationsTransformer.go @@ -1,6 +1,8 @@ // Code generated by pluginator on AnnotationsTransformer; DO NOT EDIT. // pluginator {unknown 1970-01-01T00:00:00Z } + + package builtins import ( @@ -16,6 +18,7 @@ type AnnotationsTransformerPlugin struct { FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"` } + func (p *AnnotationsTransformerPlugin) Config( _ *resmap.PluginHelpers, c []byte) (err error) { p.Annotations = nil @@ -34,5 +37,5 @@ func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error { } func NewAnnotationsTransformerPlugin() resmap.TransformerPlugin { - return &AnnotationsTransformerPlugin{} + return &AnnotationsTransformerPlugin{} } diff --git a/api/types/image.go b/api/types/image.go index c7982338f..e40ed324d 100644 --- a/api/types/image.go +++ b/api/types/image.go @@ -12,6 +12,10 @@ type Image struct { // NewName is the value used to replace the original name. NewName string `json:"newName,omitempty" yaml:"newName,omitempty"` + // TagSuffix is the value used to suffix the original tag + // If Digest and NewTag is present an error is thrown + TagSuffix string `json:"tagSuffix,omitempty" yaml:"tagSuffix,omitempty"` + // NewTag is the value used to replace the original tag. NewTag string `json:"newTag,omitempty" yaml:"newTag,omitempty"`