Skip to content

Commit

Permalink
feat(chart): install OpenTelemetry collector via operator helm chart
Browse files Browse the repository at this point in the history
(by including the official OpenTelemetry collector helm chart as a
dependency/sub-chart)

Also: Install the OpenTelemetry collector instance into the operator's
namespace instead of installing it into each monitored namespace.
  • Loading branch information
basti1302 committed Jun 7, 2024
1 parent e534a19 commit d4ea82c
Show file tree
Hide file tree
Showing 32 changed files with 413 additions and 219 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,16 @@ undeploy-via-kustomize: ## Undeploy the controller via kustomize from the K8s cl

.PHONY: deploy-via-helm
deploy-via-helm: ## Deploy the controller via helm to the K8s cluster specified in ~/.kube/config.
helm install --namespace dash0-operator-system --create-namespace --set operator.image.repository=${IMG_REPOSITORY} --set operator.image.tag=${IMG_TAG} --set operator.image.pullPolicy=Never dash0-operator helm-chart/dash0-operator
test-resources/bin/render-templates.sh manual-testing
helm install \
--namespace dash0-operator-system \
--create-namespace \
--values test-resources/helm/manual.values.yaml \
--set operator.image.repository=${IMG_REPOSITORY} \
--set operator.image.tag=${IMG_TAG} \
dash0-operator \
helm-chart/dash0-operator


.PHONY: undeploy-via-helm
undeploy-via-helm: ## Undeploy the controller via helm from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand Down
30 changes: 20 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ func startOperatorManager(
return fmt.Errorf("unable to create the clientset client")
}

otelCollectorBaseUrl, isSet := os.LookupEnv("DASH0_OTEL_COLLECTOR_BASE_URL")
if !isSet {
return fmt.Errorf("cannot start Dash0 operator, the mandatory environment variable " +
"\"DASH0_OTEL_COLLECTOR_BASE_URL\" is missing")
}

operatorImage, isSet := os.LookupEnv("DASH0_OPERATOR_IMAGE")
if !isSet {
return fmt.Errorf("cannot start Dash0 operator, the mandatory environment variable " +
Expand All @@ -165,13 +171,15 @@ func startOperatorManager(
}
}
setupLog.Info(
"version information",
"operator image and version",
"configuration:",
"operator image",
operatorImage,
"init container image and version",
"init container image",
initContainerImage,
"init container image pull policy override",
initContainerImagePullPolicy,
"otel collector base url",
otelCollectorBaseUrl,
)

images := util.Images{
Expand All @@ -181,20 +189,22 @@ func startOperatorManager(
}

if err = (&controller.Dash0Reconciler{
Client: mgr.GetClient(),
ClientSet: clientSet,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("dash0-controller"),
Images: images,
Client: mgr.GetClient(),
ClientSet: clientSet,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("dash0-controller"),
Images: images,
OtelCollectorBaseUrl: otelCollectorBaseUrl,
}).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to set up the Dash0 reconciler: %w", err)
}
setupLog.Info("Dash0 reconciler has been set up.")

if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&dash0webhook.Handler{
Recorder: mgr.GetEventRecorderFor("dash0-webhook"),
Images: images,
Recorder: mgr.GetEventRecorderFor("dash0-webhook"),
Images: images,
OtelCollectorBaseUrl: otelCollectorBaseUrl,
}).SetupWebhookWithManager(mgr); err != nil {
return fmt.Errorf("unable to create the Dash0 webhook: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions helm-chart/dash0-operator/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: opentelemetry-collector
repository: https://open-telemetry.github.io/opentelemetry-helm-charts
version: 0.93.1
digest: sha256:0d1653fa32255a0807c9a6757d7fe58abfb466a530fd6161993747955514ee4e
generated: "2024-06-07T10:59:38.555357+02:00"
5 changes: 5 additions & 0 deletions helm-chart/dash0-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ maintainers:
email: [email protected]
icon: icon/logo.svg
appVersion: "1.0.0"
dependencies:
- name: opentelemetry-collector
version: 0.93.1
repository: https://open-telemetry.github.io/opentelemetry-helm-charts
condition: opentelemetry-collector.enabled
1 change: 1 addition & 0 deletions helm-chart/dash0-operator/charts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tgz
14 changes: 14 additions & 0 deletions helm-chart/dash0-operator/templates/operator/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ spec:
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
env:
- name: DASH0_OTEL_COLLECTOR_BASE_URL
{{/*
Note: This reuses an internal template of the opentelmetry-collector Helm chart, to make sure we render the
exact same service name for the collector URL as the collector Helm chart does. This might need to be updated
if the collector Helm chart changes its service name template. Since we control the version of the collector
Helm chart we use and run rigorous tests when updating to a newer version, this approach should be safe.
*/}}
{{ $collectorSubChartValues :=
dict
"Values" (index .Values "opentelemetry-collector")
"Chart" (dict "Name" "opentelemetry-collector")
"Release" .Release
}}
value: http://{{ include "opentelemetry-collector.fullname" $collectorSubChartValues }}.{{ .Release.Namespace }}.svc.cluster.local:4318
- name: DASH0_OPERATOR_IMAGE
value: {{ include "dash0-operator.image" . | quote }}
- name: DASH0_INIT_CONTAINER_IMAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ deployment should match snapshot (default values):
command:
- /manager
env:
- name: DASH0_OTEL_COLLECTOR_BASE_URL
value: http://RELEASE-NAME-opentelemetry-collector.NAMESPACE.svc.cluster.local:4318
- name: DASH0_OPERATOR_IMAGE
value: dash0-operator-controller:1.0.0
- name: DASH0_INIT_CONTAINER_IMAGE
Expand Down
16 changes: 11 additions & 5 deletions helm-chart/dash0-operator/tests/operator/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,27 @@ tests:
value: Never
- equal:
path: spec.template.spec.containers[0].env[0].name
value: DASH0_OPERATOR_IMAGE
value: DASH0_OTEL_COLLECTOR_BASE_URL
- equal:
path: spec.template.spec.containers[0].env[0].value
value: http://RELEASE-NAME-opentelemetry-collector.NAMESPACE.svc.cluster.local:4318
- equal:
path: spec.template.spec.containers[0].env[1].name
value: DASH0_OPERATOR_IMAGE
- equal:
path: spec.template.spec.containers[0].env[1].value
value: custom-operator-image:1.2.3
- equal:
path: spec.template.spec.containers[0].env[1].name
path: spec.template.spec.containers[0].env[2].name
value: DASH0_INIT_CONTAINER_IMAGE
- equal:
path: spec.template.spec.containers[0].env[1].value
path: spec.template.spec.containers[0].env[2].value
value: custom-init-container-image:4.5.6
- equal:
path: spec.template.spec.containers[0].env[2].name
path: spec.template.spec.containers[0].env[3].name
value: DASH0_INIT_CONTAINER_IMAGE_PULL_POLICY
- equal:
path: spec.template.spec.containers[0].env[2].value
path: spec.template.spec.containers[0].env[3].value
value: Always
- equal:
path: spec.template.spec.containers[0].resources.limits.cpu
Expand Down
88 changes: 84 additions & 4 deletions helm-chart/dash0-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,88 @@ operator:
pullPolicy:

# the image pull secrets to pull the container images
imagePullSecrets: []
imagePullSecrets: [ ]

# settings for the OpenTelemetry collector instance
collector:
placeholder: "value"
# settings for the OpenTelemetry collector instance that Dash0 will use for reporting data to Dash0
opentelemetry-collector:
enabled: true

image:
repository: otel/opentelemetry-collector-k8s

mode: daemonset

service:
enabled: true

presets:
kubernetesAttributes:
enabled: true
# kubeletMetrics:
# enabled: true

additionalLabels:
dash0.com/opt-out: "true"

resources:
limits:
memory: 500Mi

config:
extensions:
bearertokenauth/dash0:
scheme: "Bearer"
# needs to be provided via --set or an additional values file for now
token:

receivers:
jaeger: {}
prometheus: {}
zipkin: {}

exporters:
otlp:
auth:
authenticator: bearertokenauth/dash0
# needs to be provided via --set or an additional values file for now
endpoint:

service:
pipelines:
traces:
receivers:
- otlp
processors:
- k8sattributes
- memory_limiter
- batch
exporters:
- otlp
metrics:
receivers:
- otlp
processors:
- k8sattributes
- memory_limiter
- batch
exporters:
- otlp
logs:
receivers:
- otlp
processors:
- k8sattributes
- memory_limiter
- batch
exporters:
- otlp

ports:
jaeger-compact:
enabled: false
jaeger-thrift:
enabled: false
jaeger-grpc:
enabled: false
zipkin:
enabled: false
Loading

0 comments on commit d4ea82c

Please sign in to comment.