From 3d7f5cc642a0d85289aa479f8578445f9130c4a7 Mon Sep 17 00:00:00 2001 From: Dan Mace Date: Mon, 2 Feb 2015 13:49:41 -0500 Subject: [PATCH] Backport annotations to PodTemplateSpec Backport annotation support to v1beta1 and v1beta2 PodTemplateSpec. This allows ReplicationController users to specify annotations for Pods in addition to labels. --- pkg/api/v1beta1/conversion.go | 6 ++++++ pkg/api/v1beta1/types.go | 1 + pkg/api/v1beta2/conversion.go | 6 ++++++ pkg/api/v1beta2/types.go | 1 + pkg/controller/replication_controller.go | 5 +++++ 5 files changed, 19 insertions(+) diff --git a/pkg/api/v1beta1/conversion.go b/pkg/api/v1beta1/conversion.go index 41e21263dcd..7780c0e890a 100644 --- a/pkg/api/v1beta1/conversion.go +++ b/pkg/api/v1beta1/conversion.go @@ -418,6 +418,9 @@ func init() { if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil { return err } + if err := s.Convert(&in.ObjectMeta.Annotations, &out.Annotations, 0); err != nil { + return err + } return nil }, func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error { @@ -431,6 +434,9 @@ func init() { if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil { return err } + if err := s.Convert(&in.Annotations, &out.ObjectMeta.Annotations, 0); err != nil { + return err + } return nil }, diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index a3e49a49c34..6eb8e11cdda 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -493,6 +493,7 @@ type PodTemplate struct { DesiredState PodState `json:"desiredState,omitempty" description:"specification of the desired state of pods created from this template"` NodeSelector map[string]string `json:"nodeSelector,omitempty" description:"a selector which must be true for the pod to fit on a node"` Labels map[string]string `json:"labels,omitempty" description:"map of string keys and values that can be used to organize and categorize the pods created from the template; must match the selector of the replication controller to which the template belongs; may match selectors of services"` + Annotations map[string]string `json:"annotations,omitempty" description:"map of string keys and values that can be used by external tooling to store and retrieve arbitrary metadata about pods created from the template"` } // Session Affinity Type string diff --git a/pkg/api/v1beta2/conversion.go b/pkg/api/v1beta2/conversion.go index 94c561f462c..72882cce78f 100644 --- a/pkg/api/v1beta2/conversion.go +++ b/pkg/api/v1beta2/conversion.go @@ -282,6 +282,9 @@ func init() { if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil { return err } + if err := s.Convert(&in.ObjectMeta.Annotations, &out.Annotations, 0); err != nil { + return err + } return nil }, func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error { @@ -295,6 +298,9 @@ func init() { if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil { return err } + if err := s.Convert(&in.Annotations, &out.ObjectMeta.Annotations, 0); err != nil { + return err + } return nil }, // Converts internal Container to v1beta1.Container. diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index 79353bf3fd5..4d5898b3247 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -457,6 +457,7 @@ type PodTemplate struct { DesiredState PodState `json:"desiredState,omitempty" description:"specification of the desired state of pods created from this template"` NodeSelector map[string]string `json:"nodeSelector,omitempty" description:"a selector which must be true for the pod to fit on a node"` Labels map[string]string `json:"labels,omitempty" description:"map of string keys and values that can be used to organize and categorize the pods created from the template; must match the selector of the replication controller to which the template belongs; may match selectors of services"` + Annotations map[string]string `json:"annotations,omitempty" description:"map of string keys and values that can be used by external tooling to store and retrieve arbitrary metadata about pods created from the template"` } // Session Affinity Type string diff --git a/pkg/controller/replication_controller.go b/pkg/controller/replication_controller.go index ef948b57e90..2f9c03221b5 100644 --- a/pkg/controller/replication_controller.go +++ b/pkg/controller/replication_controller.go @@ -61,6 +61,10 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati for k, v := range controller.Spec.Template.Labels { desiredLabels[k] = v } + desiredAnnotations := make(labels.Set) + for k, v := range controller.Spec.Template.Annotations { + desiredAnnotations[k] = v + } // use the dash (if the name isn't too long) to make the pod name a bit prettier prefix := fmt.Sprintf("%s-", controller.Name) @@ -71,6 +75,7 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati pod := &api.Pod{ ObjectMeta: api.ObjectMeta{ Labels: desiredLabels, + Annotations: desiredAnnotations, GenerateName: prefix, }, }