Commit 3d7f5cc6 authored by Dan Mace's avatar Dan Mace

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.
parent c2b79e52
...@@ -418,6 +418,9 @@ func init() { ...@@ -418,6 +418,9 @@ func init() {
if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil { if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil {
return err return err
} }
if err := s.Convert(&in.ObjectMeta.Annotations, &out.Annotations, 0); err != nil {
return err
}
return nil return nil
}, },
func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error { func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error {
...@@ -431,6 +434,9 @@ func init() { ...@@ -431,6 +434,9 @@ func init() {
if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil { if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil {
return err return err
} }
if err := s.Convert(&in.Annotations, &out.ObjectMeta.Annotations, 0); err != nil {
return err
}
return nil return nil
}, },
......
...@@ -493,6 +493,7 @@ type PodTemplate struct { ...@@ -493,6 +493,7 @@ type PodTemplate struct {
DesiredState PodState `json:"desiredState,omitempty" description:"specification of the desired state of pods created from this template"` 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"` 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"` 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 // Session Affinity Type string
......
...@@ -282,6 +282,9 @@ func init() { ...@@ -282,6 +282,9 @@ func init() {
if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil { if err := s.Convert(&in.ObjectMeta.Labels, &out.Labels, 0); err != nil {
return err return err
} }
if err := s.Convert(&in.ObjectMeta.Annotations, &out.Annotations, 0); err != nil {
return err
}
return nil return nil
}, },
func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error { func(in *PodTemplate, out *newer.PodTemplateSpec, s conversion.Scope) error {
...@@ -295,6 +298,9 @@ func init() { ...@@ -295,6 +298,9 @@ func init() {
if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil { if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil {
return err return err
} }
if err := s.Convert(&in.Annotations, &out.ObjectMeta.Annotations, 0); err != nil {
return err
}
return nil return nil
}, },
// Converts internal Container to v1beta1.Container. // Converts internal Container to v1beta1.Container.
......
...@@ -457,6 +457,7 @@ type PodTemplate struct { ...@@ -457,6 +457,7 @@ type PodTemplate struct {
DesiredState PodState `json:"desiredState,omitempty" description:"specification of the desired state of pods created from this template"` 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"` 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"` 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 // Session Affinity Type string
......
...@@ -61,6 +61,10 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati ...@@ -61,6 +61,10 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati
for k, v := range controller.Spec.Template.Labels { for k, v := range controller.Spec.Template.Labels {
desiredLabels[k] = v 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 // use the dash (if the name isn't too long) to make the pod name a bit prettier
prefix := fmt.Sprintf("%s-", controller.Name) prefix := fmt.Sprintf("%s-", controller.Name)
...@@ -71,6 +75,7 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati ...@@ -71,6 +75,7 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati
pod := &api.Pod{ pod := &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: desiredLabels, Labels: desiredLabels,
Annotations: desiredAnnotations,
GenerateName: prefix, GenerateName: prefix,
}, },
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment