Skip to content

Commit

Permalink
add OTEL trace env for helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: KubeKyrie <[email protected]>
  • Loading branch information
KubeKyrie committed Dec 5, 2023
1 parent d65f4a3 commit b275818
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 5 deletions.
51 changes: 48 additions & 3 deletions charts/clusterpedia-core/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ initContainers:
{{- end -}}

{{- define "clusterpedia.volumes" -}}
{{- if or (include "clusterpedia.storage.configmap.name" .) (include "clusterpedia.storage.plugin.initContainer" .) }}
{{- if or .Values.telemetry.tracing.enabled (include "clusterpedia.storage.configmap.name" .) (include "clusterpedia.storage.plugin.initContainer" .) }}
volumes:
{{- if .Values.telemetry.tracing.enabled }}
- name: tracing-config
configMap:
name: clusterpedia-tracing-config
{{- end }}
{{- if (include "clusterpedia.storage.configmap.name" .) }}
- name: storage-config
configMap:
Expand All @@ -154,8 +159,13 @@ volumes:
{{- end -}}

{{- define "clusterpedia.volumeMounts" -}}
{{- if or (include "clusterpedia.storage.configmap.name" .) (include "clusterpedia.storage.plugin.initContainer" .) }}
{{- if or .Values.telemetry.tracing.enabled (include "clusterpedia.storage.configmap.name" .) (include "clusterpedia.storage.plugin.initContainer" .) }}
volumeMounts:
{{- if .Values.telemetry.tracing.enabled }}
- name: tracing-config
mountPath: /etc/clusterpedia/trace
readOnly: true
{{- end }}
{{- if (include "clusterpedia.storage.configmap.name" .) }}
- name: storage-config
mountPath: /etc/clusterpedia/storage
Expand All @@ -170,12 +180,15 @@ volumeMounts:
{{- end -}}

{{- define "clusterpedia.apiserver.env" -}}
{{- if or .Values.apiserver.enableSHA1Cert .Values.storage.componentEnv (include "clusterpedia.storage.override.componentEnv" .) (include "clusterpedia.storage.plugin.initContainer" .) }}
{{- if or .Values.apiserver.enableSHA1Cert .Values.storage.componentEnv (include "clusterpedia.storage.override.componentEnv" .) (include "clusterpedia.storage.plugin.initContainer" .) (include "clusterpedia.tracing.env" .) }}
env:
{{- if (include "clusterpedia.storage.plugin.initContainer" .) }}
- name: STORAGE_PLUGINS
value: /var/lib/clusterpedia/plugins
{{- end }}
{{- if (include "clusterpedia.tracing.env" .) }}
{{ include "clusterpedia.tracing.env" . }}
{{- end }}
{{- if .Values.apiserver.enableSHA1Cert }}
- name: GODEBUG
value: x509sha1=1
Expand All @@ -188,6 +201,32 @@ env:
{{- end }}
{{- end -}}

{{- define "clusterpedia.tracing.env" -}}
{{- if and (.Values.telemetry.tracing.enabled) (.Values.telemetry.tracing.addOtelEnv) }}
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.telemetry.tracing.endpoint }}
- name: 'OTEL_SERVICE_NAME'
value: {{ include "common.names.fullname" . }}-apiserver
- name: 'OTEL_K8S_NAMESPACE'
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: OTEL_RESOURCE_ATTRIBUTES
value: 'k8s.namespace.name=$(OTEL_K8S_NAMESPACE),k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)'
{{- end }}
{{- end -}}

{{- define "clusterpedia.clustersynchroManager.env" -}}
{{- if or .Values.storage.componentEnv (include "clusterpedia.storage.override.componentEnv" .) (include "clusterpedia.storage.plugin.initContainer" .) }}
env:
Expand All @@ -202,3 +241,9 @@ env:
{{- end }}
{{- end }}
{{- end -}}

{{- define "clusterpedia.tracing.args" -}}
{{- if .Values.telemetry.tracing.enabled }}
- --tracing-config-file=/etc/clusterpedia/trace/tracing-config.yaml
{{- end }}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
command:
- /usr/local/bin/apiserver
- --secure-port=443
{{- include "clusterpedia.tracing.args" . | nindent 8}}
{{- if .Values.storage.name }}
- --storage-name={{ .Values.storage.name }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.telemetry.tracing.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: clusterpedia-tracing-config
namespace: {{ .Release.Namespace }}
data:
tracing-config.yaml: |
apiVersion: apiserver.config.k8s.io/v1beta1
kind: TracingConfiguration
endpoint: {{ .Values.telemetry.tracing.endpoint }}
samplingRatePerMillion: {{ .Values.telemetry.tracing.samplingRatePerMillion }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/clusterpedia-core/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ commonLabels: {}
## @param commonAnnotations Annotations to add to all deployed objects
##
commonAnnotations: {}
## @param telemetry define flag whether to enable otel trace
##
telemetry:
tracing:
enabled: false
endpoint: "localhost:4317"
samplingRatePerMillion: 1000000
addOtelEnv: false

## clusterpedia apiserver config
apiserver:
Expand Down
2 changes: 1 addition & 1 deletion charts/clusterpedia/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.0.0
version: 2.0.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
5 changes: 4 additions & 1 deletion charts/clusterpedia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ rm /var/local/clusterpedia/internalstorage/<storage type>
| postgresql.primary.persistence.enabled | bool | `true` | |
| postgresql.primary.persistence.size | string | `"10Gi"` | |
| storageInstallMode | string | `"internal"` | |
| telemetry.tracing.addr | string | `""` | |
| telemetry.tracing.enabled | bool | `false` | |

### StorageConfig

Expand Down Expand Up @@ -248,6 +250,7 @@ rm /var/local/clusterpedia/internalstorage/<storage type>
| clustersynchroManager.image.registry | string | `"ghcr.io"` | |
| clustersynchroManager.image.repository | string | `"clusterpedia-io/clusterpedia/clustersynchro-manager"` | |
| clustersynchroManager.image.tag | string | `"v0.7.0"` | |
| clustersynchroManager.kubeStateMetrics.enabled | bool | `false` | |
| clustersynchroManager.labels | object | `{}` | |
| clustersynchroManager.leaderElect.leaseDuration | string | `"15s"` | |
| clustersynchroManager.leaderElect.renewDeadline | string | `"10s"` | |
Expand Down Expand Up @@ -281,4 +284,4 @@ rm /var/local/clusterpedia/internalstorage/<storage type>
| controllerManager.tolerations | list | `[]` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs)
Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs)
32 changes: 32 additions & 0 deletions charts/clusterpedia/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,35 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- define "clusterpedia.hookJob.image" -}}
{{ include "common.images.image" (dict "imageRoot" .Values.hookJob.image "global" .Values.global) }}
{{- end -}}

{{- define "clusterpedia.tracing.env" -}}
{{- if and (.Values.telemetry.tracing.enabled) (.Values.telemetry.tracing.addOtelEnv) }}
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.telemetry.tracing.endpoint }}
- name: 'OTEL_SERVICE_NAME'
value: {{ include "common.names.fullname" . }}-apiserver
- name: 'OTEL_K8S_NAMESPACE'
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: OTEL_RESOURCE_ATTRIBUTES
value: 'k8s.namespace.name=$(OTEL_K8S_NAMESPACE),k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)'
{{- end -}}
{{- end -}}

{{- define "clusterpedia.tracing.args" -}}
{{- if .Values.telemetry.tracing.enabled }}
- --tracing-config-file=/etc/clusterpedia/trace/tracing-config.yaml
{{- end -}}
{{- end -}}
12 changes: 12 additions & 0 deletions charts/clusterpedia/templates/apiserver-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ spec:
- /usr/local/bin/apiserver
- --secure-port=443
- --storage-config=/etc/clusterpedia/storage/internalstorage-config.yaml
{{- include "clusterpedia.tracing.args" . | nindent 8}}
{{- with (include "clusterpedia.apiserver.featureGates" .) }}
- {{ . }}
{{- end }}
Expand All @@ -132,6 +133,7 @@ spec:
secretKeyRef:
name: {{ include "clusterpedia.internalstorage.fullname" . }}
key: password
{{- include "clusterpedia.tracing.env" . | nindent 8 }}
{{- if .Values.apiserver.enableSHA1Cert }}
- name: GODEBUG
value: netdns=go,x509sha1=1
Expand All @@ -143,6 +145,11 @@ spec:
- name: internalstorage-config
mountPath: /etc/clusterpedia/storage
readOnly: true
{{- if .Values.telemetry.tracing.enabled }}
- name: tracing-config
mountPath: /etc/clusterpedia/trace
readOnly: true
{{- end }}
serviceAccountName: {{ include "clusterpedia.apiserver.fullname" . }}
{{- if .Values.apiserver.affinity }}
affinity: {{- include "common.tplvalues.render" (dict "value" .Values.apiserver.affinity "context" $) | nindent 8 }}
Expand All @@ -160,3 +167,8 @@ spec:
- name: scripts
configMap:
name: {{ include "clusterpedia.scripts.fullname" . }}
{{- if .Values.telemetry.tracing.enabled }}
- name: tracing-config
configMap:
name: clusterpedia-tracing-config
{{- end }}
13 changes: 13 additions & 0 deletions charts/clusterpedia/templates/clusterpedia-tracing-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.telemetry.tracing.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: clusterpedia-tracing-config
namespace: {{ .Release.Namespace }}
data:
tracing-config.yaml: |
apiVersion: apiserver.config.k8s.io/v1beta1
kind: TracingConfiguration
endpoint: {{ .Values.telemetry.tracing.endpoint }}
samplingRatePerMillion: {{ .Values.telemetry.tracing.samplingRatePerMillion }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/clusterpedia/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ commonAnnotations: {}
## if PV resources are not required, set it to None!
## if defined, will create the pv on the node.
persistenceMatchNode: ""
## @param telemetry define flag whether to enable otel trace
##
telemetry:
tracing:
enabled: false
endpoint: "localhost:4317"
samplingRatePerMillion: 1000000
addOtelEnv: true

## @param storageConfig StorageConfig for the apiserver and clustersynchro manger
##
Expand Down

0 comments on commit b275818

Please sign in to comment.