-
Notifications
You must be signed in to change notification settings - Fork 8
feat(stacked-PR): create cluster with custom helm chart config #1023
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c395876
feat: API for custom helm chart configuration
supershal 437e52b
fix: update doc to make custom config immutable
supershal 80b6118
feat: fetch helm chart info from cluster variables
supershal 38bcc48
feat: validate configmap for helm chart configuration
supershal 6d76d85
test: unit test for addon validator webhook
supershal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| +++ | ||
| title = "Custom Helm Chart Configuration" | ||
| icon = "fa-solid fa-eye" | ||
| +++ | ||
|
|
||
| A default helm chart configuration is provided with a ConfigMap `default-helm-addons-config`. | ||
| This ConfigMap contains helm chart URL and version for each addon. | ||
| A a ConfigMap with customized addon configuration can be created and referenced in the `Cluster` object. | ||
|
|
||
| The helm chart configuration for an addon included in the custom ConfigMap will be installed on the cluster. | ||
| If configuration for an addon is not included in the the customized addon configuration ConfigMap, | ||
| it will be defauled from the `default-helm-addons-config` configmap. | ||
|
|
||
| The content of the ConfigMap must use below specification: | ||
|
|
||
| - It should be immutable | ||
| - The format of the addon chart configuration should be: | ||
|
|
||
| ```yaml | ||
| addon-name: | | ||
| ChartName: addon-chart-name | ||
| ChartVersion: 1.0.0 | ||
| RepositoryURL: https://my-chart-repository.example.com/charts/ | ||
| ``` | ||
|
|
||
| Example configmap `custom-helm-addons-config.yaml`: | ||
|
|
||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: <CLUSTER_NAME>-helm-addons-config-<uuid> | ||
| namespace: <CLUSTER_NAMESPACE> | ||
| labels: | ||
| clusterctl.cluster.x-k8s.io/move: "" | ||
| immutable: true | ||
| data: | ||
| nutanix-ccm: | | ||
| ChartName: nutanix-cloud-provider | ||
| ChartVersion: 0.4.2 | ||
| RepositoryURL: https://nutanix.github.io/helm/ | ||
| nutanix-storage-csi: | | ||
| ChartName: nutanix-csi-storage | ||
| ChartVersion: 3.2.0 | ||
| RepositoryURL: https://nutanix.github.io/helm-releases/ | ||
| ``` | ||
|
|
||
| create the custom configmap in the same namespace as the `Cluster` | ||
|
|
||
| ```shell | ||
| kubectl create -f custom-helm-addons-config.yaml | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| To install addons using custom helm configuration, specify following values: | ||
|
|
||
| ```yaml | ||
| apiVersion: cluster.x-k8s.io/v1beta1 | ||
| kind: Cluster | ||
| metadata: | ||
| name: <NAME> | ||
| spec: | ||
| topology: | ||
| variables: | ||
| - name: clusterConfig | ||
| value: | ||
| addons: | ||
| helmChartConfig: | ||
| configMapRef: | ||
| name: <NAME>-helm-addons-config | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,18 @@ package config | |
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| "gopkg.in/yaml.v2" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
| ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" | ||
| "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables" | ||
| ) | ||
|
|
||
| type Component string | ||
|
|
@@ -75,13 +80,28 @@ func (h *HelmChartGetter) get( | |
| return cm, err | ||
| } | ||
|
|
||
| func (h *HelmChartGetter) For( | ||
| type HelmChartInfoNotFoundError struct { | ||
| Component Component | ||
| Name string | ||
| Namespace string | ||
| } | ||
|
|
||
| func (e HelmChartInfoNotFoundError) Error() string { | ||
| return fmt.Sprintf( | ||
| "Helm Chart component %q not found in configmap %s/%s", | ||
| e.Component, | ||
| e.Namespace, | ||
| e.Name, | ||
| ) | ||
| } | ||
|
|
||
| func (h *HelmChartGetter) getInfoFor( | ||
| ctx context.Context, | ||
| log logr.Logger, | ||
| name Component, | ||
| ) (*HelmChart, error) { | ||
| log.Info( | ||
| fmt.Sprintf("Fetching HelmChart info for %q from configmap %s/%s", | ||
| fmt.Sprintf("fetching HelmChart info for %q from configmap %s/%s", | ||
| string(name), | ||
| h.cmNamespace, | ||
| h.cmName), | ||
|
|
@@ -92,14 +112,59 @@ func (h *HelmChartGetter) For( | |
| } | ||
| d, ok := cm.Data[string(name)] | ||
| if !ok { | ||
| return nil, fmt.Errorf( | ||
| "did not find key %q in configmap %s/%s", | ||
| return nil, HelmChartInfoNotFoundError{ | ||
| name, | ||
| h.cmNamespace, | ||
| h.cmName, | ||
| ) | ||
| } | ||
| } | ||
| var settings HelmChart | ||
| err = yaml.Unmarshal([]byte(d), &settings) | ||
| return &settings, err | ||
| } | ||
|
|
||
| // For returns the HelmChart info for the given component from the configmap referenced in the cluster variables. | ||
| // It first checks the configmap referenced in the cluster variables. | ||
| // If not found, it returns the HelmChart info from the default configmap. | ||
| func (h *HelmChartGetter) For( | ||
| ctx context.Context, | ||
| log logr.Logger, | ||
| cluster *clusterv1.Cluster, | ||
| name Component, | ||
| ) (*HelmChart, error) { | ||
| varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables) | ||
|
|
||
| helmChartConfig, err := variables.Get[v1alpha1.HelmChartConfig]( | ||
| varMap, | ||
| v1alpha1.ClusterConfigVariableName, | ||
| "addons", "helmChartConfig") | ||
| if err != nil { | ||
| if variables.IsNotFoundError(err) { | ||
| // HelmChartConfig is not defined in the cluster. Get the HelmChart from the default configmap. | ||
| return h.getInfoFor(ctx, log, name) | ||
| } | ||
| return nil, err | ||
| } | ||
| // helmChartConfig.ConfigMapRef or helmChartConfig.ConfigMapRef.Name will not be nil | ||
| // because it will be validated by the schema validation. | ||
| cmNameFromVariables := helmChartConfig.ConfigMapRef.Name | ||
| clusterNamespace := cluster.Namespace | ||
| hcGetter := NewHelmChartGetterFromConfigMap(cmNameFromVariables, clusterNamespace, h.cl) | ||
| overrideHelmChart, err := hcGetter.getInfoFor(ctx, log, name) | ||
| if err != nil { | ||
| if errors.As(err, &HelmChartInfoNotFoundError{}) { | ||
| // HelmChart is not defined in the custom configmap. Get the HelmChart from the default configmap. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth logging a warn |
||
| return h.getInfoFor(ctx, log, name) | ||
| } | ||
| return nil, err | ||
| } | ||
| log.Info( | ||
| fmt.Sprintf( | ||
| "using HelmChart info for %q from custom configmap %s/%s referenced in cluster variables", | ||
| string(name), | ||
| clusterNamespace, | ||
| cmNameFromVariables, | ||
| ), | ||
| ) | ||
| return overrideHelmChart, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helmChartFromCustomConfigMap would be a better name IMO. I had to think about what "override" meant in this context