Skip to content

Commit

Permalink
Append the config annotations to the pod's meta before creating the p…
Browse files Browse the repository at this point in the history
…atch

This ensures that any configs provided via the CLI options are persisted
as annotations before the configs override.

Signed-off-by: Ivan Sim <[email protected]>
  • Loading branch information
Ivan Sim committed Mar 26, 2019
1 parent f36fc16 commit 804225c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 2 additions & 4 deletions cli/cmd/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func (rt resourceTransformerInject) transform(bytes []byte) ([]byte, []inject.Re
r := inject.Report{UnsupportedResource: true}
return bytes, []inject.Report{r}, nil
}

conf.AppendPodAnnotations(rt.overrideAnnotations)
p, reports, err := conf.GetPatch(bytes, inject.ShouldInjectCLI)
if err != nil {
return nil, nil, err
Expand All @@ -139,11 +141,7 @@ func (rt resourceTransformerInject) transform(bytes []byte) ([]byte, []inject.Re
return bytes, reports, nil
}

for annotation, value := range rt.overrideAnnotations {
p.AddPodAnnotation(annotation, value)
}
p.AddPodAnnotation(k8s.CreatedByAnnotation, k8s.CreatedByAnnotationValue())

patchJSON, err := p.Marshal()
if err != nil {
return nil, nil, err
Expand Down
23 changes: 19 additions & 4 deletions pkg/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ type ResourceConfig struct {
pod struct {
// Meta is the pod's metadata. It's exported so that the YAML marshaling
// will work in the ParseMeta() function.
Meta *metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
labels map[string]string
spec *v1.PodSpec
Meta *metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
labels map[string]string
annotations map[string]string
spec *v1.PodSpec
}
}

Expand All @@ -105,6 +106,7 @@ func NewResourceConfig(configs *config.All) *ResourceConfig {

config.pod.Meta = &metav1.ObjectMeta{}
config.pod.labels = map[string]string{k8s.ControllerNSLabel: configs.GetGlobal().GetLinkerdNamespace()}
config.pod.annotations = map[string]string{}
return config
}

Expand Down Expand Up @@ -143,6 +145,13 @@ func (conf *ResourceConfig) WithProxyOutboundCapacity(m map[string]uint) *Resour
return conf
}

// AppendPodAnnotations appends the given annotations to the pod spec in conf
func (conf *ResourceConfig) AppendPodAnnotations(annotations map[string]string) {
for annotation, value := range annotations {
conf.pod.Meta.Annotations[annotation] = value
}
}

// YamlMarshalObj returns the yaml for the workload in conf
func (conf *ResourceConfig) YamlMarshalObj() ([]byte, error) {
return yaml.Marshal(conf.workload.obj)
Expand Down Expand Up @@ -181,6 +190,12 @@ func (conf *ResourceConfig) GetPatch(
return nil, nil, err
}

// append any additional pod annotations to the meta.
// for e.g., annotations that were converted from CLI inject options.
for annotation, value := range conf.pod.annotations {
conf.pod.Meta.Annotations[annotation] = value
}

var patch *Patch
if strings.ToLower(conf.workload.metaType.Kind) == k8s.Pod {
patch = NewPatchPod()
Expand Down Expand Up @@ -535,7 +550,7 @@ func (conf *ResourceConfig) injectProxyInit(patch *Patch) {
Image: conf.taggedProxyInitImage(),
ImagePullPolicy: conf.proxyInitImagePullPolicy(),
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
Args: conf.proxyInitArgs(),
Args: conf.proxyInitArgs(),
SecurityContext: &v1.SecurityContext{
Capabilities: &v1.Capabilities{
Add: []v1.Capability{v1.Capability("NET_ADMIN")},
Expand Down

0 comments on commit 804225c

Please sign in to comment.