From ff05c285613c6e4da7bcad43aebe25a276e87ab1 Mon Sep 17 00:00:00 2001 From: faiq Date: Fri, 29 Mar 2024 14:01:20 -0600 Subject: [PATCH] feat: deploy snapshot chart with nutanix --- api/v1alpha1/zz_generated.deepcopy.go | 18 ------- .../templates/role.yaml | 2 +- make/addons.mk | 1 - pkg/handlers/generic/lifecycle/csi/handler.go | 7 ++- .../lifecycle/csi/nutanix-csi/handler.go | 53 ++++++++++++++++--- pkg/handlers/generic/lifecycle/handlers.go | 6 +-- 6 files changed, 51 insertions(+), 36 deletions(-) diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index ec26a8beb..4f33138e6 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -251,23 +251,6 @@ func (in *CNI) DeepCopy() *CNI { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -<<<<<<< HEAD -======= -func (in *CPI) DeepCopyInto(out *CPI) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CPI. -func (in *CPI) DeepCopy() *CPI { - if in == nil { - return nil - } - out := new(CPI) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CSI) DeepCopyInto(out *CSI) { *out = *in @@ -296,7 +279,6 @@ func (in *CSI) DeepCopy() *CSI { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. ->>>>>>> 1020f52 (refactor: rename CSIProviders to CSI) func (in *CSIProvider) DeepCopyInto(out *CSIProvider) { *out = *in if in.StorageClassConfig != nil { diff --git a/charts/cluster-api-runtime-extensions-nutanix/templates/role.yaml b/charts/cluster-api-runtime-extensions-nutanix/templates/role.yaml index 84702cdfb..e3cd174f7 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/templates/role.yaml +++ b/charts/cluster-api-runtime-extensions-nutanix/templates/role.yaml @@ -4,7 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: cluster-api-runtime-extensions-nutanix-manager-role + name: {{ include "chart.name" . }}-manager-role rules: - apiGroups: - "" diff --git a/make/addons.mk b/make/addons.mk index 64c1b42db..c09890922 100644 --- a/make/addons.mk +++ b/make/addons.mk @@ -44,4 +44,3 @@ update-addon.aws-ccm.%: ; $(info $(M) updating aws ccm $* manifests) .PHONY: update-addon.nutanix-csi update-addon.nutanix-csi: ; $(info $(M) updating nutanix csi manifests) ./hack/addons/update-nutanix-csi.sh - diff --git a/pkg/handlers/generic/lifecycle/csi/handler.go b/pkg/handlers/generic/lifecycle/csi/handler.go index 01f3e2b66..fd07767c6 100644 --- a/pkg/handlers/generic/lifecycle/csi/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/handler.go @@ -99,7 +99,6 @@ func (c *CSIHandler) AfterControlPlaneInitialized( return } if len(csiProviders.Providers) == 1 && - csiProviders.Providers[0].StorageClassConfig != nil && len(csiProviders.Providers[0].StorageClassConfig) == 1 && csiProviders.DefaultStorage == nil { csiProviders.DefaultStorage = &v1alpha1.DefaultStorage{ @@ -113,13 +112,13 @@ func (c *CSIHandler) AfterControlPlaneInitialized( if !ok { log.V(4).Info( fmt.Sprintf( - "Skipping CSI handler, for provider given in %q. Provider handler not given ", - provider, + "Skipping CSI handler, for provider given in %s. Provider handler not given.", + provider.Name, ), ) continue } - log.Info(fmt.Sprintf("Creating csi provider %s", provider)) + log.Info(fmt.Sprintf("Creating csi provider %s", provider.Name)) err = handler.Apply( ctx, provider, diff --git a/pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go b/pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go index 090a9e06d..90190bef1 100644 --- a/pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/nutanix-csi/handler.go @@ -24,10 +24,14 @@ import ( ) const ( - defaultHelmRepositoryURL = "https://nutanix.github.io/helm/" - defaultHelmChartVersion = "v2.6.6" - defaultHelmChartName = "nutanix-csi-storage" - defaultHelmReleaseNameTemplate = "nutanix-csi-storage-%s" + defaultHelmRepositoryURL = "https://nutanix.github.io/helm/" + defaultStorageHelmChartVersion = "v2.6.6" + defaultStorageHelmChartName = "nutanix-csi-storage" + defaultStorageHelmReleaseNameTemplate = "nutanix-csi-storage-%s" + + defaultSnapshotHelmChartVersion = "v6.3.2" + defaultSnapshotHelmChartName = "nutanix-csi-snapshot" + defaultSnapshotHelmReleaseNameTemplate = "nutanix-csi-snapshot-%s" ) type NutanixCSIConfig struct { @@ -141,13 +145,13 @@ func (n *NutanixCSI) handleHelmAddonApply( }, Spec: caaphv1.HelmChartProxySpec{ RepoURL: defaultHelmRepositoryURL, - ChartName: defaultHelmChartName, + ChartName: defaultStorageHelmChartName, ClusterSelector: metav1.LabelSelector{ MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name}, }, ReleaseNamespace: req.Cluster.Namespace, - ReleaseName: fmt.Sprintf(defaultHelmReleaseNameTemplate, req.Cluster.Name), - Version: defaultHelmChartVersion, + ReleaseName: fmt.Sprintf(defaultStorageHelmReleaseNameTemplate, req.Cluster.Name), + Version: defaultStorageHelmChartVersion, ValuesTemplate: values, }, } @@ -163,6 +167,41 @@ func (n *NutanixCSI) handleHelmAddonApply( return fmt.Errorf("failed to apply nutanix-csi installation HelmChartProxy: %w", err) } + snapshotChart := &caaphv1.HelmChartProxy{ + TypeMeta: metav1.TypeMeta{ + APIVersion: caaphv1.GroupVersion.String(), + Kind: "HelmChartProxy", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: req.Cluster.Namespace, + Name: "nutanix-csi-snapshot" + req.Cluster.Name, + }, + Spec: caaphv1.HelmChartProxySpec{ + RepoURL: defaultHelmRepositoryURL, + ChartName: defaultSnapshotHelmChartName, + ClusterSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name}, + }, + ReleaseNamespace: req.Cluster.Namespace, + ReleaseName: fmt.Sprintf(defaultStorageHelmReleaseNameTemplate, req.Cluster.Name), + Version: defaultSnapshotHelmChartVersion, + }, + } + + if err = controllerutil.SetOwnerReference(&req.Cluster, snapshotChart, n.client.Scheme()); err != nil { + return fmt.Errorf( + "failed to set owner reference on nutanix-csi installation HelmChartProxy: %w", + err, + ) + } + + if err = client.ServerSideApply(ctx, n.client, snapshotChart); err != nil { + return fmt.Errorf( + "failed to apply nutanix-csi-snapshot installation HelmChartProxy: %w", + err, + ) + } + return nil } diff --git a/pkg/handlers/generic/lifecycle/handlers.go b/pkg/handlers/generic/lifecycle/handlers.go index 33d08e130..b3b0d22fb 100644 --- a/pkg/handlers/generic/lifecycle/handlers.go +++ b/pkg/handlers/generic/lifecycle/handlers.go @@ -29,7 +29,7 @@ type Handlers struct { clusterAutoscalerConfig *clusterautoscaler.Config ebsConfig *awsebs.AWSEBSConfig nutnaixCSIConfig *nutanixcsi.NutanixCSIConfig - awsCPIConfig *awscpi.AWSCPIConfig + awsccmConfig *awsccm.AWSCCMConfig } func New(globalOptions *options.GlobalOptions) *Handlers { @@ -70,10 +70,6 @@ func (h *Handlers) AddFlags(flagSet *pflag.FlagSet) { h.calicoCNIConfig.AddFlags("cni.calico", flagSet) h.ciliumCNIConfig.AddFlags("cni.cilium", flagSet) h.ebsConfig.AddFlags("awsebs", pflag.CommandLine) -<<<<<<< HEAD h.awsccmConfig.AddFlags("awsccm", pflag.CommandLine) -======= h.nutnaixCSIConfig.AddFlags("nutanixcsi", flagSet) - h.awsCPIConfig.AddFlags("awscpi", pflag.CommandLine) ->>>>>>> f7ff2e9 (fix: adds proper permissions and api fixes) }