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

feat(backendconnection): configurable resource limits for collector #160

Merged
merged 2 commits into from
Sep 30, 2024
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
16 changes: 16 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const (

developmentModeEnvVarName = "DASH0_DEVELOPMENT_MODE"

oTelColResourceSpecConfigFile = "/etc/config/otelcolresources.yaml"

//nolint
mandatoryEnvVarMissingMessageTemplate = "cannot start the Dash0 operator, the mandatory environment variable \"%s\" is missing"

Expand Down Expand Up @@ -405,6 +407,14 @@ func readEnvironmentVariables() error {
return nil
}

func readConfiguration() (*otelcolresources.OTelColResourceSpecs, error) {
oTelColResourceSpec, err := otelcolresources.ReadOTelColResourcesConfiguration(oTelColResourceSpecConfigFile)
if err != nil {
return nil, fmt.Errorf("Cannot read configuration file %s: %w", oTelColResourceSpecConfigFile, err)
}
return oTelColResourceSpec, nil
}

func readOptionalPullPolicyFromEnvironmentVariable(envVarName string) corev1.PullPolicy {
pullPolicyRaw := os.Getenv(envVarName)
if pullPolicyRaw != "" {
Expand All @@ -428,6 +438,11 @@ func startDash0Controllers(
operatorConfiguration *startup.OperatorConfigurationValues,
developmentMode bool,
) error {
oTelColResourceSpecs, err := readConfiguration()
if err != nil {
os.Exit(1)
}

oTelCollectorBaseUrl :=
fmt.Sprintf(
"http://%s-opentelemetry-collector.%s.svc.cluster.local:4318",
Expand Down Expand Up @@ -470,6 +485,7 @@ func startDash0Controllers(
Scheme: mgr.GetScheme(),
DeploymentSelfReference: deploymentSelfReference,
OTelCollectorNamePrefix: envVars.oTelCollectorNamePrefix,
OTelColResourceSpecs: oTelColResourceSpecs,
DevelopmentMode: developmentMode,
}
backendConnectionManager := &backendconnection.BackendConnectionManager{
Expand Down
5 changes: 5 additions & 0 deletions helm-chart/dash0-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ helm.sh/chart: {{ include "dash0-operator.chartNameWithVersion" . }}
{{- default (printf "%s-controller" (include "dash0-operator.chartName" .)) .Values.operator.serviceAccount.name }}
{{- end }}

{{/* otelcol resources config map name */}}
{{- define "dash0-operator.collectorResourceConfigMapName" -}}
{{ include "dash0-operator.chartName" . }}-collector-resources
{{- end }}

{{- define "dash0-operator.deploymentName" -}}
{{ include "dash0-operator.chartName" . }}-controller
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ kind: Secret
type: kubernetes.io/tls
metadata:
name: {{ include "dash0-operator.chartName" . }}-certificates
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: dash0-operator
app.kubernetes.io/component: certificates
Expand Down Expand Up @@ -152,11 +153,14 @@ spec:
name: webhook-server
protocol: TCP
resources:
{{- toYaml .Values.operator.managerPodResources | nindent 10 }}
{{- toYaml .Values.operator.managerContainerResources | nindent 10 }}
{{ include "dash0-operator.restrictiveContainerSecurityContext" . | nindent 8 }}
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: certificates
- name: certificates
mountPath: /tmp/k8s-webhook-server/serving-certs
readOnly: true
- name: config-volume
mountPath: /etc/config
readOnly: true
livenessProbe:
httpGet:
Expand All @@ -182,7 +186,7 @@ spec:
name: https
protocol: TCP
resources:
{{- toYaml .Values.operator.kubeRbacProxyPodResources | nindent 10 }}
{{- toYaml .Values.operator.kubeRbacProxyContainerResources | nindent 10 }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand All @@ -204,11 +208,15 @@ spec:
secret:
defaultMode: 420
secretName: {{ include "dash0-operator.chartName" . }}-certificates
- name: config-volume
configMap:
name: {{ template "dash0-operator.collectorResourceConfigMapName" . }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ template "dash0-operator.chartName" . }}-webhook-service
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: dash0-operator
app.kubernetes.io/component: webhook-service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "dash0-operator.collectorResourceConfigMapName" . }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: dash0-operator
app.kubernetes.io/component: controller
app.kubernetes.io/instance: collector-resources-config-map
{{- include "dash0-operator.labels" . | nindent 4 }}

data:
otelcolresources.yaml: |-
collectorDaemonSetCollectorContainerResources:
{{- toYaml .Values.operator.collectorDaemonSetCollectorContainerResources | nindent 6 }}
collectorDaemonSetConfigurationReloaderContainerResources:
{{- toYaml .Values.operator.collectorDaemonSetConfigurationReloaderContainerResources | nindent 6 }}
collectorDaemonSetFileLogOffsetSynchContainerResources:
{{- toYaml .Values.operator.collectorDaemonSetFileLogOffsetSynchContainerResources | nindent 6 }}

collectorDeploymentCollectorContainerResources:
{{- toYaml .Values.operator.collectorDeploymentCollectorContainerResources | nindent 6 }}
collectorDeploymentConfigurationReloaderContainerResources:
{{- toYaml .Values.operator.collectorDeploymentConfigurationReloaderContainerResources | nindent 6 }}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
- "--uninstrument-all"
{{ include "dash0-operator.restrictiveContainerSecurityContext" . | nindent 10 }}
resources:
{{- toYaml .Values.operator.managerPodResources | nindent 12 }}
{{- toYaml .Values.operator.managerContainerResources | nindent 12 }}
securityContext:
runAsNonRoot: true
serviceAccountName: {{ template "dash0-operator.serviceAccountName" . }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ deployment should match snapshot (default values):
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: certificates
readOnly: true
- mountPath: /etc/config
name: config-volume
readOnly: true
- args:
- --secure-listen-address=0.0.0.0:8443
- --upstream=http://127.0.0.1:8080/
Expand Down Expand Up @@ -138,6 +141,9 @@ deployment should match snapshot (default values):
secret:
defaultMode: 420
secretName: dash0-operator-certificates
- configMap:
name: dash0-operator-collector-resources
name: config-volume
metrics service should match snapshot (default settings):
1: |
apiVersion: v1
Expand Down Expand Up @@ -177,6 +183,7 @@ webhook service should match snapshot (default settings):
app.kubernetes.io/version: 0.0.0
helm.sh/chart: dash0-operator-0.0.0
name: dash0-operator-webhook-service
namespace: NAMESPACE
spec:
ports:
- port: 443
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
otelcol resources config map should match snapshot:
1: |
apiVersion: v1
data:
otelcolresources.yaml: |-
collectorDaemonSetCollectorContainerResources:
gomemlimit: 400MiB
limits:
memory: 500Mi
requests:
memory: 500Mi
collectorDaemonSetConfigurationReloaderContainerResources:
gomemlimit: 8MiB
limits:
memory: 12Mi
requests:
memory: 12Mi
collectorDaemonSetFileLogOffsetSynchContainerResources:
gomemlimit: 24MiB
limits:
memory: 32Mi
requests:
memory: 32Mi

collectorDeploymentCollectorContainerResources:
gomemlimit: 400MiB
limits:
memory: 500Mi
requests:
memory: 500Mi
collectorDeploymentConfigurationReloaderContainerResources:
gomemlimit: 8MiB
limits:
memory: 12Mi
requests:
memory: 12Mi
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: collector-resources-config-map
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: dash0-operator
app.kubernetes.io/part-of: dash0-operator
app.kubernetes.io/version: 0.0.0
helm.sh/chart: dash0-operator-0.0.0
name: dash0-operator-collector-resources
namespace: NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ tests:
repository: custom-filelog-offset-synch-image
tag: "13.14.15"
pullPolicy: Never
managerPodResources:
managerContainerResources:
limits:
cpu: 123m
memory: 456Mi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
suite: test otelcol resources config map
templates:
- operator/otelcol-resources-config-map.yaml
tests:
- it: otelcol resources config map should match snapshot
asserts:
- matchSnapshot: {}
70 changes: 66 additions & 4 deletions helm-chart/dash0-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ operator:
# label2: "value 2"
podLabels: {}

# resources for the controller manager pod(s)
managerPodResources:
# resources for the controller manager container
managerContainerResources:
limits:
cpu: 500m
memory: 128Mi
Expand All @@ -100,8 +100,8 @@ operator:
memory: 64Mi
ephemeral-storage: 500Mi

# resources for the kube-rbac-proxy pod(s)
kubeRbacProxyPodResources:
# resources for the kube-rbac-proxy container
kubeRbacProxyContainerResources:
limits:
cpu: 500m
memory: 128Mi
Expand All @@ -111,6 +111,68 @@ operator:
memory: 64Mi
ephemeral-storage: 500Mi

collectorDaemonSetCollectorContainerResources:
limits:
# cpu: (no cpu limit by default)
memory: 500Mi
# storage: (no storage limit by default)
# ephemeral-storage: (no ephemeral-storage limit by default)
gomemlimit: 400MiB
requests:
# cpu: (no cpu request by default)
memory: 500Mi
# storage: (no storage request by default)
# ephemeral-storage: (no ephemeral-storage request by default)
collectorDaemonSetConfigurationReloaderContainerResources:
limits:
# cpu: (no cpu limit by default)
memory: 12Mi
# storage: (no storage limit by default)
# ephemeral-storage: (no ephemeral-storage limit by default)
gomemlimit: 8MiB
requests:
# cpu: (no cpu request by default)
memory: 12Mi
# storage: (no storage request by default)
# ephemeral-storage: (no ephemeral-storage request by default)
collectorDaemonSetFileLogOffsetSynchContainerResources:
limits:
# cpu: (no cpu limit by default)
memory: 32Mi
# storage: (no storage limit by default)
# ephemeral-storage: (no ephemeral-storage limit by default)
gomemlimit: 24MiB
requests:
# cpu: (no cpu request by default)
memory: 32Mi
# storage: (no storage request by default)
# ephemeral-storage: (no ephemeral-storage request by default)

collectorDeploymentCollectorContainerResources:
limits:
# cpu: (no cpu limit by default)
memory: 500Mi
# storage: (no storage limit by default)
# ephemeral-storage: (no ephemeral-storage limit by default)
gomemlimit: 400MiB
requests:
# cpu: (no cpu request by default)
memory: 500Mi
# storage: (no storage request by default)
# ephemeral-storage: (no ephemeral-storage request by default)
collectorDeploymentConfigurationReloaderContainerResources:
limits:
# cpu: (no cpu limit by default)
memory: 12Mi
# storage: (no storage limit by default)
# ephemeral-storage: (no ephemeral-storage limit by default)
gomemlimit: 8MiB
requests:
# cpu: (no cpu request by default)
memory: 12Mi
# storage: (no storage request by default)
# ephemeral-storage: (no ephemeral-storage request by default)

# the port for the metrics service
metricsPort: 8443

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var _ = Describe("The backend connection manager", Ordered, func() {
Scheme: k8sClient.Scheme(),
DeploymentSelfReference: DeploymentSelfReference,
OTelCollectorNamePrefix: OTelCollectorNamePrefixTest,
OTelColResourceSpecs: &otelcolresources.DefaultOTelColResourceSpecs,
}
manager = &BackendConnectionManager{
Client: k8sClient,
Expand Down
Loading