remove created-by annotation

pull/6/head
Jun Xiang Tee 2017-10-30 12:49:44 -07:00
parent 1f53329c67
commit efbfead4ef
11 changed files with 11 additions and 119 deletions

View File

@ -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

View File

@ -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"

View File

@ -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",
],

View File

@ -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)

View File

@ -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))

View File

@ -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) {

View File

@ -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,

View File

@ -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",

View File

@ -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<none>\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 {

View File

@ -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"

View File

@ -857,7 +857,6 @@ metadata:
{"Annotations:"},
{"Status:", "Running"},
{"IP:"},
{"Created By:", "ReplicationController/redis-master"},
{"Controlled By:", "ReplicationController/redis-master"},
{"Image:", redisImage},
{"State:", "Running"},