Manage name changes (prefix/suffix) via YAML annotations rather than via in-memory-only fields.

This commit is contained in:
Natasha Sarkar
2021-01-11 13:06:21 -08:00
parent ea5d08bac5
commit bd4580d73a
34 changed files with 539 additions and 61 deletions

View File

@@ -6,7 +6,6 @@ package main
import (
"errors"
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/resmap"
@@ -70,8 +69,12 @@ func (p *plugin) Transform(m resmap.ResMap) error {
// this will add a prefix and a suffix
// to the resource even if those are
// empty
r.AddNamePrefix(p.Prefix)
r.AddNameSuffix(p.Suffix)
if p.Prefix != "" || p.Suffix != "" {
r.SetOriginalName(r.GetName(), false)
}
}
err := r.ApplyFilter(prefixsuffix.Filter{
Prefix: p.Prefix,

View File

@@ -62,6 +62,10 @@ metadata:
apiVersion: v1
kind: Service
metadata:
annotations:
config.kubernetes.io/originalName: apple
config.kubernetes.io/prefixes: baked-
config.kubernetes.io/suffixes: -pie
name: baked-apple-pie
spec:
ports:
@@ -80,6 +84,10 @@ metadata:
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
config.kubernetes.io/originalName: cm
config.kubernetes.io/prefixes: baked-
config.kubernetes.io/suffixes: -pie
name: baked-cm-pie
`)
@@ -126,6 +134,10 @@ metadata:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
config.kubernetes.io/originalName: deployment
config.kubernetes.io/prefixes: test-
config.kubernetes.io/suffixes: null
name: test-deployment
spec:
template: