Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing pod collector annotations #451

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes by Version
==================

Unreleased
-------------------
* Allow changing Pod annotations using `podAnnotations` ([#451](https://github.com/open-telemetry/opentelemetry-operator/pull/451), [@indrekj](https://github.com/indrekj))

0.35.0
-------------------
* Bumped OpenTelemetry Collector to v0.35.0
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ type OpenTelemetryCollectorSpec struct {
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
Tolerations []v1.Toleration `json:"tolerations,omitempty"`

// PodAnnotations is the set of annotations that will be attached to
// Collector and Target Allocator pods.
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
}

// OpenTelemetryCollectorStatus defines the observed state of OpenTelemetryCollector.
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ spec:
- sidecar
- statefulset
type: string
podAnnotations:
additionalProperties:
type: string
description: PodAnnotations is the set of annotations that will be
attached to Collector and Target Allocator pods.
type: object
ports:
description: Ports allows a set of ports to be exposed by the underlying
v1.Service. By default, the operator will attempt to infer the required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ spec:
- sidecar
- statefulset
type: string
podAnnotations:
additionalProperties:
type: string
description: PodAnnotations is the set of annotations that will be
attached to Collector and Target Allocator pods.
type: object
ports:
description: Ports allows a set of ports to be exposed by the underlying
v1.Service. By default, the operator will attempt to infer the required
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: otelcol.Annotations,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add an entry to the changelog (perhaps after this is merged?) about this? This can be considered a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like a separate PR after this? I can do that. I could also add it to changelog right now under (unreleased) version if that's ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be fine as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Annotations: otelcol.Spec.PodAnnotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: ServiceAccountName(otelcol),
Expand Down
21 changes: 21 additions & 0 deletions pkg/collector/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,24 @@ func TestDaemonsetHostNetwork(t *testing.T) {
})
assert.True(t, d2.Spec.Template.Spec.HostNetwork)
}

func TestDaemonsetPodAnnotations(t *testing.T) {
// prepare
testPodAnnotationValues := map[string]string{"annotation-key": "annotation-value"}
otelcol := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
PodAnnotations: testPodAnnotationValues,
},
}
cfg := config.New()

// test
ds := DaemonSet(cfg, logger, otelcol)

// verify
assert.Equal(t, "my-instance-collector", ds.Name)
assert.Equal(t, testPodAnnotationValues, ds.Spec.Template.Annotations)
}
2 changes: 1 addition & 1 deletion pkg/collector/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Deployment(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTele
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: otelcol.Annotations,
Annotations: otelcol.Spec.PodAnnotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: ServiceAccountName(otelcol),
Expand Down
21 changes: 21 additions & 0 deletions pkg/collector/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,24 @@ func TestDeploymentNewDefault(t *testing.T) {
// the pod selector should match the pod spec's labels
assert.Equal(t, d.Spec.Template.Labels, d.Spec.Selector.MatchLabels)
}

func TestDeploymentPodAnnotations(t *testing.T) {
// prepare
testPodAnnotationValues := map[string]string{"annotation-key": "annotation-value"}
otelcol := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
PodAnnotations: testPodAnnotationValues,
},
}
cfg := config.New()

// test
d := Deployment(cfg, logger, otelcol)

// verify
assert.Equal(t, "my-instance-collector", d.Name)
assert.Equal(t, testPodAnnotationValues, d.Spec.Template.Annotations)
}
2 changes: 1 addition & 1 deletion pkg/collector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func StatefulSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTel
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: otelcol.Annotations,
Annotations: otelcol.Spec.PodAnnotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: ServiceAccountName(otelcol),
Expand Down
21 changes: 21 additions & 0 deletions pkg/collector/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,24 @@ func TestStatefulSetVolumeClaimTemplates(t *testing.T) {
// assert correct pvc storage
assert.Equal(t, resource.MustParse("1Gi"), ss.Spec.VolumeClaimTemplates[0].Spec.Resources.Requests["storage"])
}

func TestStatefulSetPodAnnotations(t *testing.T) {
// prepare
testPodAnnotationValues := map[string]string{"annotation-key": "annotation-value"}
otelcol := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
PodAnnotations: testPodAnnotationValues,
},
}
cfg := config.New()

// test
ss := StatefulSet(cfg, logger, otelcol)

// verify
assert.Equal(t, "my-instance-collector", ss.Name)
assert.Equal(t, testPodAnnotationValues, ss.Spec.Template.Annotations)
}
2 changes: 1 addition & 1 deletion pkg/targetallocator/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Deployment(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTele
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: otelcol.Annotations,
Annotations: otelcol.Spec.PodAnnotations,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{Container(cfg, logger, otelcol)},
Expand Down
21 changes: 21 additions & 0 deletions pkg/targetallocator/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ func TestDeploymentNewDefault(t *testing.T) {
// the pod selector should match the pod spec's labels
assert.Equal(t, d.Spec.Template.Labels, d.Spec.Selector.MatchLabels)
}

func TestDeploymentPodAnnotations(t *testing.T) {
// prepare
testPodAnnotationValues := map[string]string{"annotation-key": "annotation-value"}
otelcol := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
PodAnnotations: testPodAnnotationValues,
},
}
cfg := config.New()

// test
ds := Deployment(cfg, logger, otelcol)

// verify
assert.Equal(t, "my-instance-targetallocator", ds.Name)
assert.Equal(t, testPodAnnotationValues, ds.Spec.Template.Annotations)
}
14 changes: 14 additions & 0 deletions tests/e2e/smoke-pod-annotations/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pa-collector
annotations:
regular-annotation: regular-value
spec:
template:
metadata:
annotations:
pod-annotation1: value1
pod-annotation2: value2
status:
readyReplicas: 1
29 changes: 29 additions & 0 deletions tests/e2e/smoke-pod-annotations/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: pa
annotations:
regular-annotation: regular-value
spec:
podAnnotations:
pod-annotation1: value1
pod-annotation2: value2
config: |
receivers:
jaeger:
protocols:
grpc:
processors:

exporters:
logging:

service:
pipelines:
traces:
receivers: [jaeger]
processors: []
exporters: [logging]
args:
metrics-level: detailed
log-level: debug