diff --git a/charts/cluster-api-runtime-extensions-nutanix/templates/deployment.yaml b/charts/cluster-api-runtime-extensions-nutanix/templates/deployment.yaml index 6e421f3fd..f66f1dd7f 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/templates/deployment.yaml +++ b/charts/cluster-api-runtime-extensions-nutanix/templates/deployment.yaml @@ -36,8 +36,9 @@ spec: - --helm-addons-configmap={{ .Values.helmAddonsConfigMap }} - --cni.cilium.helm-addon.default-values-template-configmap-name={{ .Values.hooks.cni.cilium.helmAddonStrategy.defaultValueTemplateConfigMap.name }} - --nfd.helm-addon.default-values-template-configmap-name={{ .Values.hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.name }} - - --csi.local-path.helm-addon.default-values-template-configmap-name={{ (index .Values.hooks.csi "local-path").helmAddonStrategy.defaultValueTemplateConfigMap.name }} - --csi.aws-ebs.helm-addon.default-values-template-configmap-name={{ (index .Values.hooks.csi "aws-ebs").helmAddonStrategy.defaultValueTemplateConfigMap.name }} + - --csi.nutanix.helm-addon.default-values-template-configmap-name={{ (index .Values.hooks.csi "nutanix").helmAddonStrategy.defaultValueTemplateConfigMap.name }} + - --csi.local-path.helm-addon.default-values-template-configmap-name={{ (index .Values.hooks.csi "local-path").helmAddonStrategy.defaultValueTemplateConfigMap.name }} {{- range $key, $value := .Values.extraArgs }} - --{{ $key }}={{ $value }} {{- end }} diff --git a/hack/addons/kustomize/nutanix-snapshot-csi/kustomization.yaml.tmpl b/hack/addons/kustomize/nutanix-snapshot-csi/kustomization.yaml.tmpl index be02846b1..fe105d813 100644 --- a/hack/addons/kustomize/nutanix-snapshot-csi/kustomization.yaml.tmpl +++ b/hack/addons/kustomize/nutanix-snapshot-csi/kustomization.yaml.tmpl @@ -16,4 +16,3 @@ helmCharts: version: ${NUTANIX_SNAPSHOT_CSI_CHART_VERSION} includeCRDs: true skipTests: true - namespace: nutanix-system diff --git a/hack/addons/kustomize/nutanix-storage-csi/kustomization.yaml.tmpl b/hack/addons/kustomize/nutanix-storage-csi/kustomization.yaml.tmpl index d4572e71d..ff3418b7e 100644 --- a/hack/addons/kustomize/nutanix-storage-csi/kustomization.yaml.tmpl +++ b/hack/addons/kustomize/nutanix-storage-csi/kustomization.yaml.tmpl @@ -14,7 +14,5 @@ helmCharts: repo: https://nutanix.github.io/helm-releases/ releaseName: nutanix-csi-storage version: ${NUTANIX_STORAGE_CSI_CHART_VERSION} - valuesFile: helm-values.yaml includeCRDs: true skipTests: true - namespace: nutanix-system diff --git a/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go b/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go index b5f4d5600..60c1662ae 100644 --- a/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go @@ -92,7 +92,7 @@ func (a *AWSEBS) Apply( client: a.client, } default: - return fmt.Errorf("strategy %s not implemented", strategy) + return fmt.Errorf("strategy %s not implemented", provider.Strategy) } if err := strategy.apply(ctx, cluster, a.config.DefaultsNamespace(), log); err != nil { diff --git a/pkg/handlers/generic/lifecycle/csi/localpath/handler.go b/pkg/handlers/generic/lifecycle/csi/localpath/handler.go index d1f41bf01..f4ecc298e 100644 --- a/pkg/handlers/generic/lifecycle/csi/localpath/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/localpath/handler.go @@ -87,7 +87,7 @@ func (l *LocalPathProvisionerCSI) Apply( client: l.client, } default: - return fmt.Errorf("strategy %s not implemented", strategy) + return fmt.Errorf("strategy %s not implemented", provider.Strategy) } if err := strategy.apply(ctx, cluster, l.config.DefaultsNamespace(), log); err != nil { diff --git a/pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go b/pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go deleted file mode 100644 index f070e0c78..000000000 --- a/pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright 2023 Nutanix. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package nutanix - -import ( - "context" - "fmt" - - "github.com/go-logr/logr" - "github.com/spf13/pflag" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - caaphv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/k8s/client" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/config" - csiutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/utils" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options" - handlersutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/utils" -) - -const ( - defaultStorageHelmReleaseName = "nutanix-csi-storage" - defaultStorageHelmReleaseNamespace = "ntnx-system" - - defaultSnapshotHelmReleaseName = "nutanix-csi-snapshot" - defaultSnapshotHelmReleaseNamespace = "ntnx-system" - - //nolint:gosec // Does not contain hard coded credentials. - defaultCredentialsSecretName = "nutanix-csi-credentials" -) - -var defaultStorageClassParameters = map[string]string{ - "storageType": "NutanixVolumes", - "csi.storage.k8s.io/fstype": "xfs", - "csi.storage.k8s.io/provisioner-secret-name": defaultCredentialsSecretName, - "csi.storage.k8s.io/provisioner-secret-namespace": defaultStorageHelmReleaseNamespace, - "csi.storage.k8s.io/node-publish-secret-name": defaultCredentialsSecretName, - "csi.storage.k8s.io/node-publish-secret-namespace": defaultStorageHelmReleaseNamespace, - "csi.storage.k8s.io/controller-expand-secret-name": defaultCredentialsSecretName, - "csi.storage.k8s.io/controller-expand-secret-namespace": defaultStorageHelmReleaseNamespace, -} - -type NutanixCSIConfig struct { - *options.GlobalOptions - defaultValuesTemplateConfigMapName string -} - -func (n *NutanixCSIConfig) AddFlags(prefix string, flags *pflag.FlagSet) { - flags.StringVar( - &n.defaultValuesTemplateConfigMapName, - prefix+".default-values-template-configmap-name", - "default-nutanix-csi-helm-values-template", - "default values ConfigMap name", - ) -} - -type NutanixCSI struct { - client ctrlclient.Client - config *NutanixCSIConfig - helmChartInfoGetter *config.HelmChartGetter -} - -func New( - c ctrlclient.Client, - cfg *NutanixCSIConfig, - helmChartInfoGetter *config.HelmChartGetter, -) *NutanixCSI { - return &NutanixCSI{ - client: c, - config: cfg, - helmChartInfoGetter: helmChartInfoGetter, - } -} - -func (n *NutanixCSI) Apply( - ctx context.Context, - provider v1alpha1.CSIProvider, - defaultStorage v1alpha1.DefaultStorage, - cluster *clusterv1.Cluster, - log logr.Logger, -) error { - strategy := provider.Strategy - switch strategy { - case v1alpha1.AddonStrategyHelmAddon: - err := n.handleHelmAddonApply(ctx, cluster, log) - if err != nil { - return err - } - case v1alpha1.AddonStrategyClusterResourceSet: - default: - return fmt.Errorf("stategy %s not implemented", strategy) - } - - if provider.Credentials != nil { - err := handlersutils.EnsureOwnerReferenceForSecret( - ctx, - n.client, - provider.Credentials.SecretRef.Name, - cluster, - ) - if err != nil { - return fmt.Errorf( - "error updating owner references on Nutanix CSI driver source Secret: %w", - err, - ) - } - key := ctrlclient.ObjectKey{ - Name: defaultCredentialsSecretName, - Namespace: defaultStorageHelmReleaseNamespace, - } - err = handlersutils.CopySecretToRemoteCluster( - ctx, - n.client, - provider.Credentials.SecretRef.Name, - key, - cluster, - ) - if err != nil { - return fmt.Errorf( - "error creating credentials Secret for the Nutanix CSI driver: %w", - err, - ) - } - } - - err := csiutils.CreateStorageClassesOnRemote( - ctx, - n.client, - provider.StorageClassConfigs, - cluster, - defaultStorage, - v1alpha1.CSIProviderNutanix, - v1alpha1.NutanixProvisioner, - defaultStorageClassParameters, - ) - if err != nil { - return fmt.Errorf("error creating StorageClasses for the Nutanix CSI driver: %w", err) - } - return nil -} - -func (n *NutanixCSI) handleHelmAddonApply( - ctx context.Context, - cluster *clusterv1.Cluster, - log logr.Logger, -) error { - log.Info("Retrieving Nutanix CSI installation values template for cluster") - values, err := handlersutils.RetrieveValuesTemplate( - ctx, - n.client, - n.config.defaultValuesTemplateConfigMapName, - n.config.DefaultsNamespace(), - ) - if err != nil { - return fmt.Errorf( - "failed to retrieve nutanix csi installation values template ConfigMap for cluster: %w", - err, - ) - } - - storageChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixStorageCSI) - if err != nil { - return fmt.Errorf("failed to get helm chart %q: %w", config.NutanixStorageCSI, err) - } - - snapshotChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixSnapshotCSI) - if err != nil { - return fmt.Errorf("failed to get helm chart %q: %w", config.NutanixSnapshotCSI, err) - } - - storageChartProxy := &caaphv1.HelmChartProxy{ - TypeMeta: metav1.TypeMeta{ - APIVersion: caaphv1.GroupVersion.String(), - Kind: "HelmChartProxy", - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: cluster.Namespace, - Name: "nutanix-csi-" + cluster.Name, - }, - Spec: caaphv1.HelmChartProxySpec{ - RepoURL: storageChart.Repository, - ChartName: storageChart.Name, - ClusterSelector: metav1.LabelSelector{ - MatchLabels: map[string]string{clusterv1.ClusterNameLabel: cluster.Name}, - }, - ReleaseNamespace: defaultStorageHelmReleaseNamespace, - ReleaseName: defaultStorageHelmReleaseName, - Version: storageChart.Version, - ValuesTemplate: values, - }, - } - handlersutils.SetTLSConfigForHelmChartProxyIfNeeded(storageChartProxy) - snapshotChartProxy := &caaphv1.HelmChartProxy{ - TypeMeta: metav1.TypeMeta{ - APIVersion: caaphv1.GroupVersion.String(), - Kind: "HelmChartProxy", - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: cluster.Namespace, - Name: "nutanix-csi-snapshot-" + cluster.Name, - }, - Spec: caaphv1.HelmChartProxySpec{ - RepoURL: snapshotChart.Repository, - ChartName: snapshotChart.Name, - ClusterSelector: metav1.LabelSelector{ - MatchLabels: map[string]string{clusterv1.ClusterNameLabel: cluster.Name}, - }, - ReleaseNamespace: defaultSnapshotHelmReleaseNamespace, - ReleaseName: defaultSnapshotHelmReleaseName, - Version: snapshotChart.Version, - }, - } - handlersutils.SetTLSConfigForHelmChartProxyIfNeeded(snapshotChartProxy) - // We use a slice of pointers to satisfy the gocritic linter rangeValCopy check. - for _, cp := range []*caaphv1.HelmChartProxy{storageChartProxy, snapshotChartProxy} { - if err = controllerutil.SetOwnerReference(cluster, cp, n.client.Scheme()); err != nil { - return fmt.Errorf( - "failed to set owner reference on HelmChartProxy %q: %w", - cp.Name, - err, - ) - } - - if err = client.ServerSideApply(ctx, n.client, cp, client.ForceOwnership); err != nil { - return fmt.Errorf("failed to apply HelmChartProxy %q: %w", cp.Name, err) - } - } - - return nil -} diff --git a/pkg/handlers/generic/lifecycle/csi/nutanix/handler.go b/pkg/handlers/generic/lifecycle/csi/nutanix/handler.go new file mode 100644 index 000000000..0225e2824 --- /dev/null +++ b/pkg/handlers/generic/lifecycle/csi/nutanix/handler.go @@ -0,0 +1,159 @@ +// Copyright 2024 Nutanix. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package nutanix + +import ( + "context" + "fmt" + + "github.com/go-logr/logr" + "github.com/spf13/pflag" + 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/pkg/handlers/generic/lifecycle/config" + csiutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/utils" + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options" + handlersutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/utils" +) + +const ( + defaultStorageHelmReleaseName = "nutanix-csi" + defaultStorageHelmReleaseNamespace = "ntnx-system" + + defaultSnapshotHelmReleaseName = "nutanix-csi-snapshot" + defaultSnapshotHelmReleaseNamespace = "ntnx-system" + + //nolint:gosec // Does not contain hard coded credentials. + defaultCredentialsSecretName = "nutanix-csi-credentials" +) + +type addonStrategy interface { + apply( + context.Context, + *clusterv1.Cluster, + string, + logr.Logger, + ) error +} + +var DefaultStorageClassParameters = map[string]string{ + "storageType": "NutanixVolumes", + "csi.storage.k8s.io/fstype": "xfs", + "csi.storage.k8s.io/provisioner-secret-name": defaultCredentialsSecretName, + "csi.storage.k8s.io/provisioner-secret-namespace": defaultStorageHelmReleaseNamespace, + "csi.storage.k8s.io/node-publish-secret-name": defaultCredentialsSecretName, + "csi.storage.k8s.io/node-publish-secret-namespace": defaultStorageHelmReleaseNamespace, + "csi.storage.k8s.io/controller-expand-secret-name": defaultCredentialsSecretName, + "csi.storage.k8s.io/controller-expand-secret-namespace": defaultStorageHelmReleaseNamespace, +} + +type NutanixCSIConfig struct { + *options.GlobalOptions + + helmAddonConfig helmAddonConfig +} + +func (n *NutanixCSIConfig) AddFlags(prefix string, flags *pflag.FlagSet) { + n.helmAddonConfig.AddFlags(prefix+".helm-addon", flags) +} + +type NutanixCSI struct { + client ctrlclient.Client + config *NutanixCSIConfig + helmChartInfoGetter *config.HelmChartGetter +} + +func New( + c ctrlclient.Client, + cfg *NutanixCSIConfig, + helmChartInfoGetter *config.HelmChartGetter, +) *NutanixCSI { + return &NutanixCSI{ + client: c, + config: cfg, + helmChartInfoGetter: helmChartInfoGetter, + } +} + +func (n *NutanixCSI) Apply( + ctx context.Context, + provider v1alpha1.CSIProvider, + defaultStorage v1alpha1.DefaultStorage, + cluster *clusterv1.Cluster, + log logr.Logger, +) error { + var strategy addonStrategy + switch provider.Strategy { + case v1alpha1.AddonStrategyHelmAddon: + helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixStorageCSI) + if err != nil { + return fmt.Errorf("failed to get configuration for Nutanix storage chart to create helm addon: %w", err) + } + snapshotHelmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixSnapshotCSI) + if err != nil { + return fmt.Errorf("failed to get configuration for Nutanix snapshot chart to create helm addon: %w", err) + } + strategy = helmAddonStrategy{ + config: n.config.helmAddonConfig, + client: n.client, + helmChart: helmChart, + snapshotHelmChart: snapshotHelmChart, + } + default: + return fmt.Errorf("strategy %s not implemented", provider.Strategy) + } + + if provider.Credentials != nil { + err := handlersutils.EnsureOwnerReferenceForSecret( + ctx, + n.client, + provider.Credentials.SecretRef.Name, + cluster, + ) + if err != nil { + return fmt.Errorf( + "error updating owner references on Nutanix CSI driver source Secret: %w", + err, + ) + } + key := ctrlclient.ObjectKey{ + Name: defaultCredentialsSecretName, + Namespace: defaultStorageHelmReleaseNamespace, + } + err = handlersutils.CopySecretToRemoteCluster( + ctx, + n.client, + provider.Credentials.SecretRef.Name, + key, + cluster, + ) + if err != nil { + return fmt.Errorf( + "error creating credentials Secret for the Nutanix CSI driver: %w", + err, + ) + } + } + + if err := strategy.apply(ctx, cluster, n.config.DefaultsNamespace(), log); err != nil { + return fmt.Errorf("failed to apply nutanix CSI addon: %w", err) + } + + err := csiutils.CreateStorageClassesOnRemote( + ctx, + n.client, + provider.StorageClassConfigs, + cluster, + defaultStorage, + v1alpha1.CSIProviderNutanix, + v1alpha1.NutanixProvisioner, + DefaultStorageClassParameters, + ) + if err != nil { + return fmt.Errorf("error creating StorageClasses for the Nutanix CSI driver: %w", err) + } + return nil +} diff --git a/pkg/handlers/generic/lifecycle/csi/nutanix/strategy_helmaddon.go b/pkg/handlers/generic/lifecycle/csi/nutanix/strategy_helmaddon.go new file mode 100644 index 000000000..d48042d13 --- /dev/null +++ b/pkg/handlers/generic/lifecycle/csi/nutanix/strategy_helmaddon.go @@ -0,0 +1,133 @@ +// Copyright 2024 Nutanix. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package nutanix + +import ( + "context" + "fmt" + + "github.com/go-logr/logr" + "github.com/spf13/pflag" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + + caaphv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/k8s/client" + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/config" + handlersutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/utils" +) + +type helmAddonConfig struct { + defaultValuesTemplateConfigMapName string +} + +func (c *helmAddonConfig) AddFlags(prefix string, flags *pflag.FlagSet) { + flags.StringVar( + &c.defaultValuesTemplateConfigMapName, + prefix+".default-values-template-configmap-name", + "default-nutanix-csi-helm-values-template", + "default values ConfigMap name", + ) +} + +type helmAddonStrategy struct { + config helmAddonConfig + client ctrlclient.Client + helmChart *config.HelmChart + snapshotHelmChart *config.HelmChart +} + +func (s helmAddonStrategy) apply( + ctx context.Context, + cluster *clusterv1.Cluster, + defaultsNamespace string, + log logr.Logger, +) error { + log.Info("Retrieving Nutanix CSI installation values template for cluster") + storageChartValues, err := handlersutils.RetrieveValuesTemplate( + ctx, + s.client, + s.config.defaultValuesTemplateConfigMapName, + defaultsNamespace, + ) + if err != nil { + return fmt.Errorf( + "failed to retrieve nutanix csi installation values template ConfigMap for cluster: %w", + err, + ) + } + + storageChartProxy := &caaphv1.HelmChartProxy{ + TypeMeta: metav1.TypeMeta{ + APIVersion: caaphv1.GroupVersion.String(), + Kind: "HelmChartProxy", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: cluster.Namespace, + Name: "nutanix-csi-" + cluster.Name, + }, + Spec: caaphv1.HelmChartProxySpec{ + RepoURL: s.helmChart.Repository, + ChartName: s.helmChart.Name, + ClusterSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{clusterv1.ClusterNameLabel: cluster.Name}, + }, + ReleaseNamespace: defaultStorageHelmReleaseNamespace, + ReleaseName: defaultStorageHelmReleaseName, + Version: s.helmChart.Version, + ValuesTemplate: storageChartValues, + }, + } + handlersutils.SetTLSConfigForHelmChartProxyIfNeeded(storageChartProxy) + + if err = controllerutil.SetOwnerReference(cluster, storageChartProxy, s.client.Scheme()); err != nil { + return fmt.Errorf( + "failed to set owner reference on HelmChartProxy %q: %w", + storageChartProxy.Name, + err, + ) + } + + if err = client.ServerSideApply(ctx, s.client, storageChartProxy, client.ForceOwnership); err != nil { + return fmt.Errorf("failed to apply HelmChartProxy %q: %w", storageChartProxy.Name, err) + } + + snapshotChartProxy := &caaphv1.HelmChartProxy{ + TypeMeta: metav1.TypeMeta{ + APIVersion: caaphv1.GroupVersion.String(), + Kind: "HelmChartProxy", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: cluster.Namespace, + Name: "nutanix-csi-snapshot-" + cluster.Name, + }, + Spec: caaphv1.HelmChartProxySpec{ + RepoURL: s.snapshotHelmChart.Repository, + ChartName: s.snapshotHelmChart.Name, + ClusterSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{clusterv1.ClusterNameLabel: cluster.Name}, + }, + ReleaseNamespace: defaultSnapshotHelmReleaseNamespace, + ReleaseName: defaultSnapshotHelmReleaseName, + Version: s.snapshotHelmChart.Version, + }, + } + handlersutils.SetTLSConfigForHelmChartProxyIfNeeded(snapshotChartProxy) + + if err = controllerutil.SetOwnerReference(cluster, snapshotChartProxy, s.client.Scheme()); err != nil { + return fmt.Errorf( + "failed to set owner reference on HelmChartProxy %q: %w", + snapshotChartProxy.Name, + err, + ) + } + + if err = client.ServerSideApply(ctx, s.client, snapshotChartProxy, client.ForceOwnership); err != nil { + return fmt.Errorf("failed to apply HelmChartProxy %q: %w", snapshotChartProxy.Name, err) + } + + return nil +} diff --git a/pkg/handlers/generic/lifecycle/handlers.go b/pkg/handlers/generic/lifecycle/handlers.go index 4bf5f119c..14d26f0f0 100644 --- a/pkg/handlers/generic/lifecycle/handlers.go +++ b/pkg/handlers/generic/lifecycle/handlers.go @@ -19,7 +19,7 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/awsebs" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/localpath" - nutanixcsi "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/nutanix-csi" + nutanixcsi "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/nutanix" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/nfd" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/servicelbgc" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/serviceloadbalancer" @@ -118,7 +118,7 @@ func (h *Handlers) AddFlags(flagSet *pflag.FlagSet) { h.ciliumCNIConfig.AddFlags("cni.cilium", flagSet) h.ebsConfig.AddFlags("csi.aws-ebs", pflag.CommandLine) h.awsccmConfig.AddFlags("awsccm", pflag.CommandLine) - h.nutanixCSIConfig.AddFlags("nutanixcsi", flagSet) + h.nutanixCSIConfig.AddFlags("csi.nutanix", flagSet) h.nutanixCCMConfig.AddFlags("nutanixccm", flagSet) h.metalLBConfig.AddFlags("metallb", flagSet) h.localPathCSIConfig.AddFlags("csi.local-path", flagSet) diff --git a/test/e2e/csi_helpers.go b/test/e2e/csi_helpers.go index 279a0219f..59ff4ce4e 100644 --- a/test/e2e/csi_helpers.go +++ b/test/e2e/csi_helpers.go @@ -27,6 +27,7 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" apivariables "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/awsebs" + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/nutanix" ) type WaitForCSIToBeReadyInWorkloadClusterInput struct { @@ -78,6 +79,19 @@ func WaitForCSIToBeReadyInWorkloadCluster( }, ) defaultStorageClassParameters[providerName] = awsebs.DefaultStorageClassParameters + case v1alpha1.CSIProviderNutanix: + waitForNutanixCSIToBeReadyInWorkloadCluster( + ctx, + waitForNutanixCSIToBeReadyInWorkloadClusterInput{ + strategy: providerConfig.Strategy, + workloadCluster: input.WorkloadCluster, + clusterProxy: input.ClusterProxy, + deploymentIntervals: input.DeploymentIntervals, + daemonSetIntervals: input.DaemonSetIntervals, + helmReleaseIntervals: input.HelmReleaseIntervals, + }, + ) + defaultStorageClassParameters[providerName] = nutanix.DefaultStorageClassParameters default: Fail( fmt.Sprintf( @@ -245,7 +259,65 @@ func waitForAWSEBSCSIToBeReadyInWorkloadCluster( Namespace: metav1.NamespaceSystem, }, }, + }, input.daemonSetIntervals...) +} + +type waitForNutanixCSIToBeReadyInWorkloadClusterInput struct { + strategy v1alpha1.AddonStrategy + workloadCluster *clusterv1.Cluster + clusterProxy framework.ClusterProxy + deploymentIntervals []interface{} + daemonSetIntervals []interface{} + helmReleaseIntervals []interface{} +} + +func waitForNutanixCSIToBeReadyInWorkloadCluster( + ctx context.Context, + input waitForNutanixCSIToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. +) { + switch input.strategy { + case v1alpha1.AddonStrategyHelmAddon: + WaitForHelmReleaseProxyReadyForCluster( + ctx, + WaitForHelmReleaseProxyReadyForClusterInput{ + GetLister: input.clusterProxy.GetClient(), + Cluster: input.workloadCluster, + HelmChartProxyName: "nutanix-csi-" + input.workloadCluster.Name, + }, + input.helmReleaseIntervals..., + ) + default: + Fail( + fmt.Sprintf( + "Do not know how to wait for nutanix CSI using strategy %s to be ready", + input.strategy, + ), + ) + } + + workloadClusterClient := input.clusterProxy.GetWorkloadCluster( + ctx, input.workloadCluster.Namespace, input.workloadCluster.Name, + ).GetClient() + + WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ + Getter: workloadClusterClient, + Deployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "nutanix-csi-controller", + Namespace: metav1.NamespaceSystem, + }, + }, }, input.deploymentIntervals...) + + WaitForDaemonSetsAvailable(ctx, WaitForDaemonSetsAvailableInput{ + Getter: workloadClusterClient, + DaemonSet: &appsv1.DaemonSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: "nutanix-csi-node", + Namespace: metav1.NamespaceSystem, + }, + }, + }, input.daemonSetIntervals...) } type waitForStorageClassesToExistInWorkloadClusterInput struct {