From 61261334423a06c75f8734d9deaef761acc36e52 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Fri, 15 Apr 2022 16:38:19 +0200 Subject: [PATCH 1/3] Fix: setting default Istio annotation in Pod instead of Deployment Signed-off-by: Karol Szwaj --- pkg/deployment/all_in_one.go | 15 ++++++++++----- pkg/deployment/collector.go | 15 ++++++++++----- pkg/deployment/ingester.go | 15 ++++++++++----- pkg/deployment/query.go | 15 ++++++++++----- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index a159f7dbc..a55e0e6d7 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -50,15 +50,20 @@ func (a *AllInOne) Get() *appsv1.Deployment { baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ - "prometheus.io/scrape": "true", - "prometheus.io/port": strconv.Itoa(int(adminPort)), - "sidecar.istio.io/inject": "false", - "linkerd.io/inject": "disabled", + "prometheus.io/scrape": "true", + "prometheus.io/port": strconv.Itoa(int(adminPort)), + "linkerd.io/inject": "disabled", }, Labels: a.labels(), } commonSpec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.AllInOne.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) + podAnnotations := make(map[string]string) + + for k, v := range commonSpec.Annotations { + podAnnotations[k] = v + } + podAnnotations["sidecar.istio.io/inject"] = "false" options := allArgs(a.jaeger.Spec.AllInOne.Options, a.jaeger.Spec.Storage.Options.Filter(a.jaeger.Spec.Storage.Type.OptionsPrefix())) @@ -136,7 +141,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: commonSpec.Annotations, + Annotations: podAnnotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: commonSpec.ImagePullSecrets, diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index 1f6d678a7..d45c27478 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -45,15 +45,20 @@ func (c *Collector) Get() *appsv1.Deployment { baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ - "prometheus.io/scrape": "true", - "prometheus.io/port": strconv.Itoa(int(adminPort)), - "sidecar.istio.io/inject": "false", - "linkerd.io/inject": "disabled", + "prometheus.io/scrape": "true", + "prometheus.io/port": strconv.Itoa(int(adminPort)), + "linkerd.io/inject": "disabled", }, Labels: labels, } commonSpec := util.Merge([]v1.JaegerCommonSpec{c.jaeger.Spec.Collector.JaegerCommonSpec, c.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) + podAnnotations := make(map[string]string) + + for k, v := range commonSpec.Annotations { + podAnnotations[k] = v + } + podAnnotations["sidecar.istio.io/inject"] = "false" var envFromSource []corev1.EnvFromSource if len(c.jaeger.Spec.Storage.SecretName) > 0 { @@ -126,7 +131,7 @@ func (c *Collector) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: commonSpec.Annotations, + Annotations: podAnnotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: c.jaeger.Spec.ImagePullSecrets, diff --git a/pkg/deployment/ingester.go b/pkg/deployment/ingester.go index 9b69ff120..3d7f5bcb1 100644 --- a/pkg/deployment/ingester.go +++ b/pkg/deployment/ingester.go @@ -51,15 +51,20 @@ func (i *Ingester) Get() *appsv1.Deployment { baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ - "prometheus.io/scrape": "true", - "prometheus.io/port": strconv.Itoa(int(adminPort)), - "sidecar.istio.io/inject": "false", - "linkerd.io/inject": "disabled", + "prometheus.io/scrape": "true", + "prometheus.io/port": strconv.Itoa(int(adminPort)), + "linkerd.io/inject": "disabled", }, Labels: labels, } commonSpec := util.Merge([]v1.JaegerCommonSpec{i.jaeger.Spec.Ingester.JaegerCommonSpec, i.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) + podAnnotations := make(map[string]string) + + for k, v := range commonSpec.Annotations { + podAnnotations[k] = v + } + podAnnotations["sidecar.istio.io/inject"] = "false" var envFromSource []corev1.EnvFromSource if len(i.jaeger.Spec.Storage.SecretName) > 0 { @@ -116,7 +121,7 @@ func (i *Ingester) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: commonSpec.Annotations, + Annotations: podAnnotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: i.jaeger.Spec.ImagePullSecrets, diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index a75c1104e..222ddc0f0 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -42,10 +42,9 @@ func (q *Query) Get() *appsv1.Deployment { baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ - "prometheus.io/scrape": "true", - "prometheus.io/port": strconv.Itoa(int(adminPort)), - "sidecar.istio.io/inject": "false", - "linkerd.io/inject": "disabled", + "prometheus.io/scrape": "true", + "prometheus.io/port": strconv.Itoa(int(adminPort)), + "linkerd.io/inject": "disabled", }, Labels: labels, } @@ -63,6 +62,12 @@ func (q *Query) Get() *appsv1.Deployment { } commonSpec := util.Merge([]v1.JaegerCommonSpec{q.jaeger.Spec.Query.JaegerCommonSpec, q.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) + podAnnotations := make(map[string]string) + + for k, v := range commonSpec.Annotations { + podAnnotations[k] = v + } + podAnnotations["sidecar.istio.io/inject"] = "false" options := allArgs(q.jaeger.Spec.Query.Options, q.jaeger.Spec.Storage.Options.Filter(q.jaeger.Spec.Storage.Type.OptionsPrefix())) @@ -123,7 +128,7 @@ func (q *Query) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: commonSpec.Annotations, + Annotations: podAnnotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: q.jaeger.Spec.ImagePullSecrets, From 4e33d898592f20b1c2d78502a9600a00fe3aa8af Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Tue, 19 Apr 2022 10:30:47 +0200 Subject: [PATCH 2/3] Check if annotation sidecar.istio.io/inject exists Signed-off-by: Karol Szwaj --- pkg/deployment/all_in_one.go | 7 +++++-- pkg/deployment/collector.go | 7 +++++-- pkg/deployment/ingester.go | 5 ++++- pkg/deployment/query.go | 7 +++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index a55e0e6d7..4b79e98f8 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -63,7 +63,10 @@ func (a *AllInOne) Get() *appsv1.Deployment { for k, v := range commonSpec.Annotations { podAnnotations[k] = v } - podAnnotations["sidecar.istio.io/inject"] = "false" + _, ok := podAnnotations["sidecar.istio.io/inject"] + if !ok { + podAnnotations["sidecar.istio.io/inject"] = "false" + } options := allArgs(a.jaeger.Spec.AllInOne.Options, a.jaeger.Spec.Storage.Options.Filter(a.jaeger.Spec.Storage.Type.OptionsPrefix())) @@ -124,7 +127,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { Name: a.jaeger.Name, Namespace: a.jaeger.Namespace, Labels: commonSpec.Labels, - Annotations: commonSpec.Annotations, + Annotations: baseCommonSpec.Annotations, OwnerReferences: []metav1.OwnerReference{{ APIVersion: a.jaeger.APIVersion, Kind: a.jaeger.Kind, diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index d45c27478..b5e3259f9 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -58,7 +58,10 @@ func (c *Collector) Get() *appsv1.Deployment { for k, v := range commonSpec.Annotations { podAnnotations[k] = v } - podAnnotations["sidecar.istio.io/inject"] = "false" + _, ok := podAnnotations["sidecar.istio.io/inject"] + if !ok { + podAnnotations["sidecar.istio.io/inject"] = "false" + } var envFromSource []corev1.EnvFromSource if len(c.jaeger.Spec.Storage.SecretName) > 0 { @@ -113,7 +116,7 @@ func (c *Collector) Get() *appsv1.Deployment { Name: c.name(), Namespace: c.jaeger.Namespace, Labels: commonSpec.Labels, - Annotations: commonSpec.Annotations, + Annotations: baseCommonSpec.Annotations, OwnerReferences: []metav1.OwnerReference{{ APIVersion: c.jaeger.APIVersion, Kind: c.jaeger.Kind, diff --git a/pkg/deployment/ingester.go b/pkg/deployment/ingester.go index 3d7f5bcb1..029abf226 100644 --- a/pkg/deployment/ingester.go +++ b/pkg/deployment/ingester.go @@ -64,7 +64,10 @@ func (i *Ingester) Get() *appsv1.Deployment { for k, v := range commonSpec.Annotations { podAnnotations[k] = v } - podAnnotations["sidecar.istio.io/inject"] = "false" + _, ok := podAnnotations["sidecar.istio.io/inject"] + if !ok { + podAnnotations["sidecar.istio.io/inject"] = "false" + } var envFromSource []corev1.EnvFromSource if len(i.jaeger.Spec.Storage.SecretName) > 0 { diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index 222ddc0f0..3d29b466f 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -67,7 +67,10 @@ func (q *Query) Get() *appsv1.Deployment { for k, v := range commonSpec.Annotations { podAnnotations[k] = v } - podAnnotations["sidecar.istio.io/inject"] = "false" + _, ok := podAnnotations["sidecar.istio.io/inject"] + if !ok { + podAnnotations["sidecar.istio.io/inject"] = "false" + } options := allArgs(q.jaeger.Spec.Query.Options, q.jaeger.Spec.Storage.Options.Filter(q.jaeger.Spec.Storage.Type.OptionsPrefix())) @@ -110,7 +113,7 @@ func (q *Query) Get() *appsv1.Deployment { Name: fmt.Sprintf("%s-query", q.jaeger.Name), Namespace: q.jaeger.Namespace, Labels: commonSpec.Labels, - Annotations: commonSpec.Annotations, + Annotations: baseCommonSpec.Annotations, OwnerReferences: []metav1.OwnerReference{{ APIVersion: q.jaeger.APIVersion, Kind: q.jaeger.Kind, From 015abc89e3028502c0784fd23fc1240fe158942c Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Tue, 19 Apr 2022 11:36:00 +0200 Subject: [PATCH 3/3] Simplify code Signed-off-by: Karol Szwaj --- pkg/deployment/agent.go | 11 +++++++---- pkg/deployment/all_in_one.go | 11 +++-------- pkg/deployment/collector.go | 11 +++-------- pkg/deployment/ingester.go | 11 +++-------- pkg/deployment/query.go | 11 +++-------- 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/pkg/deployment/agent.go b/pkg/deployment/agent.go index fcdd900ff..a22c2429d 100644 --- a/pkg/deployment/agent.go +++ b/pkg/deployment/agent.go @@ -64,15 +64,18 @@ func (a *Agent) Get() *appsv1.DaemonSet { baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ - "prometheus.io/scrape": "true", - "prometheus.io/port": strconv.Itoa(int(adminPort)), - "sidecar.istio.io/inject": "false", - "linkerd.io/inject": "disabled", + "prometheus.io/scrape": "true", + "prometheus.io/port": strconv.Itoa(int(adminPort)), + "linkerd.io/inject": "disabled", }, Labels: labels, } commonSpec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.Agent.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) + _, ok := commonSpec.Annotations["sidecar.istio.io/inject"] + if !ok { + commonSpec.Annotations["sidecar.istio.io/inject"] = "false" + } ca.Update(a.jaeger, commonSpec) ca.AddServiceCA(a.jaeger, commonSpec) diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index 4b79e98f8..7771912eb 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -58,14 +58,9 @@ func (a *AllInOne) Get() *appsv1.Deployment { } commonSpec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.AllInOne.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) - podAnnotations := make(map[string]string) - - for k, v := range commonSpec.Annotations { - podAnnotations[k] = v - } - _, ok := podAnnotations["sidecar.istio.io/inject"] + _, ok := commonSpec.Annotations["sidecar.istio.io/inject"] if !ok { - podAnnotations["sidecar.istio.io/inject"] = "false" + commonSpec.Annotations["sidecar.istio.io/inject"] = "false" } options := allArgs(a.jaeger.Spec.AllInOne.Options, @@ -144,7 +139,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: podAnnotations, + Annotations: commonSpec.Annotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: commonSpec.ImagePullSecrets, diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index b5e3259f9..2952dbd9d 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -53,14 +53,9 @@ func (c *Collector) Get() *appsv1.Deployment { } commonSpec := util.Merge([]v1.JaegerCommonSpec{c.jaeger.Spec.Collector.JaegerCommonSpec, c.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) - podAnnotations := make(map[string]string) - - for k, v := range commonSpec.Annotations { - podAnnotations[k] = v - } - _, ok := podAnnotations["sidecar.istio.io/inject"] + _, ok := commonSpec.Annotations["sidecar.istio.io/inject"] if !ok { - podAnnotations["sidecar.istio.io/inject"] = "false" + commonSpec.Annotations["sidecar.istio.io/inject"] = "false" } var envFromSource []corev1.EnvFromSource @@ -134,7 +129,7 @@ func (c *Collector) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: podAnnotations, + Annotations: commonSpec.Annotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: c.jaeger.Spec.ImagePullSecrets, diff --git a/pkg/deployment/ingester.go b/pkg/deployment/ingester.go index 029abf226..1ec3c87aa 100644 --- a/pkg/deployment/ingester.go +++ b/pkg/deployment/ingester.go @@ -59,14 +59,9 @@ func (i *Ingester) Get() *appsv1.Deployment { } commonSpec := util.Merge([]v1.JaegerCommonSpec{i.jaeger.Spec.Ingester.JaegerCommonSpec, i.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) - podAnnotations := make(map[string]string) - - for k, v := range commonSpec.Annotations { - podAnnotations[k] = v - } - _, ok := podAnnotations["sidecar.istio.io/inject"] + _, ok := commonSpec.Annotations["sidecar.istio.io/inject"] if !ok { - podAnnotations["sidecar.istio.io/inject"] = "false" + commonSpec.Annotations["sidecar.istio.io/inject"] = "false" } var envFromSource []corev1.EnvFromSource @@ -124,7 +119,7 @@ func (i *Ingester) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: podAnnotations, + Annotations: commonSpec.Annotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: i.jaeger.Spec.ImagePullSecrets, diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index 3d29b466f..bedf919f6 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -62,14 +62,9 @@ func (q *Query) Get() *appsv1.Deployment { } commonSpec := util.Merge([]v1.JaegerCommonSpec{q.jaeger.Spec.Query.JaegerCommonSpec, q.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) - podAnnotations := make(map[string]string) - - for k, v := range commonSpec.Annotations { - podAnnotations[k] = v - } - _, ok := podAnnotations["sidecar.istio.io/inject"] + _, ok := commonSpec.Annotations["sidecar.istio.io/inject"] if !ok { - podAnnotations["sidecar.istio.io/inject"] = "false" + commonSpec.Annotations["sidecar.istio.io/inject"] = "false" } options := allArgs(q.jaeger.Spec.Query.Options, @@ -131,7 +126,7 @@ func (q *Query) Get() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, - Annotations: podAnnotations, + Annotations: commonSpec.Annotations, }, Spec: corev1.PodSpec{ ImagePullSecrets: q.jaeger.Spec.ImagePullSecrets,