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