From efbfead4ef9fd91ce130586787a6e3c54ca21e02 Mon Sep 17 00:00:00 2001 From: Jun Xiang Tee Date: Mon, 30 Oct 2017 12:49:44 -0700 Subject: [PATCH] remove created-by annotation --- hack/make-rules/test-cmd-util.sh | 6 +-- pkg/api/annotation_key_constants.go | 6 --- pkg/controller/BUILD | 2 - pkg/controller/controller_utils.go | 28 ++------------ pkg/controller/cronjob/utils.go | 5 --- pkg/controller/cronjob/utils_test.go | 14 +------ pkg/kubectl/cmd/annotate_test.go | 4 +- pkg/kubectl/cmd/drain_test.go | 38 ------------------- pkg/printers/internalversion/describe.go | 20 +--------- .../api/core/v1/annotation_key_constants.go | 6 --- test/e2e/kubectl/kubectl.go | 1 - 11 files changed, 11 insertions(+), 119 deletions(-) diff --git a/hack/make-rules/test-cmd-util.sh b/hack/make-rules/test-cmd-util.sh index 8cd4d07b61e..8ac62f33bfe 100755 --- a/hack/make-rules/test-cmd-util.sh +++ b/hack/make-rules/test-cmd-util.sh @@ -1253,7 +1253,7 @@ run_kubectl_run_tests() { # Post-Condition: Job "pi" is created kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" 'pi:' # Describe command (resource only) should print detailed information - kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Created By" + kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Controlled By" # Clean up kubectl delete jobs pi "${kube_flags[@]}" # Post-condition: no pods exist. @@ -2746,7 +2746,7 @@ run_deployment_tests() { # Describe command (resource only) should print detailed information kube::test::describe_resource_assert rs "Name:" "Pod Template:" "Labels:" "Selector:" "Controlled By" "Replicas:" "Pods Status:" "Volumes:" # Describe command (resource only) should print detailed information - kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Created By" "Controlled By" + kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Controlled By" # Clean up kubectl delete deployment test-nginx-apps "${kube_flags[@]}" @@ -2986,7 +2986,7 @@ run_rs_tests() { # Describe command should print events information when show-events=true kube::test::describe_resource_events_assert rs true # Describe command (resource only) should print detailed information - kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Created By" "Controlled By" + kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Controlled By" ### Scale replica set frontend with current-replicas and replicas # Pre-condition: 3 replicas diff --git a/pkg/api/annotation_key_constants.go b/pkg/api/annotation_key_constants.go index e935424462b..6a6827bb572 100644 --- a/pkg/api/annotation_key_constants.go +++ b/pkg/api/annotation_key_constants.go @@ -45,12 +45,6 @@ const ( // 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. - // This field is deprecated in favor of ControllerRef (see #44407). - // TODO(#50720): Remove this field in v1.9. - CreatedByAnnotation = "kubernetes.io/created-by" - // PreferAvoidPodsAnnotationKey represents the key of preferAvoidPods data (json serialized) // in the Annotations of a Node. PreferAvoidPodsAnnotationKey string = "scheduler.alpha.kubernetes.io/preferAvoidPods" diff --git a/pkg/controller/BUILD b/pkg/controller/BUILD index 1ea0993ddff..11ed251371b 100644 --- a/pkg/controller/BUILD +++ b/pkg/controller/BUILD @@ -83,13 +83,11 @@ go_library( "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", "//vendor/k8s.io/apiserver/pkg/authentication/serviceaccount:go_default_library", "//vendor/k8s.io/client-go/kubernetes:go_default_library", - "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/authentication/v1:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/tools/cache:go_default_library", "//vendor/k8s.io/client-go/tools/record:go_default_library", - "//vendor/k8s.io/client-go/tools/reference:go_default_library", "//vendor/k8s.io/client-go/util/integer:go_default_library", "//vendor/k8s.io/client-go/util/retry:go_default_library", ], diff --git a/pkg/controller/controller_utils.go b/pkg/controller/controller_utils.go index 360f2091b2d..1e78f5535d9 100644 --- a/pkg/controller/controller_utils.go +++ b/pkg/controller/controller_utils.go @@ -38,10 +38,8 @@ import ( "k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" - "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" - ref "k8s.io/client-go/tools/reference" "k8s.io/client-go/util/integer" clientretry "k8s.io/client-go/util/retry" _ "k8s.io/kubernetes/pkg/api/install" @@ -474,29 +472,12 @@ func getPodsFinalizers(template *v1.PodTemplateSpec) []string { return desiredFinalizers } -func getPodsAnnotationSet(template *v1.PodTemplateSpec, object runtime.Object) (labels.Set, error) { +func getPodsAnnotationSet(template *v1.PodTemplateSpec) labels.Set { desiredAnnotations := make(labels.Set) for k, v := range template.Annotations { desiredAnnotations[k] = v } - createdByRef, err := ref.GetReference(scheme.Scheme, object) - if err != nil { - return desiredAnnotations, fmt.Errorf("unable to get controller reference: %v", err) - } - - // TODO: this code was not safe previously - as soon as new code came along that switched to v2, old clients - // would be broken upon reading it. This is explicitly hardcoded to v1 to guarantee predictable deployment. - // We need to consistently handle this case of annotation versioning. - codec := scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion) - - createdByRefJson, err := runtime.Encode(codec, &v1.SerializedReference{ - Reference: *createdByRef, - }) - if err != nil { - return desiredAnnotations, fmt.Errorf("unable to serialize controller reference: %v", err) - } - desiredAnnotations[v1.CreatedByAnnotation] = string(createdByRefJson) - return desiredAnnotations, nil + return desiredAnnotations } func getPodsPrefix(controllerName string) string { @@ -553,10 +534,7 @@ func (r RealPodControl) PatchPod(namespace, name string, data []byte) error { func GetPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Object, controllerRef *metav1.OwnerReference) (*v1.Pod, error) { desiredLabels := getPodsLabelSet(template) desiredFinalizers := getPodsFinalizers(template) - desiredAnnotations, err := getPodsAnnotationSet(template, parentObject) - if err != nil { - return nil, err - } + desiredAnnotations := getPodsAnnotationSet(template) accessor, err := meta.Accessor(parentObject) if err != nil { return nil, fmt.Errorf("parentObject does not have ObjectMeta, %v", err) diff --git a/pkg/controller/cronjob/utils.go b/pkg/controller/cronjob/utils.go index 078b55d05ab..d3286d99ced 100644 --- a/pkg/controller/cronjob/utils.go +++ b/pkg/controller/cronjob/utils.go @@ -176,11 +176,6 @@ func getJobFromTemplate(sj *batchv1beta1.CronJob, scheduledTime time.Time) (*bat // scheduled-job-name=$SJ_NAME -- for user convenience labels := copyLabels(&sj.Spec.JobTemplate) annotations := copyAnnotations(&sj.Spec.JobTemplate) - createdByRefJson, err := makeCreatedByRefJson(sj) - if err != nil { - return nil, err - } - annotations[v1.CreatedByAnnotation] = string(createdByRefJson) // We want job names for a given nominal start time to have a deterministic name to avoid the same job being created twice name := fmt.Sprintf("%s-%d", sj.Name, getTimeHash(scheduledTime)) diff --git a/pkg/controller/cronjob/utils_test.go b/pkg/controller/cronjob/utils_test.go index dbb1512121e..fb6b569f2e6 100644 --- a/pkg/controller/cronjob/utils_test.go +++ b/pkg/controller/cronjob/utils_test.go @@ -83,21 +83,9 @@ func TestGetJobFromTemplate(t *testing.T) { if len(job.ObjectMeta.Labels) != 1 { t.Errorf("Wrong number of labels") } - if len(job.ObjectMeta.Annotations) != 2 { + if len(job.ObjectMeta.Annotations) != 1 { t.Errorf("Wrong number of annotations") } - v, ok := job.ObjectMeta.Annotations[v1.CreatedByAnnotation] - if !ok { - t.Errorf("Missing created-by annotation") - } - expectedCreatedBy := `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"CronJob","namespace":"snazzycats","name":"mycronjob","uid":"1a2b3c","apiVersion":"batch"}} -` - if len(v) != len(expectedCreatedBy) { - t.Errorf("Wrong length for created-by annotation, expected %v got %v", len(expectedCreatedBy), len(v)) - } - if v != expectedCreatedBy { - t.Errorf("Wrong value for created-by annotation, expected %v got %v", expectedCreatedBy, v) - } } func TestGetParentUIDFromJob(t *testing.T) { diff --git a/pkg/kubectl/cmd/annotate_test.go b/pkg/kubectl/cmd/annotate_test.go index 7396d9a4936..885184fc094 100644 --- a/pkg/kubectl/cmd/annotate_test.go +++ b/pkg/kubectl/cmd/annotate_test.go @@ -118,8 +118,8 @@ func TestParseAnnotations(t *testing.T) { expectErr: false, }, { - annotations: []string{"url=" + testURL, api.CreatedByAnnotation + "=" + testJSON}, - expected: map[string]string{"url": testURL, api.CreatedByAnnotation: testJSON}, + annotations: []string{"url=" + testURL, "fake.kubernetes.io/annotation=" + testJSON}, + expected: map[string]string{"url": testURL, "fake.kubernetes.io/annotation": testJSON}, expectedRemove: []string{}, scenario: "add annotations with special characters", expectErr: false, diff --git a/pkg/kubectl/cmd/drain_test.go b/pkg/kubectl/cmd/drain_test.go index 10be330fad1..5754d591635 100644 --- a/pkg/kubectl/cmd/drain_test.go +++ b/pkg/kubectl/cmd/drain_test.go @@ -247,9 +247,6 @@ func TestDrain(t *testing.T) { }, } - rc_anno := make(map[string]string) - rc_anno[api.CreatedByAnnotation] = refJson(t, &rc) - rc_pod := corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "bar", @@ -257,7 +254,6 @@ func TestDrain(t *testing.T) { CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: labels, SelfLink: testapi.Default.SelfLink("pods", "bar"), - Annotations: rc_anno, OwnerReferences: []metav1.OwnerReference{ { APIVersion: "v1", @@ -286,9 +282,6 @@ func TestDrain(t *testing.T) { }, } - ds_anno := make(map[string]string) - ds_anno[api.CreatedByAnnotation] = refJson(t, &ds) - ds_pod := corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "bar", @@ -296,7 +289,6 @@ func TestDrain(t *testing.T) { CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: labels, SelfLink: testapi.Default.SelfLink("pods", "bar"), - Annotations: ds_anno, OwnerReferences: []metav1.OwnerReference{ { APIVersion: "extensions/v1beta1", @@ -312,21 +304,6 @@ func TestDrain(t *testing.T) { }, } - missing_ds := extensions.DaemonSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: "missing-ds", - Namespace: "default", - CreationTimestamp: metav1.Time{Time: time.Now()}, - SelfLink: testapi.Default.SelfLink("daemonsets", "missing-ds"), - }, - Spec: extensions.DaemonSetSpec{ - Selector: &metav1.LabelSelector{MatchLabels: labels}, - }, - } - - missing_ds_anno := make(map[string]string) - missing_ds_anno[api.CreatedByAnnotation] = refJson(t, &missing_ds) - orphaned_ds_pod := corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "bar", @@ -334,16 +311,6 @@ func TestDrain(t *testing.T) { CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: labels, SelfLink: testapi.Default.SelfLink("pods", "bar"), - Annotations: missing_ds_anno, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "extensions/v1beta1", - Kind: "DaemonSet", - Name: "missing-ds", - BlockOwnerDeletion: boolptr(true), - Controller: boolptr(true), - }, - }, }, Spec: corev1.PodSpec{ NodeName: "node", @@ -369,7 +336,6 @@ func TestDrain(t *testing.T) { CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: labels, SelfLink: testapi.Default.SelfLink("pods", "bar"), - Annotations: map[string]string{api.CreatedByAnnotation: refJson(t, &job)}, OwnerReferences: []metav1.OwnerReference{ { APIVersion: "v1", @@ -395,9 +361,6 @@ func TestDrain(t *testing.T) { }, } - rs_anno := make(map[string]string) - rs_anno[api.CreatedByAnnotation] = refJson(t, &rs) - rs_pod := corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "bar", @@ -405,7 +368,6 @@ func TestDrain(t *testing.T) { CreationTimestamp: metav1.Time{Time: time.Now()}, Labels: labels, SelfLink: testapi.Default.SelfLink("pods", "bar"), - Annotations: rs_anno, OwnerReferences: []metav1.OwnerReference{ { APIVersion: "v1", diff --git a/pkg/printers/internalversion/describe.go b/pkg/printers/internalversion/describe.go index aaa520e72a2..3e66282cab4 100644 --- a/pkg/printers/internalversion/describe.go +++ b/pkg/printers/internalversion/describe.go @@ -19,7 +19,6 @@ package internalversion import ( "bytes" "crypto/x509" - "encoding/json" "fmt" "io" "net" @@ -647,9 +646,6 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) { w.Write(LEVEL_0, "Message:\t%s\n", pod.Status.Message) } w.Write(LEVEL_0, "IP:\t%s\n", pod.Status.PodIP) - if createdBy := printCreator(pod.Annotations); len(createdBy) > 0 { - w.Write(LEVEL_0, "Created By:\t%s\n", createdBy) - } if controlledBy := printController(pod); len(controlledBy) > 0 { w.Write(LEVEL_0, "Controlled By:\t%s\n", controlledBy) } @@ -688,18 +684,6 @@ func printController(controllee metav1.Object) string { return "" } -func printCreator(annotation map[string]string) string { - value, ok := annotation[api.CreatedByAnnotation] - if ok { - var r api.SerializedReference - err := json.Unmarshal([]byte(value), &r) - if err == nil { - return fmt.Sprintf("%s/%s", r.Reference.Kind, r.Reference.Name) - } - } - return "" -} - func describeVolumes(volumes []api.Volume, w PrefixWriter, space string) { if volumes == nil || len(volumes) == 0 { w.Write(LEVEL_0, "%sVolumes:\t\n", space) @@ -1686,8 +1670,8 @@ func describeJob(job *batch.Job, events *api.EventList) (string, error) { w.Write(LEVEL_0, "Selector:\t%s\n", selector) printLabelsMultiline(w, "Labels", job.Labels) printAnnotationsMultiline(w, "Annotations", job.Annotations) - if createdBy := printCreator(job.Annotations); len(createdBy) > 0 { - w.Write(LEVEL_0, "Created By:\t%s\n", createdBy) + if controlledBy := printController(job); len(controlledBy) > 0 { + w.Write(LEVEL_0, "Controlled By:\t%s\n", controlledBy) } w.Write(LEVEL_0, "Parallelism:\t%d\n", *job.Spec.Parallelism) if job.Spec.Completions != nil { diff --git a/staging/src/k8s.io/api/core/v1/annotation_key_constants.go b/staging/src/k8s.io/api/core/v1/annotation_key_constants.go index e623913fdd1..de4e3cee447 100644 --- a/staging/src/k8s.io/api/core/v1/annotation_key_constants.go +++ b/staging/src/k8s.io/api/core/v1/annotation_key_constants.go @@ -45,12 +45,6 @@ const ( // 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. - // This field is deprecated in favor of ControllerRef (see #44407). - // TODO(#50720): Remove this field in v1.9. - CreatedByAnnotation = "kubernetes.io/created-by" - // PreferAvoidPodsAnnotationKey represents the key of preferAvoidPods data (json serialized) // in the Annotations of a Node. PreferAvoidPodsAnnotationKey string = "scheduler.alpha.kubernetes.io/preferAvoidPods" diff --git a/test/e2e/kubectl/kubectl.go b/test/e2e/kubectl/kubectl.go index 205ddd3ae9a..e70dc1bfead 100644 --- a/test/e2e/kubectl/kubectl.go +++ b/test/e2e/kubectl/kubectl.go @@ -857,7 +857,6 @@ metadata: {"Annotations:"}, {"Status:", "Running"}, {"IP:"}, - {"Created By:", "ReplicationController/redis-master"}, {"Controlled By:", "ReplicationController/redis-master"}, {"Image:", redisImage}, {"State:", "Running"},