mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 04:55:08 +00:00
Rename id annotations to build annotations.
This commit is contained in:
@@ -721,7 +721,7 @@ func TestNameReferenceNamespace(t *testing.T) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
@@ -883,7 +883,7 @@ func TestNameReferenceClusterWide(t *testing.T) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
@@ -1010,7 +1010,7 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
@@ -1047,7 +1047,7 @@ func TestNameReferenceCandidateSelection(t *testing.T) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ s/$BAR/bar baz/g
|
||||
"argsFromFile": "sed-input.txt",
|
||||
})
|
||||
|
||||
pluginConfig.RemoveIdAnnotations()
|
||||
pluginConfig.RemoveBuildAnnotations()
|
||||
p := NewExecPlugin(
|
||||
pLdr.AbsolutePluginPath(
|
||||
konfig.DisabledPluginConfig(),
|
||||
|
||||
@@ -244,7 +244,7 @@ metadata:
|
||||
t.Fatalf("unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
expected.RemoveIdAnnotations()
|
||||
expected.RemoveBuildAnnotations()
|
||||
expYaml, err := expected.AsYaml()
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -252,7 +252,7 @@ metadata:
|
||||
assert.NoError(t, kt.Load())
|
||||
actual, err := kt.MakeCustomizedResMap()
|
||||
assert.NoError(t, err)
|
||||
actual.RemoveIdAnnotations()
|
||||
actual.RemoveBuildAnnotations()
|
||||
actYaml, err := actual.AsYaml()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expYaml, actYaml)
|
||||
|
||||
@@ -58,7 +58,7 @@ func (k *WNodeFactory) SliceFromBytes(bs []byte) ([]ifc.Kunstructured, error) {
|
||||
|
||||
// shouldDropObject returns true if the resource should not be accumulated.
|
||||
func shouldDropObject(m yaml.ResourceMeta) bool {
|
||||
_, y := m.ObjectMeta.Annotations[konfig.IgnoredByKustomizeResourceAnnotation]
|
||||
_, y := m.ObjectMeta.Annotations[konfig.IgnoredByKustomizeAnnotation]
|
||||
return y
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ func (kf *KunstructuredFactoryImpl) skipResource(u unstructured.Unstructured) bo
|
||||
return false
|
||||
}
|
||||
// check if the Resource has opt-ed out of kustomize
|
||||
_, found := an[konfig.IgnoredByKustomizeResourceAnnotation]
|
||||
_, found := an[konfig.IgnoredByKustomizeAnnotation]
|
||||
return found
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,11 @@ const (
|
||||
// A program name, for use in help, finding the XDG_CONFIG_DIR, etc.
|
||||
ProgramName = "kustomize"
|
||||
|
||||
// ConfigAnnoDomain is configuration-related annotation namespace.
|
||||
ConfigAnnoDomain = "config.kubernetes.io"
|
||||
|
||||
// If a resource has this annotation, kustomize will drop it.
|
||||
IgnoredByKustomizeResourceAnnotation = "config.kubernetes.io/local-config"
|
||||
IgnoredByKustomizeAnnotation = ConfigAnnoDomain + "/local-config"
|
||||
|
||||
// Label key that indicates the resources are built from Kustomize
|
||||
ManagedbyLabelKey = "app.kubernetes.io/managed-by"
|
||||
|
||||
@@ -93,6 +93,6 @@ func (b *Kustomizer) Run(path string) (resmap.ResMap, error) {
|
||||
}
|
||||
t.Transform(m)
|
||||
}
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -246,6 +246,6 @@ type ResMap interface {
|
||||
ApplySmPatch(
|
||||
selectedSet *resource.IdSet, patch *resource.Resource) error
|
||||
|
||||
// Remove annotations used exclusively by the kustomize build process.
|
||||
RemoveIdAnnotations()
|
||||
// RemoveBuildAnnotations removes annotations created by the build process.
|
||||
RemoveBuildAnnotations()
|
||||
}
|
||||
|
||||
@@ -621,8 +621,8 @@ func (m *resWrangler) ApplySmPatch(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *resWrangler) RemoveIdAnnotations() {
|
||||
func (m *resWrangler) RemoveBuildAnnotations() {
|
||||
for _, r := range m.Resources() {
|
||||
r.RemoveIdAnnotations()
|
||||
r.RemoveBuildAnnotations()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -998,7 +998,7 @@ spec:
|
||||
return
|
||||
}
|
||||
assert.False(t, tc.errorExpected)
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
yml, err := m.AsYaml()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, strings.Join(tc.expected, "---\n"), string(yml))
|
||||
@@ -1111,7 +1111,7 @@ $patch: delete
|
||||
assert.NoError(t, err, name)
|
||||
assert.NoError(t, m.ApplySmPatch(idSet, p), name)
|
||||
assert.Equal(t, tc.finalMapSize, m.Size(), name)
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
yml, err := m.AsYaml()
|
||||
assert.NoError(t, err, name)
|
||||
assert.Equal(t, tc.expected, string(yml), name)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/wrappy"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/resid"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||
@@ -30,10 +31,10 @@ type Resource struct {
|
||||
}
|
||||
|
||||
const (
|
||||
nameAnnotation = "config.kubernetes.io/originalName"
|
||||
prefixAnnotation = "config.kubernetes.io/prefixes"
|
||||
suffixAnnotation = "config.kubernetes.io/suffixes"
|
||||
namespaceAnnotation = "config.kubernetes.io/originalNs"
|
||||
buildAnnotationOriginalName = konfig.ConfigAnnoDomain + "/originalName"
|
||||
buildAnnotationPrefixes = konfig.ConfigAnnoDomain + "/prefixes"
|
||||
buildAnnotationSuffixes = konfig.ConfigAnnoDomain + "/suffixes"
|
||||
buildAnnotationOriginalNamespace = konfig.ConfigAnnoDomain + "/originalNs"
|
||||
)
|
||||
|
||||
func (r *Resource) ResetPrimaryData(incoming *Resource) {
|
||||
@@ -244,12 +245,12 @@ func copyStringSlice(s []string) []string {
|
||||
|
||||
// Implements ResCtx AddNamePrefix
|
||||
func (r *Resource) AddNamePrefix(p string) {
|
||||
r.addAdditiveAnnotation(prefixAnnotation, p)
|
||||
r.addAdditiveAnnotation(buildAnnotationPrefixes, p)
|
||||
}
|
||||
|
||||
// Implements ResCtx AddNameSuffix
|
||||
func (r *Resource) AddNameSuffix(s string) {
|
||||
r.addAdditiveAnnotation(suffixAnnotation, s)
|
||||
r.addAdditiveAnnotation(buildAnnotationSuffixes, s)
|
||||
}
|
||||
|
||||
func (r *Resource) addAdditiveAnnotation(name, value string) {
|
||||
@@ -309,19 +310,19 @@ func sameEndingSubarray(a, b []string) bool {
|
||||
// Implements ResCtx GetNamePrefixes
|
||||
func (r *Resource) GetNamePrefixes() []string {
|
||||
annotations := r.GetAnnotations()
|
||||
if _, ok := annotations[prefixAnnotation]; !ok {
|
||||
if _, ok := annotations[buildAnnotationPrefixes]; !ok {
|
||||
return nil
|
||||
}
|
||||
return strings.Split(annotations[prefixAnnotation], ",")
|
||||
return strings.Split(annotations[buildAnnotationPrefixes], ",")
|
||||
}
|
||||
|
||||
// Implements ResCtx GetNameSuffixes
|
||||
func (r *Resource) GetNameSuffixes() []string {
|
||||
annotations := r.GetAnnotations()
|
||||
if _, ok := annotations[suffixAnnotation]; !ok {
|
||||
if _, ok := annotations[buildAnnotationSuffixes]; !ok {
|
||||
return nil
|
||||
}
|
||||
return strings.Split(annotations[suffixAnnotation], ",")
|
||||
return strings.Split(annotations[buildAnnotationSuffixes], ",")
|
||||
}
|
||||
|
||||
// OutermostPrefixSuffixEquals returns true if both resources
|
||||
@@ -345,21 +346,24 @@ func (r *Resource) PrefixesSuffixesEquals(o ResCtx) bool {
|
||||
return sameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && sameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
|
||||
}
|
||||
|
||||
func (r *Resource) RemoveIdAnnotations() {
|
||||
// RemoveBuildAnnotations removes annotations created by the build process.
|
||||
// These are internal-only to kustomize, added to the data pipeline to
|
||||
// track name changes so name references can be fixed.
|
||||
func (r *Resource) RemoveBuildAnnotations() {
|
||||
annotations := r.GetAnnotations()
|
||||
if len(annotations) == 0 {
|
||||
return
|
||||
}
|
||||
delete(annotations, nameAnnotation)
|
||||
delete(annotations, prefixAnnotation)
|
||||
delete(annotations, suffixAnnotation)
|
||||
delete(annotations, namespaceAnnotation)
|
||||
delete(annotations, buildAnnotationOriginalName)
|
||||
delete(annotations, buildAnnotationPrefixes)
|
||||
delete(annotations, buildAnnotationSuffixes)
|
||||
delete(annotations, buildAnnotationOriginalNamespace)
|
||||
r.SetAnnotations(annotations)
|
||||
}
|
||||
|
||||
func (r *Resource) GetOriginalName() string {
|
||||
annotations := r.GetAnnotations()
|
||||
if name, ok := annotations[nameAnnotation]; ok {
|
||||
if name, ok := annotations[buildAnnotationOriginalName]; ok {
|
||||
return name
|
||||
}
|
||||
return r.kunStr.GetName()
|
||||
@@ -370,8 +374,8 @@ func (r *Resource) SetOriginalName(n string, overwrite bool) *Resource {
|
||||
if annotations == nil {
|
||||
annotations = make(map[string]string)
|
||||
}
|
||||
if _, ok := annotations[nameAnnotation]; !ok || overwrite {
|
||||
annotations[nameAnnotation] = n
|
||||
if _, ok := annotations[buildAnnotationOriginalName]; !ok || overwrite {
|
||||
annotations[buildAnnotationOriginalName] = n
|
||||
}
|
||||
r.kunStr.SetAnnotations(annotations)
|
||||
return r
|
||||
@@ -379,7 +383,7 @@ func (r *Resource) SetOriginalName(n string, overwrite bool) *Resource {
|
||||
|
||||
func (r *Resource) GetOriginalNs() string {
|
||||
annotations := r.GetAnnotations()
|
||||
if ns, ok := annotations[namespaceAnnotation]; ok {
|
||||
if ns, ok := annotations[buildAnnotationOriginalNamespace]; ok {
|
||||
return ns
|
||||
}
|
||||
ns := r.GetNamespace()
|
||||
@@ -397,8 +401,8 @@ func (r *Resource) SetOriginalNs(n string, overwrite bool) *Resource {
|
||||
if annotations == nil {
|
||||
annotations = make(map[string]string)
|
||||
}
|
||||
if _, ok := annotations[namespaceAnnotation]; !ok || overwrite {
|
||||
annotations[namespaceAnnotation] = n
|
||||
if _, ok := annotations[buildAnnotationOriginalNamespace]; !ok || overwrite {
|
||||
annotations[buildAnnotationOriginalNamespace] = n
|
||||
}
|
||||
r.SetAnnotations(annotations)
|
||||
return r
|
||||
|
||||
@@ -127,7 +127,7 @@ func (th Harness) AssertActualEqualsExpected(
|
||||
}
|
||||
|
||||
func (th Harness) AssertActualEqualsExpectedNoIdAnnotations(m resmap.ResMap, expected string) {
|
||||
m.RemoveIdAnnotations()
|
||||
m.RemoveBuildAnnotations()
|
||||
th.AssertActualEqualsExpectedWithTweak(m, nil, expected)
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ func (th *HarnessEnhanced) LoadAndRunGenerator(
|
||||
if err != nil {
|
||||
th.t.Fatalf("Err: %v", err)
|
||||
}
|
||||
rm.RemoveIdAnnotations()
|
||||
rm.RemoveBuildAnnotations()
|
||||
return rm
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user