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

Awx-operator Helm upgrade fails due to version labels in selector #1057

Closed
3 tasks done
andriktr opened this issue Sep 22, 2022 · 10 comments · Fixed by #1114
Closed
3 tasks done

Awx-operator Helm upgrade fails due to version labels in selector #1057

andriktr opened this issue Sep 22, 2022 · 10 comments · Fixed by #1114
Labels
component:operator good first issue Good for newcomers Hacktoberfest Issues tagged for Hacktoberfest help wanted Extra attention is needed type:bug Something isn't working

Comments

@andriktr
Copy link

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that the AWX Operator is open source software provided for free and that I might not receive a timely response.

Bug Summary

Hi,
If we try to run helm upgrade for awx-operator for example from 0.28.0 to 0.29.0 version update is failing with the following error:

Error: UPGRADE FAILED: release awx-operator failed, and has been rolled back due to atomic being set: cannot patch "awx-operator-controller-manager" with kind Deployment: Deployment.apps "awx-operator-controller-manager" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"control-plane":"controller-manager", "helm.sh/chart":"awx-operator-0.29.0"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

The reason for this is a version label used in deployment selector:

spec:
  replicas: 1
  selector:
    matchLabels:
      control-plane: controller-manager
      helm.sh/chart: awx-operator-0.29.0
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: manager
      labels:
        control-plane: controller-manager
        helm.sh/chart: awx-operator-0.29.0

Deployment selector labels are immutable and can't be changed during upgrade https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#label-selector-updates
In our case this selector changes from one version to another

AWX Operator version

0.28.0

AWX version

21.5.0

Kubernetes platform

kubernetes

Kubernetes/Platform version

1.23.5

Modifications

no

Steps to reproduce

run helm upgrade for awx-operator

Expected results

deployment upgraded

Actual results

upgrade fails with

Error: UPGRADE FAILED: release awx-operator failed, and has been rolled back due to atomic being set: cannot patch "awx-operator-controller-manager" with kind Deployment: Deployment.apps "awx-operator-controller-manager" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"control-plane":"controller-manager", "helm.sh/chart":"awx-operator-0.29.0"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Additional information

No response

Operator Logs

No response

@andriktr andriktr changed the title Awx Helm upgrade fails due to version labels in selector Awx-operator Helm upgrade fails due to version labels in selector Sep 22, 2022
@jeffb4
Copy link

jeffb4 commented Sep 22, 2022

I ran into this problem as well. Not that it should be required, but you can kubectl -n awx delete deployment awx-operator-controller-manager and continue with the Helm chart upgrade.

@andriktr
Copy link
Author

@jeffb4 Yea sure we can remove existing awx-operator deployment and run helm upgrade, but this is not how it should be :)
Selector label should not contain helm.sh/chart: awx-operator-0.29.0 or any other label which may change from version to version. This especially important if you have automated deployment via pipelines.

@fosterseth fosterseth added type:bug Something isn't working component:operator good first issue Good for newcomers help wanted Extra attention is needed and removed needs_triage labels Sep 28, 2022
@FlorianLaunay
Copy link
Contributor

@andriktr thanks for this issue!

Yeah, very frustrating problem 😓

@trippinnik
Copy link
Contributor

Same 0.29.0 to 0.30.0

@andriktr
Copy link
Author

andriktr commented Oct 5, 2022

The only way I see how to fix it is to remove helm.sh/chart: awx-operator-x.xx.x selector and point it as a breaking change in the release.
Currently as workaround I just changing a version number in the selector to the same which was set during the first awx-operator helm installation.

@john-westcott-iv john-westcott-iv added the Hacktoberfest Issues tagged for Hacktoberfest label Oct 6, 2022
@FlorianLaunay
Copy link
Contributor

I have started to work on a local branch to fix this. I will keep you in touch and open a PR when the fix will be ready.

@FlorianLaunay
Copy link
Contributor

FlorianLaunay commented Nov 8, 2022

After investigations, this problem seems to be caused by kustomize during the helm chart generation. This one is managed in Makefile by the helm-chart-generate step (Makefile#L295) using kustomize edit set label to add commonLabels field to kustomization.yaml containing the helm.sh/chart label with the operator version.

Unfortunately kustomize use commonLabels arg to set the metadata.labels field but also spec.selector.matchLabels and the community seams to disagree with this behavior : kubernetes-sigs/kustomize#1009 😅 . Indeed this field is now immutable for deployments in recent versions of Kubernetes (https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#label-selector-updates). So running a helm upgrade with a chart containing a deployment template with a different content in the spec.selector.matchLabels field is not allowed and cause this error.

The only solution I see is to use the labels fiels in kustomization.yaml instead of commonLabels (kubernetes-sigs/kustomize#3743). But unfortunately again, kustomize edit set label don't manage this new field 😢. But it seems well-documented (kubernetes-sigs/kustomize#3756) (https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/labels/) 🤩 .

Using this new field means stop using kustomize edit set label and add labels field in kustomization.yaml with yq. I need to modify the Makefile to do that and run some test builds before submitting a PR.

@FlorianLaunay
Copy link
Contributor

@andriktr I have a working fix with #1114

Waiting to be reviewed 😇

@andriktr
Copy link
Author

andriktr commented Nov 8, 2022

@FlorianLaunay sounds great.
Thanks for your effort ;)

@FlorianLaunay
Copy link
Contributor

FlorianLaunay commented Nov 14, 2022

@andriktr I have a working fix with #1114

Waiting to be reviewed 😇

Got an interesting review from the AWX team. Another solution is now being considered. Awaiting for their response to push 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:operator good first issue Good for newcomers Hacktoberfest Issues tagged for Hacktoberfest help wanted Extra attention is needed type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants