diff --git a/pkg/api/helpers.go b/pkg/api/helpers.go index f18cc0eb759..9208c20bd5d 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 ae6dbadba74..c4f5c2894f2 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 eb12826b40d..3fd34040c7c 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 eecdff87a8d..19d5e7bca2f 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" @@ -240,7 +239,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 94e38685a3f..adc433d8185 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 9c540f90d6d..32c0b03e1e0 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)