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

Using commonLabels in helm charts breaks selectors and thus patch deployments #1523

Open
xSAVIKx opened this issue Jan 22, 2025 · 3 comments
Assignees
Labels
bug Something isn't working internally-reviewed The issue has been reviewed internally.

Comments

@xSAVIKx
Copy link

xSAVIKx commented Jan 22, 2025

Component(s)

helm

Component version

0.12.3

wgc version

0.71.4

controlplane version

0.118.1

router version

0.150.0

What happened?

Description

Adding commonLabels to already deployed components breaks deployment.

Steps to Reproduce

Add common labels to controlplane in the helm chart as:

controlplane:
  commonLabels:
    env: stage
    team: devops
    owner: test
    domain: infra

Expected Result

Deployment is successful

Actual Result

Error: UPGRADE FAILED: release cosmo failed, and has been rolled back due to atomic being set: cannot patch "cosmo-controlplane" with kind Deployment: Deployment.apps "cosmo-controlplane" is invalid: spec.selector: Invalid value: v1.LabelSelector***MatchLabels:map[string]string***"app.kubernetes.io/instance":"cosmo", "app.kubernetes.io/name":"controlplane", "domain":"infra", "env":"stage", "owner":"test", "team":"devops"***, MatchExpressions:[]v1.LabelSelectorRequirement(nil)***: field is immutable && cannot patch "cosmo-graphqlmetrics" with kind Deployment: Deployment.apps "cosmo-graphqlmetrics" is invalid: spec.selector: Invalid value: v1.LabelSelector***MatchLabels:map[string]string***"app.kubernetes.io/instance":"cosmo", "app.kubernetes.io/name":"graphqlmetrics", "domain":"infra", "env":"stage", "owner":"test", "team":"devops"***, MatchExpressions:[]v1.LabelSelectorRequirement(nil)***: field is immutable && cannot patch "cosmo-otelcollector" with kind Deployment: Deployment.apps "cosmo-otelcollector" is invalid: spec.selector: Invalid value: v1.LabelSelector***MatchLabels:map[string]string***"app.kubernetes.io/instance":"cosmo", "app.kubernetes.io/name":"otelcollector", "domain":"infra", "env":"stage", "owner":"test", "team":"devops"***, MatchExpressions:[]v1.LabelSelectorRequirement(nil)***: field is immutable && cannot patch "cosmo-router" with kind Deployment: Deployment.apps "cosmo-router" is invalid: spec.selector: Invalid value: v1.LabelSelector***MatchLabels:map[string]string***"app.kubernetes.io/instance":"cosmo", "app.kubernetes.io/name":"router", "domain":"infra", "env":"stage", "owner":"test", "team":"devops"***, MatchExpressions:[]v1.LabelSelectorRequirement(nil)***: field is immutable && cannot patch "cosmo-studio" with kind Deployment: Deployment.apps "cosmo-studio" is invalid: spec.selector: Invalid value: v1.LabelSelector***MatchLabels:map[string]string***"app.kubernetes.io/instance":"cosmo", "app.kubernetes.io/name":"studio", "domain":"infra", "env":"stage", "owner":"test", "team":"devops"***, MatchExpressions:[]v1.LabelSelectorRequirement(nil)***: field is immutable

I'd not be expecting these extra labels to be used in selectors at all.

Environment information

No response

Router configuration

Router execution config

Log output

Additional context

No response

@xSAVIKx xSAVIKx added the bug Something isn't working label Jan 22, 2025
Copy link

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible.
The roadmap is driven by our customers and we have to prioritize issues that are important to them.
You can influence the priority by becoming a customer. Please contact us here.

@xSAVIKx xSAVIKx changed the title Using additionalLabels in helm charts breaks selectors and thus patch deployments Using commonLabels in helm charts breaks selectors and thus patch deployments Jan 22, 2025
@xSAVIKx
Copy link
Author

xSAVIKx commented Jan 22, 2025

I guess moving these commonLabels from selector labels helper to common labels helper will do the trick. Also now it feels like the naming may be a bit confusing.

{{/*
Common labels
*/}}
{{- define "controlplane.labels" -}}
{{ $version := .Values.image.version | default .Chart.AppVersion -}}
helm.sh/chart: {{ include "controlplane.chart" . }}
{{ include "controlplane.selectorLabels" . }}
app.kubernetes.io/version: {{ $version | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Job labels, used to append defaults and
extra labels (jobLabels) to each job
*/}}
{{- define "controlplane.job.labels" -}}
{{ include "controlplane.labels" .context }}
{{- range $key, $value := .context.Values.additionalJobLabels }}
{{ $key }}: {{ quote $value }}
{{- end }}
{{- if and (hasKey . "additionalLabels") -}}
{{- range $key, $value := .additionalLabels }}
{{ $key }}: {{ quote $value }}
{{- end }}
{{- end -}}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "controlplane.selectorLabels" -}}
app.kubernetes.io/name: {{ include "controlplane.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- range $key, $value := .Values.commonLabels }}
{{ $key }}: {{ quote $value }}
{{- end }}
{{- end }}

@StarpTech
Copy link
Contributor

Hi @xSAVIKx thanks for opening an issue. We'll take a look and come back.

@StarpTech StarpTech added the internally-reviewed The issue has been reviewed internally. label Jan 28, 2025
@StarpTech StarpTech self-assigned this Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working internally-reviewed The issue has been reviewed internally.
Projects
None yet
Development

No branches or pull requests

2 participants