diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go index ed25c8ae3e7..b61965bd4fd 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go @@ -817,7 +817,7 @@ func getLastApplied(obj runtime.Object) (string, error) { return "", fmt.Errorf("no annotations on obj: %v", obj) } - lastApplied, ok := annotations[corev1.LastAppliedConfigAnnotation] + lastApplied, ok := annotations[internal.LastAppliedConfigAnnotation] if !ok { return "", fmt.Errorf("expected last applied annotation, but got none for object: %v", obj) } diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastapplied.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastapplied.go index 5264c82772f..b00b6b8298a 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastapplied.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastapplied.go @@ -19,12 +19,17 @@ package internal import ( "fmt" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation" "k8s.io/apimachinery/pkg/runtime" ) +// LastAppliedConfigAnnotation is the annotation used to store the previous +// configuration of a resource for use in a three way diff by UpdateApplyAnnotation. +// +// This is a copy of the corev1 annotation since we don't want to depend on the whole package. +const LastAppliedConfigAnnotation = "kubectl.kubernetes.io/last-applied-configuration" + // SetLastApplied sets the last-applied annotation the given value in // the object. func SetLastApplied(obj runtime.Object, value string) error { @@ -36,9 +41,9 @@ func SetLastApplied(obj runtime.Object, value string) error { if annotations == nil { annotations = map[string]string{} } - annotations[corev1.LastAppliedConfigAnnotation] = value + annotations[LastAppliedConfigAnnotation] = value if err := apimachineryvalidation.ValidateAnnotationsSize(annotations); err != nil { - delete(annotations, corev1.LastAppliedConfigAnnotation) + delete(annotations, LastAppliedConfigAnnotation) } accessor.SetAnnotations(annotations) return nil diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedmanager.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedmanager.go index 88675630aae..3f6cf88210c 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedmanager.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedmanager.go @@ -20,7 +20,6 @@ import ( "encoding/json" "fmt" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -100,7 +99,7 @@ func (f *lastAppliedManager) allowedConflictsFromLastApplied(liveObj runtime.Obj if annotations == nil { return nil, fmt.Errorf("no last applied annotation") } - var lastApplied, ok = annotations[corev1.LastAppliedConfigAnnotation] + var lastApplied, ok = annotations[LastAppliedConfigAnnotation] if !ok || lastApplied == "" { return nil, fmt.Errorf("no last applied annotation") } diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater.go index 0d9320730a1..06e6c5d8ce5 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater.go @@ -19,7 +19,6 @@ package internal import ( "fmt" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -78,7 +77,7 @@ func hasLastApplied(obj runtime.Object) bool { if annotations == nil { return false } - lastApplied, ok := annotations[corev1.LastAppliedConfigAnnotation] + lastApplied, ok := annotations[LastAppliedConfigAnnotation] return ok && len(lastApplied) > 0 } @@ -92,7 +91,7 @@ func buildLastApplied(obj runtime.Object) (string, error) { // Remove the annotation from the object before encoding the object var annotations = accessor.GetAnnotations() - delete(annotations, corev1.LastAppliedConfigAnnotation) + delete(annotations, LastAppliedConfigAnnotation) accessor.SetAnnotations(annotations) lastApplied, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj) diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater_test.go index 35d3267fb4e..181f4943c5a 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/lastappliedupdater_test.go @@ -114,7 +114,7 @@ func TestLargeLastApplied(t *testing.T) { Name: "large-update-test-cm", Namespace: "default", Annotations: map[string]string{ - corev1.LastAppliedConfigAnnotation: "nonempty", + internal.LastAppliedConfigAnnotation: "nonempty", }, }, Data: map[string]string{"k": "v"}, @@ -129,7 +129,7 @@ func TestLargeLastApplied(t *testing.T) { Name: "large-update-test-cm", Namespace: "default", Annotations: map[string]string{ - corev1.LastAppliedConfigAnnotation: "nonempty", + internal.LastAppliedConfigAnnotation: "nonempty", }, }, Data: map[string]string{"k": "v"}, @@ -153,7 +153,7 @@ func TestLargeLastApplied(t *testing.T) { Name: "large-update-test-cm", Namespace: "default", Annotations: map[string]string{ - corev1.LastAppliedConfigAnnotation: "nonempty", + internal.LastAppliedConfigAnnotation: "nonempty", }, }, Data: map[string]string{"k": "v"}, @@ -174,7 +174,7 @@ func TestLargeLastApplied(t *testing.T) { Name: "large-update-test-cm", Namespace: "default", Annotations: map[string]string{ - corev1.LastAppliedConfigAnnotation: "nonempty", + internal.LastAppliedConfigAnnotation: "nonempty", }, }, Data: map[string]string{"k": "v"}, @@ -220,7 +220,7 @@ func TestLargeLastApplied(t *testing.T) { if annotations == nil { t.Errorf("No annotations on obj: %v", f.Live()) } - lastApplied, ok := annotations[corev1.LastAppliedConfigAnnotation] + lastApplied, ok := annotations[internal.LastAppliedConfigAnnotation] if ok || len(lastApplied) > 0 { t.Errorf("Expected no last applied annotation, but got last applied with length: %d", len(lastApplied)) } @@ -238,7 +238,7 @@ func getLastApplied(obj runtime.Object) (string, error) { return "", fmt.Errorf("no annotations on obj: %v", obj) } - lastApplied, ok := annotations[corev1.LastAppliedConfigAnnotation] + lastApplied, ok := annotations[internal.LastAppliedConfigAnnotation] if !ok { return "", fmt.Errorf("expected last applied annotation, but got none for object: %v", obj) }