Skip to content

Commit

Permalink
PR comments fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcariapas authored and mcariatm committed Jan 25, 2022
1 parent 2b4da33 commit f216c31
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 378 deletions.
364 changes: 0 additions & 364 deletions go.sum

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions pkg/collector/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
)

// Annotations return the annotations for OpenTelemetryCollector pod.
func Annotations(instance v1alpha1.OpenTelemetryCollector) (map[string]string, map[string]string) {
func Annotations(instance v1alpha1.OpenTelemetryCollector) map[string]string {
// new map every time, so that we don't touch the instance's annotations
annotations, podAnnotations := map[string]string{}, map[string]string{}
annotations := map[string]string{}

// set default prometheus annotations
annotations["prometheus.io/scrape"] = "true"
Expand All @@ -37,18 +37,26 @@ func Annotations(instance v1alpha1.OpenTelemetryCollector) (map[string]string, m
annotations[k] = v
}
}
// make sure sha256 for configMap is always calculated
annotations["opentelemetry-operator-config/sha256"] = getConfigMapSHA(instance.Spec.Config)

if nil != instance.Spec.PodAnnotations {
for k, v := range instance.Spec.PodAnnotations {
podAnnotations[k] = v
}
return annotations
}

// PodAnnotations return the spec annotations for OpenTelemetryCollector pod.
func PodAnnotations(instance v1alpha1.OpenTelemetryCollector) map[string]string {
// new map every time, so that we don't touch the instance's annotations
podAnnotations := map[string]string{}

// allow override of pod annotations
for k, v := range instance.Spec.PodAnnotations {
podAnnotations[k] = v
}

// make sure sha256 for configMap is always calculated
annotations["opentelemetry-operator-config/sha256"] = getConfigMapSHA(instance.Spec.Config)
podAnnotations["opentelemetry-operator-config/sha256"] = getConfigMapSHA(instance.Spec.Config)

return annotations, podAnnotations
return podAnnotations
}

func getConfigMapSHA(config string) string {
Expand Down
9 changes: 6 additions & 3 deletions pkg/collector/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func TestDefaultAnnotations(t *testing.T) {
}

// test
annotations, podAnnotations := Annotations(otelcol)
annotations := Annotations(otelcol)
podAnnotations := PodAnnotations(otelcol)

//verify
assert.Equal(t, "true", annotations["prometheus.io/scrape"])
Expand Down Expand Up @@ -64,7 +65,8 @@ func TestUserAnnotations(t *testing.T) {
}

// test
annotations, podAnnotations := Annotations(otelcol)
annotations := Annotations(otelcol)
podAnnotations := PodAnnotations(otelcol)

//verify
assert.Equal(t, "false", annotations["prometheus.io/scrape"])
Expand All @@ -86,7 +88,8 @@ func TestAnnotationsPropagateDown(t *testing.T) {
}

// test
annotations, podAnnotations := Annotations(otelcol)
annotations := Annotations(otelcol)
podAnnotations := PodAnnotations(otelcol)

// verify
assert.Len(t, annotations, 5)
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
labels := Labels(otelcol)
labels["app.kubernetes.io/name"] = naming.Collector(otelcol)

annotations, podAnnotations := Annotations(otelcol)
annotations := Annotations(otelcol)
podAnnotations := PodAnnotations(otelcol)

return appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func Deployment(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTele
labels := Labels(otelcol)
labels["app.kubernetes.io/name"] = naming.Collector(otelcol)

annotations, podAnnotations := Annotations(otelcol)
annotations := Annotations(otelcol)
podAnnotations := PodAnnotations(otelcol)

return appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func StatefulSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTel
labels := Labels(otelcol)
labels["app.kubernetes.io/name"] = naming.Collector(otelcol)

annotations, podAnnotations := Annotations(otelcol)
annotations := Annotations(otelcol)
podAnnotations := PodAnnotations(otelcol)

return appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit f216c31

Please sign in to comment.