From 5d8c8fabb959701cda3c594f6767bf42e1b0f1b9 Mon Sep 17 00:00:00 2001 From: Jason Crouse Date: Wed, 20 Mar 2024 15:50:38 -0400 Subject: [PATCH 1/4] copy opamp bridge chart from OCS to KOS --- charts/kube-otel-stack/Chart.yaml | 2 +- charts/kube-otel-stack/templates/_helpers.tpl | 43 ++++ charts/kube-otel-stack/templates/bridge.yaml | 184 ++++++++++++++++++ .../kube-otel-stack/templates/collector.yaml | 5 + charts/kube-otel-stack/values.yaml | 31 +++ 5 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 charts/kube-otel-stack/templates/bridge.yaml diff --git a/charts/kube-otel-stack/Chart.yaml b/charts/kube-otel-stack/Chart.yaml index bac0fea..b21be5d 100644 --- a/charts/kube-otel-stack/Chart.yaml +++ b/charts/kube-otel-stack/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: kube-otel-stack description: Chart for sending Kubernetes metrics to Lightstep using the OpenTelemetry Operator. type: application -version: 0.4.2 +version: 0.5.0 appVersion: 0.91.0 dependencies: # cert manager must be manually installed because it has CRDs diff --git a/charts/kube-otel-stack/templates/_helpers.tpl b/charts/kube-otel-stack/templates/_helpers.tpl index c26fb2a..60601cd 100644 --- a/charts/kube-otel-stack/templates/_helpers.tpl +++ b/charts/kube-otel-stack/templates/_helpers.tpl @@ -93,3 +93,46 @@ heritage: {{ $.Release.Service | quote }} {{- $userValue := index . 3 -}} {{- include "kube-otel-stack.kubeVersionDefaultValue" (list $values ">= 1.23-0" $insecure $secure $userValue) -}} {{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "opentelemetry-opamp-bridge.fullname" -}} +{{- if .fullnameOverride }} +{{- .fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.opAMPBridge.name }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "opentelemetry-collector.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "opentelemetry-opamp-bridge.labels" -}} +helm.sh/chart: {{ include "opentelemetry-collector.chart" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Create the name of the clusterRole to use for the opampbridge +*/}} +{{- define "opentelemetry-opamp-bridge.clusterRoleName" -}} +{{- printf "%s-bridge" .Release.Name }} +{{- end }} \ No newline at end of file diff --git a/charts/kube-otel-stack/templates/bridge.yaml b/charts/kube-otel-stack/templates/bridge.yaml new file mode 100644 index 0000000..d2eced9 --- /dev/null +++ b/charts/kube-otel-stack/templates/bridge.yaml @@ -0,0 +1,184 @@ +{{- if .Values.opAMPBridge.enabled }} +apiVersion: opentelemetry.io/v1alpha1 +kind: OpAMPBridge +metadata: + name: {{ include "opentelemetry-opamp-bridge.fullname" . }} + labels: + {{- include "otel-cloud-stack.labels" $ | indent 4 }} + {{- with $.Values.opAMPBridge.labels }} + {{- range $key, $value := . }} + {{- printf "%s: %s" $key (tpl $value $ | quote) | nindent 4 }} + {{- end }} + {{- end }} + {{- with $.Values.opAMPBridge.annotations }} + annotations: + {{- range $key, $value := . }} + {{- printf "%s: %s" $key (tpl $value $ | quote) | nindent 4 }} + {{- end }} + {{- end }} +spec: + {{- if $.Values.opAMPBridge.endpoint }} + endpoint: {{ $.Values.opAMPBridge.endpoint }} + {{- end }} + {{- with $.Values.opAMPBridge.headers }} + headers: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with $.Values.opAMPBridge.capabilities }} + capabilities: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with $.Values.opAMPBridge.componentsAllowed }} + componentsAllowed: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with $.Values.opAMPBridge.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 4}} + {{- end }} + {{- if $.Values.opAMPBridge.replicas }} + replicas: {{ $.Values.opAMPBridge.replicas }} + {{- end }} + {{- if $.Values.opAMPBridge.serviceAccount }} + serviceAccount: {{ $.Values.opAMPBridge.serviceAccount }} + {{- end }} + {{- if $.Values.opAMPBridge.image.digest }} + image: "{{ $.Values.opAMPBridge.image.repository }}@{{ $.Values.opAMPBridge.image.digest }}" + {{- else }} + image: "{{ $.Values.opAMPBridge.image.repository }}:{{ $.Values.opAMPBridge.image.tag | default $.Chart.AppVersion }}" + {{- end }} + {{- if $.Values.opAMPBridge.upgradeStrategy }} + upgradeStrategy: {{ $.Values.opAMPBridge.upgradeStrategy }} + {{- end }} + {{- if $.Values.opAMPBridge.imagePullPolicy }} + imagePullPolicy: {{ $.Values.opAMPBridge.imagePullPolicy }} + {{- end }} + {{- if $.Values.opAMPBridge.hostNetwork }} + hostNetwork: {{ $.Values.opAMPBridge.hostNetwork }} + {{- end }} + {{- if $.Values.opAMPBridge.priorityClassName }} + priorityClassName: {{ $.Values.opAMPBridge.priorityClassName }} + {{- end }} + {{- with $.Values.opAMPBridge.securityContext }} + securityContext: + {{- toYaml . | nindent 4}} + {{- end }} + {{- with $.Values.opAMPBridge.podAnnotations }} + podAnnotations: + {{- toYaml . | nindent 4}} + {{- end }} + {{- with $.Values.opAMPBridge.resources }} + resources: + {{- toYaml . | nindent 4}} + {{- end }} + {{- with $.Values.opAMPBridge.affinity }} + affinity: + {{- toYaml . | nindent 4}} + {{- end }} + {{- if $.Values.opAMPBridge.tolerations }} + tolerations: + {{- with $.Values.opAMPBridge.tolerations }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- if $.Values.opAMPBridge.volumes }} + volumes: + {{- with $.Values.opAMPBridge.volumes }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- if $.Values.opAMPBridge.topologySpreadConstraints }} + topologySpreadConstraints: + {{- with $.Values.opAMPBridge.topologySpreadConstraints }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- if $.Values.opAMPBridge.volumeMounts }} + volumeMounts: + {{- with $.Values.opAMPBridge.volumeMounts }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- if $.Values.opAMPBridge.ports }} + ports: + {{- with $.Values.opAMPBridge.ports }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} + env: + {{- with $.Values.extraEnvs }} + {{- toYaml . | nindent 4 }} + {{- end }} + - name: OTEL_K8S_NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: OTEL_K8S_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: OTEL_K8S_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_K8S_POD_UID + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.uid + - name: OTEL_K8S_POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP + - name: OTEL_RESOURCE_ATTRIBUTES + value: "k8s.cluster.name={{ $.Values.clusterName }}" + {{- with $.Values.opAMPBridge.env }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if $.Values.opAMPBridge.envFrom }} + envFrom: + {{- with $.Values.opAMPBridge.envFrom }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "opentelemetry-opamp-bridge.clusterRoleName" . }} +rules: + - apiGroups: + - opentelemetry.io + resources: + - opentelemetrycollectors + verbs: + - "*" + - apiGroups: + - "" + resources: + - pods + verbs: + - 'list' + - 'get' +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "opentelemetry-opamp-bridge.fullname" . }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: "{{ include "opentelemetry-opamp-bridge.clusterRoleName" . }}" +subjects: + - kind: ServiceAccount + # quirk of the Operator + {{- if $.Values.opAMPBridge.serviceAccount }} + name: "{{ $.Values.opAMPBridge.serviceAccount }}" + {{- else }} + name: "{{ (include "opentelemetry-opamp-bridge.fullname" .) }}-opamp-bridge" + {{- end }} + namespace: "{{ $.Release.Namespace }}" +{{- end }} \ No newline at end of file diff --git a/charts/kube-otel-stack/templates/collector.yaml b/charts/kube-otel-stack/templates/collector.yaml index 29d3e41..8dabcde 100644 --- a/charts/kube-otel-stack/templates/collector.yaml +++ b/charts/kube-otel-stack/templates/collector.yaml @@ -11,6 +11,11 @@ metadata: {{- toYaml . | nindent 4}} {{- end }} labels: + {{- if and $.Values.opAMPBridge.enabled $.Values.opAMPBridge.addReportingLabel }} + opentelemetry.io/opamp-reporting: "true" + {{- else if and $.Values.opAMPBridge.enabled $.Values.opAMPBridge.addManagedLabel }} + opentelemetry.io/opamp-managed: "true" + {{- end }} {{- include "kube-otel-stack.labels" $ | indent 4 }} spec: mode: {{ $collector.mode }} diff --git a/charts/kube-otel-stack/values.yaml b/charts/kube-otel-stack/values.yaml index 6708428..9916ef3 100644 --- a/charts/kube-otel-stack/values.yaml +++ b/charts/kube-otel-stack/values.yaml @@ -1242,3 +1242,34 @@ prometheus-node-exporter: ## If true, create PSPs for node-exporter ## pspEnabled: false + +opAMPBridge: + enabled: false + # Adds `opentelemetry.io/opamp-reporting: true` to all collectors + addReportingLabel: true + # Adds `opentelemetry.io/opamp-managed: true` to all collectors + addManagedLabel: false + image: + repository: ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge + tag: "0.96.0" + endpoint: "wss://opamp.lightstep.com/v1/opamp" + headers: + "Authorization": "bearer ${LS_OPAMP_API_KEY}" + env: + - name: LS_OPAMP_API_KEY + valueFrom: + secretKeyRef: + key: LS_OPAMP_API_KEY + name: otel-opamp-bridge-secret + capabilities: + AcceptsOpAMPConnectionSettings: true + AcceptsOtherConnectionSettings: true + AcceptsRemoteConfig: true + AcceptsRestartCommand: true + ReportsEffectiveConfig: true + ReportsHealth: true + ReportsOwnLogs: true + ReportsOwnMetrics: true + ReportsOwnTraces: true + ReportsRemoteConfig: true + ReportsStatus: true From 9b36f83e111e0f5f8bed0f009bd9132068b187b2 Mon Sep 17 00:00:00 2001 From: Jason Crouse Date: Wed, 20 Mar 2024 15:54:02 -0400 Subject: [PATCH 2/4] fix name and add bridge labels --- charts/kube-otel-stack/templates/bridge.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/charts/kube-otel-stack/templates/bridge.yaml b/charts/kube-otel-stack/templates/bridge.yaml index d2eced9..c73202a 100644 --- a/charts/kube-otel-stack/templates/bridge.yaml +++ b/charts/kube-otel-stack/templates/bridge.yaml @@ -4,7 +4,8 @@ kind: OpAMPBridge metadata: name: {{ include "opentelemetry-opamp-bridge.fullname" . }} labels: - {{- include "otel-cloud-stack.labels" $ | indent 4 }} + {{- include "kube-otel-stack.labels" $ | indent 4 }} + {{- include "opentelemetry-opamp-bridge.labels" $ | indent 4 }} {{- with $.Values.opAMPBridge.labels }} {{- range $key, $value := . }} {{- printf "%s: %s" $key (tpl $value $ | quote) | nindent 4 }} From 20b4a478c35ce952c43b83ace4f0ed9d8441decf Mon Sep 17 00:00:00 2001 From: Jason Crouse Date: Wed, 20 Mar 2024 16:10:09 -0400 Subject: [PATCH 3/4] rm labels helper that does duplicate work --- charts/kube-otel-stack/templates/_helpers.tpl | 17 ----------------- charts/kube-otel-stack/templates/bridge.yaml | 3 +-- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/charts/kube-otel-stack/templates/_helpers.tpl b/charts/kube-otel-stack/templates/_helpers.tpl index 60601cd..896fad0 100644 --- a/charts/kube-otel-stack/templates/_helpers.tpl +++ b/charts/kube-otel-stack/templates/_helpers.tpl @@ -112,23 +112,6 @@ If release name contains chart name it will be used as a full name. {{- end }} {{- end }} -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "opentelemetry-collector.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "opentelemetry-opamp-bridge.labels" -}} -helm.sh/chart: {{ include "opentelemetry-collector.chart" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} {{/* Create the name of the clusterRole to use for the opampbridge diff --git a/charts/kube-otel-stack/templates/bridge.yaml b/charts/kube-otel-stack/templates/bridge.yaml index c73202a..c931b4f 100644 --- a/charts/kube-otel-stack/templates/bridge.yaml +++ b/charts/kube-otel-stack/templates/bridge.yaml @@ -2,10 +2,9 @@ apiVersion: opentelemetry.io/v1alpha1 kind: OpAMPBridge metadata: - name: {{ include "opentelemetry-opamp-bridge.fullname" . }} + name: {{ include "opentelemetry-opamp-bridge.fullname" $ }} labels: {{- include "kube-otel-stack.labels" $ | indent 4 }} - {{- include "opentelemetry-opamp-bridge.labels" $ | indent 4 }} {{- with $.Values.opAMPBridge.labels }} {{- range $key, $value := . }} {{- printf "%s: %s" $key (tpl $value $ | quote) | nindent 4 }} From a4263a0079979e0a066bd9c151bdbd9b478a83eb Mon Sep 17 00:00:00 2001 From: Jason Crouse Date: Wed, 20 Mar 2024 16:11:27 -0400 Subject: [PATCH 4/4] newlines --- charts/kube-otel-stack/templates/_helpers.tpl | 2 +- charts/kube-otel-stack/templates/bridge.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/kube-otel-stack/templates/_helpers.tpl b/charts/kube-otel-stack/templates/_helpers.tpl index 896fad0..1632ca8 100644 --- a/charts/kube-otel-stack/templates/_helpers.tpl +++ b/charts/kube-otel-stack/templates/_helpers.tpl @@ -118,4 +118,4 @@ Create the name of the clusterRole to use for the opampbridge */}} {{- define "opentelemetry-opamp-bridge.clusterRoleName" -}} {{- printf "%s-bridge" .Release.Name }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/kube-otel-stack/templates/bridge.yaml b/charts/kube-otel-stack/templates/bridge.yaml index c931b4f..ca9c72a 100644 --- a/charts/kube-otel-stack/templates/bridge.yaml +++ b/charts/kube-otel-stack/templates/bridge.yaml @@ -181,4 +181,4 @@ subjects: name: "{{ (include "opentelemetry-opamp-bridge.fullname" .) }}-opamp-bridge" {{- end }} namespace: "{{ $.Release.Namespace }}" -{{- end }} \ No newline at end of file +{{- end }}