Repository navigation
install: Add ability to auto-fill or manually set .Capabilities.APIVersions in helm - #1176
Conversation
michi-covalent
left a comment
There was a problem hiding this comment.
lgtm other than lint issues
|
btw gke workflows are broken right now. should be fixed in #1177 |
|
ok #1177 is merged. please rebase 🙏 |
1cda8b8 to
89e54ea
Compare
|
Rebased! Additionally, I adjust the code to only include known-needed CRDs (right now just |
|
@learnitall thanks for the PR, taking a look now. I also noticed a spelling mistake in the first commit: Do you mind rewording that |
| apiVersionsStr := "" | ||
| if len(apiVersions) > 0 { | ||
| for _, av := range apiVersions { | ||
| apiVersionsStr = fmt.Sprintf("%s --api-versions %s", apiVersionsStr, av) |
There was a problem hiding this comment.
I think --api-versions takes a string array, could we do that instead of adding a bunch of individual --api-versions flags to make the rendered command cleaner?
There was a problem hiding this comment.
I tried to see if we could, but I don't think we can. You're right that helm uses a StringArrayVarP for --api-versions (template.go#L184), but any value passed to a StringArrayVarP will be taken "as-is" and not be separated by commas. That functionality is implemented in StringSliceVarP:
# https://pkg.go.dev/github.com/spf13/pflag#StringArrayVarP
StringArrayVar defines a string flag with specified name, default value, and usage string.
The argument p points to a []string variable in which to store the value of the flag.
The value of each argument will not try to be separated by comma. Use a StringSlice for that.
I don't think helm does any work to take the values from --api-versions and look for CSVs, as the string slice from --api-versions is converted to a VersionSet, which is just an alias for a string slice. It as a method Has(apiVersion string) bool which is just a simple for-loop search through the slice.
I submitted an issue on this upstream, maybe in the future we can revisit: helm/helm#11485
89e54ea to
25c7d70
Compare
|
Force pushed a new set of commits that address your feedback @tommyp1ckles, as well as fixing that typo. (Thank you for the nits, really helpful in getting my Go up to spec.) |
This commit adds `ListApiResources`, which is based off of kubectl's `api-resources` sub-command, allowing for consumers of the k8s client to gain information on what GVRs are installed into the cluster. The main use case for such a method is filling in helm's API Capabilities for validity checks that include CRDs. Signed-off-by: Ryan Drew <[email protected]>
This commit takes the `helm template` logging step in `MergeVals` and splits it off into its own function. This allows for the use of merged helm values to decide on what to include for `--api-versions` without having to add this logic into `MeregVals` itself. Signed-off-by: Ryan Drew <[email protected]>
The commit introduces the `--api-versions` parameter for the `install` sub-command, which allows for users to set helm's Capabilities.APIVersions as needed for Cilium chart validation. If a user does not provide a value or set of values for `--api-versions`, then a discovery client will be used to auto-fill this value based on the available api versions in a cluster (see install/helm.go#L271). This change is needed because helm will not contact the k8s api server to determine what CRDs are installed into a cluster, leading to chart validation to fail anytime a CRD is required. For this reason, the `--api-versions` CLI argument was introduced to `helm template` (see pr [helm/helm#5392]). The cilium-cli does not allow for users to specify this argument to helm, therefore users can face a similar issue when installing cilium with certain features. For instance, enabling the use of prometheus ServiceMonitors will trigger a check for `monitoring.coreos.com/v1` while performing chart validation (by [cilium/install/kubernetes/cilium/templates/validate.yaml#L21]), but since helm does not adjust Capabilties.APIVersions based on the CRDs installed in a cluster, helm will _always_ believe that `monitoring.coreos.com/v1` is not available. [helm/helm#5392]: helm/helm#5392 [cilium/install/kubernetes/cilium/templates/validate.yaml#L21]: https://github.com/cilium/cilium/blob/v1.12.2/install/kubernetes/cilium/templates/validate.yaml#L21 Fixes: cilium#1107 Signed-off-by: Ryan Drew <[email protected]>
25c7d70 to
b012dd6
Compare
|
alright let's ship this |
|
Thanks everybody! 🚀 |
This is an attempt to fix #1107 by introducing two ways to set
.Capabilities.APIVersionsin helm while rendering Cilium templates:.Capabilities.APIVersions.--api-versionsCLI argument.I've also adjusted the code that prints out the
helm templatecommand to include any equivalent--api-versionsargs when setting.Capabilities.APIVersionsusing one of the above methods.To do this, I changed following functions/interfaces:
hubble/hubble.go: k8sHubble.genManifests: Adjust for breaking changes in internal/helm.goinstall/helm.go: K8sInstaller.generateManifests: Pull api versions from CLI params if available, otherwise use client to auto-populate. If auto-populate fails, log a warning to the user.install/install.go: Parameters: AddApiVersionsparameter.install/install.go: k8sInstallerImplementation: AddListApiResourcesmethod signature.k8s/client.go: Client.ListApiResources: AddListApiResourcesimplementation.internal/helm/helm.go: newClient: Add argument for settingclient.APIVersions.internal/helm/helm.go: GenManifests: Add argument for passing api versions tonewClient.internal/helm/helm.go: MergeVals: Move helm template loggingPrintHelmTemplateCommandinternal/helm/helm.go: PrintHelmTemplateCommand: New function for logging thehelm templatewith a parameter for setting--api-versions.