Skip to content

Commit

Permalink
Merge pull request #54445 from crimsonfaith91/rem
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 53190, 54790, 54445, 52607, 54801). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

remove created-by annotation

**What this PR does / why we need it**:
This PR removes `CreatedByAnnotation`.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #50720

**Release note**:

```release-note
The `kubernetes.io/created-by` annotation is no longer added to controller-created objects. Use the  `metadata.ownerReferences` item that has `controller` set to `true` to determine which controller, if any, owns an object.
```
  • Loading branch information
Kubernetes Submit Queue committed Nov 1, 2017
2 parents 3bea3e8 + efbfead commit ed00d9c
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 119 deletions.
6 changes: 3 additions & 3 deletions hack/make-rules/test-cmd-util.sh
Expand Up @@ -1264,7 +1264,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.
Expand Down Expand Up @@ -2768,7 +2768,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[@]}"

Expand Down Expand Up @@ -3008,7 +3008,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
Expand Down
6 changes: 0 additions & 6 deletions pkg/api/annotation_key_constants.go
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/BUILD
Expand Up @@ -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",
],
Expand Down
28 changes: 3 additions & 25 deletions pkg/controller/controller_utils.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions pkg/controller/cronjob/utils.go
Expand Up @@ -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))

Expand Down
14 changes: 1 addition & 13 deletions pkg/controller/cronjob/utils_test.go
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/annotate_test.go
Expand Up @@ -117,8 +117,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,
Expand Down
38 changes: 0 additions & 38 deletions pkg/kubectl/cmd/drain_test.go
Expand Up @@ -247,17 +247,13 @@ 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",
Namespace: "default",
CreationTimestamp: metav1.Time{Time: time.Now()},
Labels: labels,
SelfLink: testapi.Default.SelfLink("pods", "bar"),
Annotations: rc_anno,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand Down Expand Up @@ -286,17 +282,13 @@ 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",
Namespace: "default",
CreationTimestamp: metav1.Time{Time: time.Now()},
Labels: labels,
SelfLink: testapi.Default.SelfLink("pods", "bar"),
Annotations: ds_anno,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "extensions/v1beta1",
Expand All @@ -312,38 +304,13 @@ 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",
Namespace: "default",
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",
Expand All @@ -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",
Expand All @@ -395,17 +361,13 @@ 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",
Namespace: "default",
CreationTimestamp: metav1.Time{Time: time.Now()},
Labels: labels,
SelfLink: testapi.Default.SelfLink("pods", "bar"),
Annotations: rs_anno,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand Down
20 changes: 2 additions & 18 deletions pkg/printers/internalversion/describe.go
Expand Up @@ -19,7 +19,6 @@ package internalversion
import (
"bytes"
"crypto/x509"
"encoding/json"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -649,9 +648,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)
}
Expand Down Expand Up @@ -690,18 +686,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<none>\n", space)
Expand Down Expand Up @@ -1708,8 +1692,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 {
Expand Down
6 changes: 0 additions & 6 deletions staging/src/k8s.io/api/core/v1/annotation_key_constants.go
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion test/e2e/kubectl/kubectl.go
Expand Up @@ -857,7 +857,6 @@ metadata:
{"Annotations:"},
{"Status:", "Running"},
{"IP:"},
{"Created By:", "ReplicationController/redis-master"},
{"Controlled By:", "ReplicationController/redis-master"},
{"Image:", redisImage},
{"State:", "Running"},
Expand Down

0 comments on commit ed00d9c

Please sign in to comment.