Skip to content

[opentelemetry-kube-stack] Custom collectors missing empty volumes and volumeMounts arrays during dry-runs #1696

Open
@kitforbes

Description

@kitforbes

When using a custom collector (not a preset) without any volumes or volumeMounts, the chart will render an empty field (null)

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: custom
spec:
  volumeMounts:
  volumes:

This is fine during installation, but when working with something like Flux when driftDetection is enabled, this will throw an error as the spec won't accept null.

cannot determine release state: unable to determine cluster state: OpenTelemetryCollector/monitoring/otel-gateway dry-run failed (Invalid): OpenTelemetryCollector.opentelemetry.io "otel-gateway" is invalid: [spec.volumes: Invalid value: "null": spec.volumes in body must be of type array: "null", spec.volumeMounts: Invalid value: "null": spec.volumeMounts in body must be of type array: "null"]

Ideally the empty arrays would be declared

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: custom
spec:
  volumeMounts: []
  volumes: []

Copying the implementation from your securityContext, this could be implemented in this way:

diff --git a/charts/opentelemetry-kube-stack/templates/collector.yaml b/charts/opentelemetry-kube-stack/templates/collector.yaml
index d99459b5..eb0b579b 100644
--- a/charts/opentelemetry-kube-stack/templates/collector.yaml
+++ b/charts/opentelemetry-kube-stack/templates/collector.yaml
@@ -113,6 +113,7 @@ spec:
   {{- toYaml . | nindent 4}}
   {{- end }}
   volumeMounts:
+  {{- if or $collector.presets.logsCollection.enabled $collector.presets.hostMetrics.enabled $collector.volumeMounts }}
   {{- if $collector.presets.logsCollection.enabled }}
   - name: varlogpods
     mountPath: /var/log/pods
@@ -134,6 +135,9 @@ spec:
   {{- with $collector.volumeMounts }}
   {{- toYaml . | nindent 2 }}
   {{- end }}
+  {{- else }}
+  {{- toYaml $collector.volumeMounts | nindent 4 }}
+  {{- end }}
   {{- with $collector.ports }}
   ports:
   {{- toYaml . | nindent 4 }}
@@ -180,6 +184,7 @@ spec:
   {{- toYaml . | nindent 4 }}
   {{- end }}
   volumes:
+  {{- if or $collector.presets.logsCollection.enabled $collector.presets.hostMetrics.enabled $collector.volumes }}
   {{- if $collector.presets.logsCollection.enabled }}
   - name: varlogpods
     hostPath:
@@ -202,6 +207,9 @@ spec:
   {{- with $collector.volumes }}
   {{- toYaml . | nindent 2 }}
   {{- end }}
+  {{- else }}
+  {{- toYaml $collector.volumes | nindent 4 }}
+  {{- end }}
   {{- with $collector.initContainers }}
   initContainers:
   {{- toYaml . | nindent 4 }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions