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

[kube-prometheus-stack] upgrade CRDs using helm #5175

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

jkroepke
Copy link
Member

@jkroepke jkroepke commented Jan 15, 2025

What this PR does / why we need it

Since helm does not support upgrading CRDs, it's an manual task for our end-users. However the velero chart https://github.com/vmware-tanzu/helm-charts/tree/main/charts/velero/templates/upgrade-crds implement a upgrade job using helm hooks that works for at least 1 year.

Which issue this PR fixes

(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged)

  • fixes #

Special notes for your reviewer

I would leave it disabled for now in order to have the ability to test the job on real upgrades.

Checklist

  • DCO signed
  • Chart Version bumped
  • Title of the PR starts with chart name (e.g. [prometheus-couchdb-exporter])

@jkroepke
Copy link
Member Author

Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
@GMartinez-Sisti
Copy link
Member

@QuentinBisson @GMartinez-Sisti this is super WIP (but working) what did you think? It based on https://github.com/vmware-tanzu/helm-charts/tree/main/charts/velero/templates/upgrade-crds?rgh-link-date=2025-01-15T09%3A52%3A20Z

I'm all up for it! 🙌 -> #4507

Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
@jkroepke
Copy link
Member Author

I'm all up for it! 🙌 -> #4507

Please take note that the CRDs needs to be pre-compressed, All CRDs in gzip format are approx. 300KB, while xz just using 80KB.

The creation of the tar.xz is part of hack scripts, but how we protect us against suspicious tar files?

Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
@GMartinez-Sisti
Copy link
Member

I'm all up for it! 🙌 -> #4507

Please take note that the CRDs needs to be pre-compressed, All CRDs in gzip format are approx. 300KB, while xz just using 80KB.

The creation of the tar.xz is part of hack scripts, but how we protect us against suspicious tar files?

Checksum? We can add a checksum file next to it, then run the same on ci and check the match.

@jkroepke
Copy link
Member Author

jkroepke commented Jan 15, 2025

I give-up after an hour to setup an reproducible tar archive which can be generated on any os (e.g. mac and linux)

For example, I can't find a tar option on mac where I can drop the mtime of the files.

GNU tar adds some pax header while bsd tar does not do it.

@GMartinez-Sisti
Copy link
Member

I give-up after an hour to setup an reproducible tar archive which can be generated on any os (e.g. mac and linux)

For example, I can't find a tar option on mac where I can drop the mtime of the files.

GNU tar adds some pax header while bsd tar does not do it.

Yeah, it’s hard to find a way with native commands, I usually fix these issues by running the commands in a docker container.

@jkroepke jkroepke force-pushed the upgrade-crds branch 3 times, most recently from 0b25bf6 to d4e4126 Compare January 15, 2025 22:21
@jkroepke jkroepke force-pushed the upgrade-crds branch 8 times, most recently from 05bb2ce to f481141 Compare January 15, 2025 23:47
@jkroepke
Copy link
Member Author

What about check,

I give-up after an hour to setup an reproducible tar archive which can be generated on any os (e.g. mac and linux)
For example, I can't find a tar option on mac where I can drop the mtime of the files.
GNU tar adds some pax header while bsd tar does not do it.

Yeah, it’s hard to find a way with native commands, I usually fix these issues by running the commands in a docker container.

please offer a solution.

While tar isn't the big issue, xz might be. Seems not possible to get the same archive from macos/linux using xz compression. Even with gnu tar on mac, the archive is different. gz is not an option, because the compression rate is really, really bad.

Tests with zstd works fine, however busybox does not support zstd.

Then, I tried docker. The ubuntu docker image does not have xz pre installed. starting with apt-get first feels terrible slow. busybox have xz embedded, but does not offer capabilities to strip the mtime.

@GMartinez-Sisti
Copy link
Member

please offer a solution.

While tar isn't the big issue, xz might be. Seems not possible to get the same archive from macos/linux using xz compression. Even with gnu tar on mac, the archive is different. gz is not an option, because the compression rate is really, really bad.

Tests with zstd works fine, however busybox does not support zstd.

Then, I tried docker. The ubuntu docker image does not have xz pre installed. starting with apt-get first feels terrible slow. busybox have xz embedded, but does not offer capabilities to strip the mtime.

Sure, I can test this during the weekend.

jkroepke and others added 5 commits January 20, 2025 23:42
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
@jkroepke jkroepke marked this pull request as ready for review January 20, 2025 23:12
@jkroepke jkroepke changed the title [kube-prometheus-stack] WIP: upgrade CRDs using helm [kube-prometheus-stack] upgrade CRDs using helm Jan 20, 2025
@jkroepke
Copy link
Member Author

Ready to review!

Signed-off-by: Jan-Otto Kröpke <[email protected]>
@QuentinBisson
Copy link
Member

QuentinBisson commented Jan 21, 2025

Is it expected that your PR carry the binary #5175 (comment)?

EDIT: Yes it is.

Overall I quite like the job approach but i'm not really fond of the archive though. Is there a specific reason why we cannot use curl to fetch the crds from this chart app version instead?

jkroepke and others added 4 commits January 21, 2025 10:30
@jkroepke
Copy link
Member Author

jkroepke commented Jan 25, 2025

Overall I quite like the job approach but i'm not really fond of the archive though. Is there a specific reason why we cannot use curl to fetch the crds from this chart app version instead?

Yeah, sideloading is not good in enterprise context where internet is restricted. That lead to unexpected situations.

One possible solution would be that we provide the CRDs as OCI image. Then, we can mount the image as PVC. but It will take some time: https://kubernetes.io/blog/2024/08/16/kubernetes-1-31-image-volume-source/

@aidanleuck
Copy link

This is awesome! I started looking at ways I could implement something similar in our wrapper chart. We use Terraform to deploy this chart and manage 20-30 Kubernetes clusters. Performing the CRD upgrades manually when we needed to take a major version upgrade had become tedious. This will help out our org a ton and resolve our biggest pain point with the deployment.

@jkroepke
Copy link
Member Author

@aidanleuck great to know. Once implemented, we are happy about feedback.

@muffl0n
Copy link
Contributor

muffl0n commented Jan 26, 2025

Really looking forward to this, too! If you need any early feedback, let me know!

@aidanleuck
Copy link

aidanleuck commented Jan 26, 2025

Overall I quite like the job approach but i'm not really fond of the archive though. Is there a specific reason why we cannot use curl to fetch the crds from this chart app version instead?

Yeah, sideloading is not good in enterprise context where internet is restricted. That lead to unexpected situations.

One possible solution would be that we provide the CRDs as OCI image. Then, we can mount the image as PVC. but It will take some time: https://kubernetes.io/blog/2024/08/16/kubernetes-1-31-image-volume-source/

I like mounting an OCI image, but as you mentioned this is a cutting-edge feature and it won't work with older clusters. If I understand this PR correctly, the busybox image is doing the decompression of the CRD archive, the results of which are placed in a PVC that the kubectl pod uses to apply. Would it be simpler if you created a Dockerfile and extend the kubectl image? That way you don't need a shared PVC at all and you just use a single container image to run the job.

CI/Deployment you can build the custom kubectl image and the CRDS bundled together. You can tag the image with the same version as the appVersion. This will get rid of the tar archive issue as well.

Here's the pseudocode (Note use a multi-stage build if you want to merge all the crds into a single file)
Dockerfile

FROM registry.k8s.io/kubectl
COPY ./charts/crds/crds /var/crds

job.yaml

image: <custom-built-image>
workingDir: /var/
command:    
  - kubectl
args:
  - apply
  - --server-side
  - --filename
  - crds/*.yaml

Let me know if I am off base here and am missing something, but this seems like a simpler solution to the problem. I can whip up a POC if you like this idea.

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.

5 participants