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

Fix CRD chart regression and fix CRDs for upgrades #1131

Merged
merged 5 commits into from
Apr 21, 2021

Conversation

aiyengar2
Copy link
Contributor

@aiyengar2 aiyengar2 commented Apr 21, 2021

The first commit reverts a change introduced in a previous commit that deletes CRDs before re-installing them. This is not an option in a production environment since it would wipe out all of the CRs in the cluster, which would effectively remove any customization that a user added between Monitoring chart upgrades.

The second commit modifies the CRD chart to use rancher/agent instead of rancher/kubectl (since we need to perform some light scripting and sh is not offered in rancher/kubectl).

Once the image was modified, I changed the remove-finalizer container to avoid doing an entire kubectl apply in favor of just removing the finalizers (the original intention of the container) and added a new initContainer on install that would destroy the preserveUnknownField on an upgrade due to an issue with upgrading an apiextensions.k8s.io/v1beta1 CRD to one in apiextensions.k8s.io/v1, as noted in https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-pruning using the workaround described in kubernetes-sigs/controller-tools#476 (comment).

Related Issue: rancher/rancher#31991, rancher/rancher#32225

- >
{{- range $path, $_ := (.Files.Glob "crd-manifest/**.yaml") }}
{{- $crd := get (get ($.Files.Get $path | fromYaml) "metadata") "name" }}
if [[ -n "$(kubectl get crd {{ $crd }} -o jsonpath='{.spec.preserveUnknownFields}')" ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a best effort operation (hence the || true) that should be done only if the CRD exists and has .spec.preserveUnknownFields set to some value.

If the CRD does not exist or if .spec.preserveUnknownFields is unset, this bash script will skip since the kubectl get command will return nothing to the stdout, but it will still print the error in finding the resource since the kubectl get command prints to stderr.

Comment on lines +30 to +31
{{- range $path, $_ := (.Files.Glob "crd-manifest/**.yaml") }}
{{- $crd := get (get ($.Files.Get $path | fromYaml) "metadata") "name" }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helm code that basically says "look at each file in crd-manifest that ends with .yaml and parse it as a YAML doc. Then pull out metadata.name's value and put it in the variable $crd."

e.g. anywhere that says {{ $crd }} below would look like prometheus.monitoring.coreos.com.

Copy link
Contributor

@brendarearden brendarearden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aiyengar2 aiyengar2 merged commit 18df430 into rancher:dev-v2.5-source Apr 21, 2021
github-actions bot pushed a commit that referenced this pull request Apr 21, 2021
Fix CRD chart regression and fix CRDs for upgrades
github-actions bot pushed a commit that referenced this pull request Apr 21, 2021
Fix CRD chart regression and fix CRDs for upgrades
github-actions bot pushed a commit that referenced this pull request Apr 21, 2021
Merge pull request #1131 from aiyengar2/fix_crd_chart

Fix CRD chart regression and fix CRDs for upgrades
github-actions bot pushed a commit to jiaqiluo/charts that referenced this pull request Apr 22, 2021
Fix CRD chart regression and fix CRDs for upgrades
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants