From 930332751b885cee9b12ce8631e92aa030fc1324 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Tue, 24 May 2016 17:47:23 -0700 Subject: [PATCH] Use `CreatedByAnnotation` contant A nit but didn't want the strings to get out of sync. Signed-off-by: Doug Davis --- pkg/api/helpers.go | 4 ++++ pkg/controller/controller_utils.go | 4 +--- pkg/kubectl/cmd/annotate_test.go | 4 ++-- pkg/kubectl/cmd/drain.go | 3 +-- pkg/kubectl/cmd/drain_test.go | 9 ++++----- pkg/kubectl/describe.go | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/api/helpers.go b/pkg/api/helpers.go index 1349ef62b0b..047b4d63d3b 100644 --- a/pkg/api/helpers.go +++ b/pkg/api/helpers.go @@ -424,6 +424,10 @@ const ( // SeccompContainerAnnotationKeyPrefix represents the key of a seccomp profile applied // to one container of a pod. SeccompContainerAnnotationKeyPrefix string = "container.seccomp.security.alpha.kubernetes.io/" + + // CreatedByAnnotation represents the key used to store the spec(json) + // used to create the resource. + CreatedByAnnotation = "kubernetes.io/created-by" ) // GetAffinityFromPod gets the json serialized affinity data from Pod.Annotations diff --git a/pkg/controller/controller_utils.go b/pkg/controller/controller_utils.go index efdab55c137..a4878a543a7 100644 --- a/pkg/controller/controller_utils.go +++ b/pkg/controller/controller_utils.go @@ -40,8 +40,6 @@ import ( ) const ( - CreatedByAnnotation = "kubernetes.io/created-by" - // If a watch drops a delete event for a pod, it'll take this long // before a dormant controller waiting for those packets is woken up anyway. It is // specifically targeted at the case where some problem prevents an update @@ -392,7 +390,7 @@ func getPodsAnnotationSet(template *api.PodTemplateSpec, object runtime.Object) if err != nil { return desiredAnnotations, fmt.Errorf("unable to serialize controller reference: %v", err) } - desiredAnnotations[CreatedByAnnotation] = string(createdByRefJson) + desiredAnnotations[api.CreatedByAnnotation] = string(createdByRefJson) return desiredAnnotations, nil } diff --git a/pkg/kubectl/cmd/annotate_test.go b/pkg/kubectl/cmd/annotate_test.go index 58730662ab0..bfb8877782f 100644 --- a/pkg/kubectl/cmd/annotate_test.go +++ b/pkg/kubectl/cmd/annotate_test.go @@ -116,8 +116,8 @@ func TestParseAnnotations(t *testing.T) { expectErr: false, }, { - annotations: []string{"url=" + testURL, "kubernetes.io/created-by=" + testJSON}, - expected: map[string]string{"url": testURL, "kubernetes.io/created-by": testJSON}, + annotations: []string{"url=" + testURL, api.CreatedByAnnotation + "=" + testJSON}, + expected: map[string]string{"url": testURL, api.CreatedByAnnotation: testJSON}, expectedRemove: []string{}, scenario: "add annotations with special characters", expectErr: false, diff --git a/pkg/kubectl/cmd/drain.go b/pkg/kubectl/cmd/drain.go index 07e79d790c2..667e962b6f2 100644 --- a/pkg/kubectl/cmd/drain.go +++ b/pkg/kubectl/cmd/drain.go @@ -29,7 +29,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/meta" client "k8s.io/kubernetes/pkg/client/unversioned" - "k8s.io/kubernetes/pkg/controller" "k8s.io/kubernetes/pkg/fields" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/kubectl/resource" @@ -238,7 +237,7 @@ func (o *DrainOptions) getController(sr *api.SerializedReference) (interface{}, } func (o *DrainOptions) getPodCreator(pod api.Pod) (*api.SerializedReference, error) { - creatorRef, found := pod.ObjectMeta.Annotations[controller.CreatedByAnnotation] + creatorRef, found := pod.ObjectMeta.Annotations[api.CreatedByAnnotation] if !found { return nil, nil } diff --git a/pkg/kubectl/cmd/drain_test.go b/pkg/kubectl/cmd/drain_test.go index 4fb3bad4b88..f5c08f049f1 100644 --- a/pkg/kubectl/cmd/drain_test.go +++ b/pkg/kubectl/cmd/drain_test.go @@ -36,7 +36,6 @@ import ( "k8s.io/kubernetes/pkg/apis/batch" "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/client/unversioned/fake" - "k8s.io/kubernetes/pkg/controller" "k8s.io/kubernetes/pkg/conversion" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/runtime" @@ -219,7 +218,7 @@ func TestDrain(t *testing.T) { } rc_anno := make(map[string]string) - rc_anno[controller.CreatedByAnnotation] = refJson(t, &rc) + rc_anno[api.CreatedByAnnotation] = refJson(t, &rc) rc_pod := api.Pod{ ObjectMeta: api.ObjectMeta{ @@ -247,7 +246,7 @@ func TestDrain(t *testing.T) { } ds_anno := make(map[string]string) - ds_anno[controller.CreatedByAnnotation] = refJson(t, &ds) + ds_anno[api.CreatedByAnnotation] = refJson(t, &ds) ds_pod := api.Pod{ ObjectMeta: api.ObjectMeta{ @@ -280,7 +279,7 @@ func TestDrain(t *testing.T) { Namespace: "default", CreationTimestamp: unversioned.Time{Time: time.Now()}, Labels: labels, - Annotations: map[string]string{controller.CreatedByAnnotation: refJson(t, &job)}, + Annotations: map[string]string{api.CreatedByAnnotation: refJson(t, &job)}, }, } @@ -298,7 +297,7 @@ func TestDrain(t *testing.T) { } rs_anno := make(map[string]string) - rs_anno[controller.CreatedByAnnotation] = refJson(t, &rs) + rs_anno[api.CreatedByAnnotation] = refJson(t, &rs) rs_pod := api.Pod{ ObjectMeta: api.ObjectMeta{ diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index 2d6f79245ba..231f71c41cf 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -549,7 +549,7 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) { } func printControllers(annotation map[string]string) string { - value, ok := annotation["kubernetes.io/created-by"] + value, ok := annotation[api.CreatedByAnnotation] if ok { var r api.SerializedReference err := json.Unmarshal([]byte(value), &r)