Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <[email protected]>
  • Loading branch information
cnvergence committed Apr 19, 2022
1 parent 4e33d89 commit 015abc8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
11 changes: 7 additions & 4 deletions pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions pkg/deployment/all_in_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions pkg/deployment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions pkg/deployment/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions pkg/deployment/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 015abc8

Please sign in to comment.