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

wip: add images from helm chart template #380

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

Conversation

wcrum
Copy link
Contributor

@wcrum wcrum commented Dec 13, 2024

Please check below, if the PR fulfills these requirements:

  • Commit(s) and code follow the repositories guidelines.
  • Test(s) have been added or updated to support these change(s).
  • Doc(s) have been added or updated to support these change(s).

Associated Links:

Types of Changes:

  • Modify the way some values get passed and iterate over helm chart to save images found within the manifests.

Proposed Changes:

  • Proposing to add additional flag to support users to iterate over helm charts they store and automatically add the images the helm chart references.

Verification/Testing of Changes:

  • Utilize the --add-images flag to hauler store add chart [chart]
  • Adds an additional -f/--values to allow hauler user to pass values into template. Similar to helm.

Additional Context:

  • See slack thread.

@zackbradys
Copy link
Member

zackbradys commented Dec 14, 2024

hey @wcrum... I do like the idea of being able to include images referenced in charts, and a lot of of users and customers have asked us for it, but it might take a bit more thought on how to support the most amount of charts since there could be various ways they include images and then you can also get into dependent charts. Maybe a way for users to pass their values file on opt of the default values?

Additionally, a lot of charts require checking the k8s version when using helm template so if you don't have a cluster up or a kubeconfig to a cluster, then it won't be able to template it. See some of the tests below...

Maybe more reliable results would come from yaml parsing with gopkg.in/yaml.v3? Open to ideas...

zackbradys@Zacks-MacBook-Pro hauler % ./dist/hauler_darwin_arm64_v8.0/hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev --add-ima
ges
2024-12-13 23:03:57 INF adding 'chart' [hauler-helm] to the store
Pulled: ghcr.io/hauler-dev/hauler-helm:1.1.1
Digest: sha256:3957fc2bf560f2ccd64e38b59651b097dddb38863124745df264053cae1b807a
2024-12-13 23:03:58 INF successfully added 'chart' [hauler/hauler-helm:1.1.1]
2024-12-13 23:03:58 INF adding 'image' [hauler/hauler-debug:1.1.1] to the store
2024-12-13 23:04:04 INF successfully added 'image' [index.docker.io/hauler/hauler-debug:1.1.1]
2024-12-13 23:04:04 INF adding 'image' [hauler/hauler:1.1.1] to the store
2024-12-13 23:04:09 INF successfully added 'image' [index.docker.io/hauler/hauler:1.1.1]
2024-12-13 23:04:09 INF adding 'image' [rancher/kubectl:v1.31.3] to the store
2024-12-13 23:04:12 INF successfully added 'image' [index.docker.io/rancher/kubectl:v1.31.3]
zackbradys@Zacks-MacBook-Pro hauler % ./dist/hauler_darwin_arm64_v8.0/hauler store info                                                  
+-------------------------------------------+-------+-----------------+----------+----------+
| REFERENCE                                 | TYPE  | PLATFORM        | # LAYERS | SIZE     |
+-------------------------------------------+-------+-----------------+----------+----------+
| hauler/hauler-helm:1.1.1                  | chart | -               |        1 | 3.8 kB   |
| index.docker.io/hauler/hauler-debug:1.1.1 | image | linux/amd64     |        8 | 73.0 MB  |
|                                           | image | linux/arm64     |        8 | 68.7 MB  |
| index.docker.io/hauler/hauler:1.1.1       | image | linux/amd64     |        9 | 67.1 MB  |
|                                           | image | linux/arm64     |        9 | 62.4 MB  |
| index.docker.io/rancher/kubectl:v1.31.3   | image | linux/amd64     |        3 | 17.2 MB  |
|                                           | image | linux/arm64     |        3 | 15.7 MB  |
|                                           | image | unknown/unknown |        1 | 8.4 kB   |
|                                           | image | unknown/unknown |        1 | 8.4 kB   |
+-------------------------------------------+-------+-----------------+----------+----------+
|                                                                        TOTAL   | 304.0 MB |
+-------------------------------------------+-------+-----------------+----------+----------+


zackbradys@Zacks-MacBook-Pro hauler % ./dist/hauler_darwin_arm64_v8.0/hauler store add chart rancher --repo https://releases.rancher.com/server-charts/stable --add-images
2024-12-13 23:07:23 INF adding 'chart' [rancher] to the store
2024-12-13 23:07:25 INF successfully added 'chart' [hauler/rancher:2.10.0]
2024-12-13 23:07:25 INF adding 'image' ["rancher/shell:v0.3.0"] to the store
2024-12-13 23:07:25 ERR unable to parse 'image' ["rancher/shell:v0.3.0"]: could not parse reference: "rancher/shell:v0.3.0"


zackbradys@Zacks-MacBook-Pro hauler % ./dist/hauler_darwin_arm64_v8.0/hauler store add chart vault --repo https://helm.releases.hashicorp.com --add-images            
2024-12-13 23:20:31 INF adding 'chart' [vault] to the store
2024-12-13 23:20:32 INF successfully added 'chart' [hauler/vault:0.29.1]
Error: template: vault/templates/server-statefulset.yaml:27:14: executing "vault/templates/server-statefulset.yaml" at <semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version>: error calling semverCompare: Invalid Semantic Version
Usage:
  hauler store add chart [flags]

Examples:
# fetch local helm chart
hauler store add chart path/to/chart/directory --repo .

# fetch local compressed helm chart
hauler store add chart path/to/chart.tar.gz --repo .

# fetch remote oci helm chart
hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev

# fetch remote oci helm chart with version
hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev --version 1.0.6

# fetch remote helm chart
hauler store add chart rancher --repo https://releases.rancher.com/server-charts/stable

# fetch remote helm chart with specific version
hauler store add chart rancher --repo https://releases.rancher.com/server-charts/latest --version 2.9.1

Flags:
      --add-images                 (Optional) Add images referenced in helm template
      --ca-file string             (Optional) Location of CA Bundle to enable certification verification
      --cert-file string           (Optional) Location of the TLS Certificate to use for client authenication
  -h, --help                       help for chart
      --insecure-skip-tls-verify   (Optional) Skip TLS certificate verification
      --key-file string            (Optional) Location of the TLS Key to use for client authenication
      --password string            (Optional) Password to use for authentication
      --repo string                Location of the chart (https:// | http:// | oci://)
      --username string            (Optional) Username to use for authentication
      --verify                     (Optional) Verify the chart before fetching it
      --version string             (Optional) Specifiy the version of the chart (v1.0.0 | 2.0.0 | ^2.0.0)

Global Flags:
  -d, --haulerdir string   Set the location of the hauler directory (default $HOME/.hauler)
      --ignore-errors      Ignore/Bypass errors (i.e. warn on error) (defaults false)
  -l, --log-level string   Set the logging level (i.e. info, debug, warn) (default "info")
  -r, --retries int        Set the number of retries for operations (default 3)
  -s, --store string       Set the directory to use for the content store

2024-12-13 23:20:32 ERR template: vault/templates/server-statefulset.yaml:27:14: executing "vault/templates/server-statefulset.yaml" at <semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version>: error calling semverCompare: Invalid Semantic Version


zackbradys@Zacks-MacBook-Pro hauler % ./dist/hauler_darwin_arm64_v8.0/hauler store add chart gitea --repo https://dl.gitea.com/charts --add-images

2024-12-13 23:22:24 INF adding 'chart' [gitea] to the store
2024-12-13 23:22:25 INF successfully added 'chart' [hauler/gitea:10.6.0]
Error: template: gitea/charts/redis/templates/master/service.yaml:23:10: executing "gitea/charts/redis/templates/master/service.yaml" at <semverCompare ">=1.22-0" (include "common.capabilities.kubeVersion" .)>: error calling semverCompare: Invalid Semantic Version
Usage:
  hauler store add chart [flags]

Examples:
# fetch local helm chart
hauler store add chart path/to/chart/directory --repo .

# fetch local compressed helm chart
hauler store add chart path/to/chart.tar.gz --repo .

# fetch remote oci helm chart
hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev

# fetch remote oci helm chart with version
hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev --version 1.0.6

# fetch remote helm chart
hauler store add chart rancher --repo https://releases.rancher.com/server-charts/stable

# fetch remote helm chart with specific version
hauler store add chart rancher --repo https://releases.rancher.com/server-charts/latest --version 2.9.1

Flags:
      --add-images                 (Optional) Add images referenced in helm template
      --ca-file string             (Optional) Location of CA Bundle to enable certification verification
      --cert-file string           (Optional) Location of the TLS Certificate to use for client authenication
  -h, --help                       help for chart
      --insecure-skip-tls-verify   (Optional) Skip TLS certificate verification
      --key-file string            (Optional) Location of the TLS Key to use for client authenication
      --password string            (Optional) Password to use for authentication
      --repo string                Location of the chart (https:// | http:// | oci://)
      --username string            (Optional) Username to use for authentication
      --verify                     (Optional) Verify the chart before fetching it
      --version string             (Optional) Specifiy the version of the chart (v1.0.0 | 2.0.0 | ^2.0.0)

Global Flags:
  -d, --haulerdir string   Set the location of the hauler directory (default $HOME/.hauler)
      --ignore-errors      Ignore/Bypass errors (i.e. warn on error) (defaults false)
  -l, --log-level string   Set the logging level (i.e. info, debug, warn) (default "info")
  -r, --retries int        Set the number of retries for operations (default 3)
  -s, --store string       Set the directory to use for the content store

2024-12-13 23:22:25 ERR template: gitea/charts/redis/templates/master/service.yaml:23:10: executing "gitea/charts/redis/templates/master/service.yaml" at <semverCompare ">=1.22-0" (include "common.capabilities.kubeVersion" .)>: error calling semverCompare: Invalid Semantic Version

@zackbradys zackbradys added enhancement New feature or request size/M Denotes an issue/PR requiring a relatively moderate amount of work labels Dec 14, 2024
@zackbradys zackbradys linked an issue Dec 14, 2024 that may be closed by this pull request
@wcrum
Copy link
Contributor Author

wcrum commented Dec 16, 2024

Hey @zackbradys - I am pretty easily able to fix all of these things.

9e0a56b fixes an issue with my strip image logic, just forgot to remove / replace double quotes.

b6faa3c somewhat resolves the issue seen within your shared logs. When using the helm function chartutil.ToRenderValues(chrt *chart.Chart, chrtVals map[string]interface{}, options chartutil.ReleaseOptions, caps *chartutil.Capabilities) it does not actually pull in the current kubeconfig as context, it looks for caps *chartutil.Capabilities which has the KubeVersion as a property which we can simply fake.

What would you think is the best way forward on this? KubeVersion could be something that is passed as an additional flag, the default could be the latest Kubernetes release.

@wcrum
Copy link
Contributor Author

wcrum commented Dec 17, 2024

🐛 @zackbradys there is a bug around the search for image: some CRDs, ConfigMaps with data and other things use the image: in some other context... this isnt the same as a initcontainer or container image reference so it causes several errors.

~/Coding/hauler > hauler store add chart gpu-operator-v24.9.1.tgz --repo . --add-images
2024-12-17 13:41:46 INF adding 'chart' [gpu-operator-v24.9.1.tgz] to the store
2024-12-17 13:41:46 INF successfully added 'chart' [hauler/gpu-operator:v24.9.1]
2024-12-17 13:41:46 INF adding 'image' [container-toolkit] to the store
2024-12-17 13:41:48 ERR error (attempt 1/3)... getting image "index.docker.io/library/container-toolkit:latest": GET https://index.docker.io/v2/library/container-toolkit/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/container-toolkit Type:repository]]

@zackbradys zackbradys added this to the Hauler v1.1-next1 milestone Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size/M Denotes an issue/PR requiring a relatively moderate amount of work
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[feature] save all images referenced while saving helm chart
2 participants