Skip to content

Commit

Permalink
Use istio inject label (#763)
Browse files Browse the repository at this point in the history
Ref: knative/eventing#8204

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
Co-authored-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
knative-prow-robot and pierDipi authored Sep 27, 2024
1 parent 7ce3eca commit 8fa68ba
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/eventshub/103-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ metadata:
namespace: {{ .namespace }}
labels:
app: eventshub-{{ .name }}
{{ range $key, $value := .labels }}
{{ $key }}: "{{ $value }}"
{{ end }}
{{ if .annotations }}
annotations:
{{ range $key, $value := .annotations }}
Expand Down
12 changes: 10 additions & 2 deletions pkg/eventshub/104-forwarder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ metadata:
{{ end }}
spec:
template:
{{ if .podannotations }}
{{ if or .podannotations .podlabels }}
metadata:
{{ if .podannotations }}
annotations:
{{ range $key, $value := .podannotations }}
{{ $key }}: "{{ $value }}"
{{ end }}
{{ end }}
{{ end }}
{{ if .podlabels }}
labels:
{{ range $key, $value := .podlabels }}
{{ $key }}: "{{ $value }}"
{{ end }}
{{ end }}
{{ end }}
spec:
serviceAccountName: "{{ .name }}"
Expand Down
2 changes: 2 additions & 0 deletions pkg/eventshub/eventshub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func ExampleIstioAnnotation() {
}

manifest.WithIstioPodAnnotations(cfg)
manifest.WithIstioPodLabels(cfg)

files, err := manifest.ExecuteYAML(ctx, templates, images, cfg)
if err != nil {
Expand Down Expand Up @@ -153,6 +154,7 @@ func ExampleIstioAnnotation() {
// namespace: example
// labels:
// app: eventshub-hubhub
// sidecar.istio.io/inject: "true"
// annotations:
// proxy.istio.io/config: "{ 'holdApplicationUntilProxyStarts': true }"
// sidecar.istio.io/inject: "true"
Expand Down
1 change: 1 addition & 0 deletions pkg/eventshub/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func Install(name string, options ...EventsHubOption) feature.StepFn {

if ic := environment.GetIstioConfig(ctx); ic.Enabled {
manifest.WithIstioPodAnnotations(cfg)
manifest.WithIstioPodLabels(cfg)
}

manifest.PodSecurityCfgFn(ctx, t)(cfg)
Expand Down
24 changes: 24 additions & 0 deletions pkg/manifest/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ func WithPodAnnotations(additional map[string]interface{}) CfgFn {
}
}

// WithPodLabels appends pod labels (usually used by types where pod template is embedded)
func WithPodLabels(additional map[string]string) CfgFn {
return func(cfg map[string]interface{}) {
if ann, ok := cfg["podlabels"]; ok {
m := make(map[string]interface{}, len(additional))
for k, v := range additional {
m[k] = v
}
appendToOriginal(ann, m)
return
}
cfg["podlabels"] = additional
}
}

func appendToOriginal(original interface{}, additional map[string]interface{}) {
annotations := original.(map[string]interface{})
for k, v := range additional {
Expand Down Expand Up @@ -92,3 +107,12 @@ func WithIstioPodAnnotations(cfg map[string]interface{}) {
WithAnnotations(podAnnotations)(cfg)
WithPodAnnotations(podAnnotations)(cfg)
}

func WithIstioPodLabels(cfg map[string]interface{}) {
podLabels := map[string]string{
"sidecar.istio.io/inject": "true",
}

WithLabels(podLabels)(cfg)
WithPodLabels(podLabels)(cfg)
}
1 change: 1 addition & 0 deletions pkg/resources/cronjob/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func Install(name string, image string, options ...manifest.CfgFn) feature.StepF

if ic := environment.GetIstioConfig(ctx); ic.Enabled {
manifest.WithIstioPodAnnotations(cfg)
manifest.WithIstioPodLabels(cfg)
}

manifest.PodSecurityCfgFn(ctx, t)(cfg)
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func Install(name string, image string, options ...manifest.CfgFn) feature.StepF

if ic := environment.GetIstioConfig(ctx); ic.Enabled {
manifest.WithIstioPodAnnotations(cfg)
manifest.WithIstioPodLabels(cfg)
}

manifest.PodSecurityCfgFn(ctx, t)(cfg)
Expand Down
3 changes: 3 additions & 0 deletions pkg/resources/deployment/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ spec:
{{ range $key, $value := .selectors }}
{{ $key }}: "{{ $value }}"
{{ end }}
{{ range $key, $value := .podlabels }}
{{ $key }}: "{{ $value }}"
{{ end }}
spec:
{{ if .podSecurityContext }}
securityContext:
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Install(name string, image string, options ...manifest.CfgFn) feature.StepF

if ic := environment.GetIstioConfig(ctx); ic.Enabled {
manifest.WithIstioPodAnnotations(cfg)
manifest.WithIstioPodLabels(cfg)
}

manifest.PodSecurityCfgFn(ctx, t)(cfg)
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func Install(name string, image string, opts ...manifest.CfgFn) feature.StepFn {

if ic := environment.GetIstioConfig(ctx); ic.Enabled {
manifest.WithIstioPodAnnotations(cfg)
manifest.WithIstioPodLabels(cfg)
}

manifest.PodSecurityCfgFn(ctx, t)(cfg)
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

v1 "k8s.io/api/core/v1"

testlog "knative.dev/reconciler-test/pkg/logging"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/pkg/resources/pod"
Expand Down

0 comments on commit 8fa68ba

Please sign in to comment.