mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Merge pull request #26237 from duglin/UseConstant
Automatic merge from submit-queue Use `CreatedByAnnotation` constant A nit but didn't want the strings to get out of sync. Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
commit
739e3dd1b1
@ -424,6 +424,10 @@ const (
|
|||||||
// SeccompContainerAnnotationKeyPrefix represents the key of a seccomp profile applied
|
// SeccompContainerAnnotationKeyPrefix represents the key of a seccomp profile applied
|
||||||
// to one container of a pod.
|
// to one container of a pod.
|
||||||
SeccompContainerAnnotationKeyPrefix string = "container.seccomp.security.alpha.kubernetes.io/"
|
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
|
// GetAffinityFromPod gets the json serialized affinity data from Pod.Annotations
|
||||||
|
@ -40,8 +40,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CreatedByAnnotation = "kubernetes.io/created-by"
|
|
||||||
|
|
||||||
// If a watch drops a delete event for a pod, it'll take this long
|
// 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
|
// 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
|
// 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 {
|
if err != nil {
|
||||||
return desiredAnnotations, fmt.Errorf("unable to serialize controller reference: %v", err)
|
return desiredAnnotations, fmt.Errorf("unable to serialize controller reference: %v", err)
|
||||||
}
|
}
|
||||||
desiredAnnotations[CreatedByAnnotation] = string(createdByRefJson)
|
desiredAnnotations[api.CreatedByAnnotation] = string(createdByRefJson)
|
||||||
return desiredAnnotations, nil
|
return desiredAnnotations, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +116,8 @@ func TestParseAnnotations(t *testing.T) {
|
|||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
annotations: []string{"url=" + testURL, "kubernetes.io/created-by=" + testJSON},
|
annotations: []string{"url=" + testURL, api.CreatedByAnnotation + "=" + testJSON},
|
||||||
expected: map[string]string{"url": testURL, "kubernetes.io/created-by": testJSON},
|
expected: map[string]string{"url": testURL, api.CreatedByAnnotation: testJSON},
|
||||||
expectedRemove: []string{},
|
expectedRemove: []string{},
|
||||||
scenario: "add annotations with special characters",
|
scenario: "add annotations with special characters",
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
|
@ -29,7 +29,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/meta"
|
"k8s.io/kubernetes/pkg/api/meta"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
"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) {
|
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 {
|
if !found {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/apis/batch"
|
"k8s.io/kubernetes/pkg/apis/batch"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/fake"
|
"k8s.io/kubernetes/pkg/client/unversioned/fake"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
|
||||||
"k8s.io/kubernetes/pkg/conversion"
|
"k8s.io/kubernetes/pkg/conversion"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
@ -219,7 +218,7 @@ func TestDrain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc_anno := make(map[string]string)
|
rc_anno := make(map[string]string)
|
||||||
rc_anno[controller.CreatedByAnnotation] = refJson(t, &rc)
|
rc_anno[api.CreatedByAnnotation] = refJson(t, &rc)
|
||||||
|
|
||||||
rc_pod := api.Pod{
|
rc_pod := api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -247,7 +246,7 @@ func TestDrain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ds_anno := make(map[string]string)
|
ds_anno := make(map[string]string)
|
||||||
ds_anno[controller.CreatedByAnnotation] = refJson(t, &ds)
|
ds_anno[api.CreatedByAnnotation] = refJson(t, &ds)
|
||||||
|
|
||||||
ds_pod := api.Pod{
|
ds_pod := api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -280,7 +279,7 @@ func TestDrain(t *testing.T) {
|
|||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
CreationTimestamp: unversioned.Time{Time: time.Now()},
|
CreationTimestamp: unversioned.Time{Time: time.Now()},
|
||||||
Labels: labels,
|
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 := make(map[string]string)
|
||||||
rs_anno[controller.CreatedByAnnotation] = refJson(t, &rs)
|
rs_anno[api.CreatedByAnnotation] = refJson(t, &rs)
|
||||||
|
|
||||||
rs_pod := api.Pod{
|
rs_pod := api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
@ -549,7 +549,7 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printControllers(annotation map[string]string) string {
|
func printControllers(annotation map[string]string) string {
|
||||||
value, ok := annotation["kubernetes.io/created-by"]
|
value, ok := annotation[api.CreatedByAnnotation]
|
||||||
if ok {
|
if ok {
|
||||||
var r api.SerializedReference
|
var r api.SerializedReference
|
||||||
err := json.Unmarshal([]byte(value), &r)
|
err := json.Unmarshal([]byte(value), &r)
|
||||||
|
Loading…
Reference in New Issue
Block a user