diff --git a/api/v1alpha1/addon_types.go b/api/v1alpha1/addon_types.go index 1d7bd5533..55d3af60c 100644 --- a/api/v1alpha1/addon_types.go +++ b/api/v1alpha1/addon_types.go @@ -96,7 +96,7 @@ type GenericAddons struct { ServiceLoadBalancer *ServiceLoadBalancer `json:"serviceLoadBalancer,omitempty"` } -// +kubebuilder:validation:Required +// +kubebuilder:validation:Optional // +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon type AddonStrategy string @@ -109,14 +109,14 @@ type CNI struct { // Addon strategy used to deploy the CNI provider to the workload cluster. // +kubebuilder:default=HelmAddon - Strategy AddonStrategy `json:"strategy"` + Strategy *AddonStrategy `json:"strategy,omitempty"` } // NFD tells us to enable or disable the node feature discovery addon. type NFD struct { // Addon strategy used to deploy Node Feature Discovery (NFD) to the workload cluster. // +kubebuilder:default=HelmAddon - Strategy AddonStrategy `json:"strategy"` + Strategy *AddonStrategy `json:"strategy,omitempty"` } // ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon. @@ -124,7 +124,7 @@ type ClusterAutoscaler struct { // Addon strategy used to deploy cluster-autoscaler to the management cluster // targeting the workload cluster. // +kubebuilder:default=HelmAddon - Strategy AddonStrategy `json:"strategy"` + Strategy *AddonStrategy `json:"strategy,omitempty"` } type GenericCSI struct { @@ -139,7 +139,7 @@ type GenericCSI struct { type SnapshotController struct { // Addon strategy used to deploy the snapshot controller to the workload cluster. // +kubebuilder:default=HelmAddon - Strategy AddonStrategy `json:"strategy"` + Strategy *AddonStrategy `json:"strategy,omitempty"` } type DefaultStorage struct { @@ -197,7 +197,7 @@ type CSIProvider struct { // Addon strategy used to deploy the CSI provider to the workload cluster. // +kubebuilder:default=HelmAddon - Strategy AddonStrategy `json:"strategy"` + Strategy *AddonStrategy `json:"strategy,omitempty"` // The reference to any secret used by the CSI Provider. // +kubebuilder:validation:Optional @@ -239,7 +239,7 @@ type CCM struct { // Addon strategy used to deploy the CCM to the workload cluster. // +kubebuilder:default=HelmAddon - Strategy AddonStrategy `json:"strategy"` + Strategy *AddonStrategy `json:"strategy,omitempty"` } type CCMCredentials struct { diff --git a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml index 3df8c6979..9373306e8 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml @@ -71,8 +71,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object clusterAutoscaler: description: ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon. @@ -86,8 +84,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object cni: description: CNI required for providing CNI configuration. @@ -107,7 +103,6 @@ spec: type: string required: - provider - - strategy type: object csi: properties: @@ -187,7 +182,6 @@ spec: type: string required: - storageClassConfigs - - strategy type: object required: - aws-ebs @@ -202,8 +196,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object required: - defaultStorage @@ -219,8 +211,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object serviceLoadBalancer: properties: diff --git a/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml index 4ecb4e141..572b1307a 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml @@ -71,8 +71,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object clusterAutoscaler: description: ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon. @@ -86,8 +84,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object cni: description: CNI required for providing CNI configuration. @@ -107,7 +103,6 @@ spec: type: string required: - provider - - strategy type: object csi: properties: @@ -187,7 +182,6 @@ spec: type: string required: - storageClassConfigs - - strategy type: object required: - local-path @@ -202,8 +196,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object required: - defaultStorage @@ -219,8 +211,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object serviceLoadBalancer: properties: diff --git a/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml index a9c3a0106..8050bfd75 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml @@ -71,8 +71,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object clusterAutoscaler: description: ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon. @@ -86,8 +84,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object cni: description: CNI required for providing CNI configuration. @@ -107,7 +103,6 @@ spec: type: string required: - provider - - strategy type: object csi: properties: @@ -187,7 +182,6 @@ spec: type: string required: - storageClassConfigs - - strategy type: object required: - nutanix @@ -202,8 +196,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object required: - defaultStorage @@ -219,8 +211,6 @@ spec: - ClusterResourceSet - HelmAddon type: string - required: - - strategy type: object serviceLoadBalancer: properties: diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 1a27f596a..df67ea023 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -421,6 +421,11 @@ func (in *CCM) DeepCopyInto(out *CCM) { *out = new(CCMCredentials) **out = **in } + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(AddonStrategy) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CCM. @@ -452,6 +457,11 @@ func (in *CCMCredentials) DeepCopy() *CCMCredentials { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CNI) DeepCopyInto(out *CNI) { *out = *in + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(AddonStrategy) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CNI. @@ -490,6 +500,11 @@ func (in *CSIProvider) DeepCopyInto(out *CSIProvider) { (*out)[key] = *val.DeepCopy() } } + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(AddonStrategy) + **out = **in + } if in.Credentials != nil { in, out := &in.Credentials, &out.Credentials *out = new(CSICredentials) @@ -510,6 +525,11 @@ func (in *CSIProvider) DeepCopy() *CSIProvider { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterAutoscaler) DeepCopyInto(out *ClusterAutoscaler) { *out = *in + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(AddonStrategy) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterAutoscaler. @@ -842,17 +862,17 @@ func (in *GenericAddons) DeepCopyInto(out *GenericAddons) { if in.CNI != nil { in, out := &in.CNI, &out.CNI *out = new(CNI) - **out = **in + (*in).DeepCopyInto(*out) } if in.NFD != nil { in, out := &in.NFD, &out.NFD *out = new(NFD) - **out = **in + (*in).DeepCopyInto(*out) } if in.ClusterAutoscaler != nil { in, out := &in.ClusterAutoscaler, &out.ClusterAutoscaler *out = new(ClusterAutoscaler) - **out = **in + (*in).DeepCopyInto(*out) } if in.CCM != nil { in, out := &in.CCM, &out.CCM @@ -883,7 +903,7 @@ func (in *GenericCSI) DeepCopyInto(out *GenericCSI) { if in.SnapshotController != nil { in, out := &in.SnapshotController, &out.SnapshotController *out = new(SnapshotController) - **out = **in + (*in).DeepCopyInto(*out) } } @@ -1075,6 +1095,11 @@ func (in *LocalObjectReference) DeepCopy() *LocalObjectReference { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NFD) DeepCopyInto(out *NFD) { *out = *in + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(AddonStrategy) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NFD. @@ -1309,7 +1334,9 @@ func (in *NutanixNodeSpec) DeepCopy() *NutanixNodeSpec { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NutanixPrismCentralEndpointCredentials) DeepCopyInto(out *NutanixPrismCentralEndpointCredentials) { +func (in *NutanixPrismCentralEndpointCredentials) DeepCopyInto( + out *NutanixPrismCentralEndpointCredentials, +) { *out = *in out.SecretRef = in.SecretRef } @@ -1479,6 +1506,11 @@ func (in *ServiceLoadBalancerConfiguration) DeepCopy() *ServiceLoadBalancerConfi // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SnapshotController) DeepCopyInto(out *SnapshotController) { *out = *in + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(AddonStrategy) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SnapshotController. diff --git a/pkg/handlers/generic/lifecycle/ccm/aws/handler.go b/pkg/handlers/generic/lifecycle/ccm/aws/handler.go index a9143804f..57b0f971a 100644 --- a/pkg/handlers/generic/lifecycle/ccm/aws/handler.go +++ b/pkg/handlers/generic/lifecycle/ccm/aws/handler.go @@ -9,6 +9,7 @@ import ( "github.com/go-logr/logr" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -91,7 +92,7 @@ func (a *AWSCCM) Apply( } var strategy addons.Applier - switch clusterConfig.Addons.CCM.Strategy { + switch ptr.Deref(clusterConfig.Addons.CCM.Strategy, "") { case v1alpha1.AddonStrategyHelmAddon: helmChart, err := a.helmChartInfoGetter.For(ctx, log, config.AWSCCM) if err != nil { @@ -109,8 +110,10 @@ func (a *AWSCCM) Apply( }, client: a.client, } + case "": + return fmt.Errorf("strategy not specified for AWS CCM") default: - return fmt.Errorf("strategy %s not implemented", clusterConfig.Addons.CCM.Strategy) + return fmt.Errorf("strategy %s not implemented", *clusterConfig.Addons.CCM.Strategy) } if err := strategy.Apply(ctx, cluster, a.config.DefaultsNamespace(), log); err != nil { diff --git a/pkg/handlers/generic/lifecycle/clusterautoscaler/handler.go b/pkg/handlers/generic/lifecycle/clusterautoscaler/handler.go index b28037f03..0b4d2e9e7 100644 --- a/pkg/handlers/generic/lifecycle/clusterautoscaler/handler.go +++ b/pkg/handlers/generic/lifecycle/clusterautoscaler/handler.go @@ -9,6 +9,7 @@ import ( "github.com/go-logr/logr" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" @@ -111,7 +112,7 @@ func (n *DefaultClusterAutoscaler) apply( varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables) - cniVar, err := variables.Get[v1alpha1.ClusterAutoscaler]( + caVar, err := variables.Get[v1alpha1.ClusterAutoscaler]( varMap, n.variableName, n.variablePath...) @@ -136,7 +137,7 @@ func (n *DefaultClusterAutoscaler) apply( } var strategy addonStrategy - switch cniVar.Strategy { + switch ptr.Deref(caVar.Strategy, "") { case v1alpha1.AddonStrategyClusterResourceSet: strategy = crsStrategy{ config: n.config.crsConfig, @@ -166,10 +167,13 @@ func (n *DefaultClusterAutoscaler) apply( client: n.client, helmChart: helmChart, } + case "": + resp.SetStatus(runtimehooksv1.ResponseStatusFailure) + resp.SetMessage("strategy not specified for cluster-autoscaler addon") default: resp.SetStatus(runtimehooksv1.ResponseStatusFailure) resp.SetMessage( - fmt.Sprintf("unknown cluster-autoscaler addon deployment strategy %q", cniVar.Strategy), + fmt.Sprintf("unknown cluster-autoscaler addon deployment strategy %q", *caVar.Strategy), ) return } diff --git a/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go b/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go index 0c85597b5..e570cfd24 100644 --- a/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go +++ b/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go @@ -29,7 +29,7 @@ func TestVariableValidation_AWS(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: v1alpha1.AddonStrategyClusterResourceSet, + Strategy: ptr.To(v1alpha1.AddonStrategyClusterResourceSet), }, }, }, @@ -41,7 +41,7 @@ func TestVariableValidation_AWS(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), }, }, }, @@ -53,7 +53,7 @@ func TestVariableValidation_AWS(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: "invalid-strategy", + Strategy: ptr.To[v1alpha1.AddonStrategy]("invalid-strategy"), }, }, }, @@ -76,7 +76,7 @@ func TestVariableValidation_Nutanix(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: v1alpha1.AddonStrategyClusterResourceSet, + Strategy: ptr.To(v1alpha1.AddonStrategyClusterResourceSet), }, }, }, @@ -88,7 +88,7 @@ func TestVariableValidation_Nutanix(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), }, }, }, @@ -100,7 +100,7 @@ func TestVariableValidation_Nutanix(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: "invalid-strategy", + Strategy: ptr.To[v1alpha1.AddonStrategy]("invalid-strategy"), }, }, }, @@ -123,7 +123,7 @@ func TestVariableValidation_Docker(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: v1alpha1.AddonStrategyClusterResourceSet, + Strategy: ptr.To(v1alpha1.AddonStrategyClusterResourceSet), }, }, }, @@ -135,7 +135,7 @@ func TestVariableValidation_Docker(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), }, }, }, @@ -147,7 +147,7 @@ func TestVariableValidation_Docker(t *testing.T) { Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ - Strategy: "invalid-strategy", + Strategy: ptr.To[v1alpha1.AddonStrategy]("invalid-strategy"), }, }, }, diff --git a/pkg/handlers/generic/lifecycle/cni/calico/handler.go b/pkg/handlers/generic/lifecycle/cni/calico/handler.go index a8bb161f7..2ca181dce 100644 --- a/pkg/handlers/generic/lifecycle/cni/calico/handler.go +++ b/pkg/handlers/generic/lifecycle/cni/calico/handler.go @@ -9,6 +9,7 @@ import ( "github.com/go-logr/logr" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" @@ -144,7 +145,7 @@ func (c *CalicoCNI) apply( } var strategy addonStrategy - switch cniVar.Strategy { + switch ptr.Deref(cniVar.Strategy, "") { case v1alpha1.AddonStrategyClusterResourceSet: strategy = crsStrategy{ config: c.config.crsConfig, @@ -173,9 +174,12 @@ func (c *CalicoCNI) apply( client: c.client, helmChart: helmChart, } + case "": + resp.SetStatus(runtimehooksv1.ResponseStatusFailure) + resp.SetMessage("strategy not specified for CNI addon") default: resp.SetStatus(runtimehooksv1.ResponseStatusFailure) - resp.SetMessage(fmt.Sprintf("unknown CNI addon deployment strategy %q", cniVar.Strategy)) + resp.SetMessage(fmt.Sprintf("unknown CNI addon deployment strategy %q", *cniVar.Strategy)) return } diff --git a/pkg/handlers/generic/lifecycle/cni/cilium/handler.go b/pkg/handlers/generic/lifecycle/cni/cilium/handler.go index f8445a275..282f88bcd 100644 --- a/pkg/handlers/generic/lifecycle/cni/cilium/handler.go +++ b/pkg/handlers/generic/lifecycle/cni/cilium/handler.go @@ -9,6 +9,7 @@ import ( "github.com/go-logr/logr" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" @@ -143,7 +144,7 @@ func (c *CiliumCNI) apply( } var strategy addonStrategy - switch cniVar.Strategy { + switch ptr.Deref(cniVar.Strategy, "") { case v1alpha1.AddonStrategyClusterResourceSet: strategy = crsStrategy{ config: c.config.crsConfig, @@ -169,9 +170,12 @@ func (c *CiliumCNI) apply( client: c.client, helmChart: helmChart, } + case "": + resp.SetStatus(runtimehooksv1.ResponseStatusFailure) + resp.SetMessage("strategy not specified for Cilium CNI addon") default: resp.SetStatus(runtimehooksv1.ResponseStatusFailure) - resp.SetMessage(fmt.Sprintf("unknown CNI addon deployment strategy %q", cniVar.Strategy)) + resp.SetMessage(fmt.Sprintf("unknown CNI addon deployment strategy %q", *cniVar.Strategy)) return } diff --git a/pkg/handlers/generic/lifecycle/cni/variables_test.go b/pkg/handlers/generic/lifecycle/cni/variables_test.go index 028c7b78d..98d738896 100644 --- a/pkg/handlers/generic/lifecycle/cni/variables_test.go +++ b/pkg/handlers/generic/lifecycle/cni/variables_test.go @@ -23,7 +23,7 @@ var testDefs = []capitest.VariableTestDef{{ GenericAddons: v1alpha1.GenericAddons{ CNI: &v1alpha1.CNI{ Provider: v1alpha1.CNIProviderCalico, - Strategy: v1alpha1.AddonStrategyClusterResourceSet, + Strategy: ptr.To(v1alpha1.AddonStrategyClusterResourceSet), }, }, }, @@ -35,7 +35,7 @@ var testDefs = []capitest.VariableTestDef{{ GenericAddons: v1alpha1.GenericAddons{ CNI: &v1alpha1.CNI{ Provider: v1alpha1.CNIProviderCalico, - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), }, }, }, @@ -47,7 +47,7 @@ var testDefs = []capitest.VariableTestDef{{ GenericAddons: v1alpha1.GenericAddons{ CNI: &v1alpha1.CNI{ Provider: "invalid-provider", - Strategy: v1alpha1.AddonStrategyClusterResourceSet, + Strategy: ptr.To(v1alpha1.AddonStrategyClusterResourceSet), }, }, }, @@ -60,7 +60,7 @@ var testDefs = []capitest.VariableTestDef{{ GenericAddons: v1alpha1.GenericAddons{ CNI: &v1alpha1.CNI{ Provider: v1alpha1.CNIProviderCalico, - Strategy: "invalid-strategy", + Strategy: ptr.To[v1alpha1.AddonStrategy]("invalid-strategy"), }, }, }, diff --git a/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go b/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go index 5fd34c2f6..8cce4d5c0 100644 --- a/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/awsebs/handler.go @@ -9,6 +9,7 @@ import ( "github.com/go-logr/logr" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -78,7 +79,7 @@ func (a *AWSEBS) Apply( log logr.Logger, ) error { var strategy addons.Applier - switch provider.Strategy { + switch ptr.Deref(provider.Strategy, "") { case v1alpha1.AddonStrategyHelmAddon: helmChart, err := a.helmChartInfoGetter.For(ctx, log, config.AWSEBSCSI) if err != nil { @@ -94,8 +95,10 @@ func (a *AWSEBS) Apply( config: a.config.crsConfig, client: a.client, } + case "": + return fmt.Errorf("strategy not specified for AWS EBS CSI driver") default: - return fmt.Errorf("strategy %s not implemented", provider.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 db993ab66..5cd4b88f6 100644 --- a/pkg/handlers/generic/lifecycle/csi/localpath/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/localpath/handler.go @@ -9,6 +9,7 @@ import ( "github.com/go-logr/logr" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -74,7 +75,7 @@ func (l *LocalPathProvisionerCSI) Apply( log logr.Logger, ) error { var strategy addons.Applier - switch provider.Strategy { + switch ptr.Deref(provider.Strategy, "") { case v1alpha1.AddonStrategyHelmAddon: helmChart, err := l.helmChartInfoGetter.For(ctx, log, config.LocalPathProvisionerCSI) if err != nil { @@ -90,8 +91,10 @@ func (l *LocalPathProvisionerCSI) Apply( config: l.config.crsConfig, client: l.client, } + case "": + return fmt.Errorf("strategy not provided for local-path CSI addon") default: - return fmt.Errorf("strategy %s not implemented", provider.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/handler.go b/pkg/handlers/generic/lifecycle/csi/nutanix/handler.go index ee70efd56..571bafd68 100644 --- a/pkg/handlers/generic/lifecycle/csi/nutanix/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/nutanix/handler.go @@ -9,6 +9,7 @@ import ( "github.com/go-logr/logr" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -86,7 +87,7 @@ func (n *NutanixCSI) Apply( log logr.Logger, ) error { var strategy addons.Applier - switch provider.Strategy { + switch ptr.Deref(provider.Strategy, "") { case v1alpha1.AddonStrategyHelmAddon: helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.NutanixStorageCSI) if err != nil { @@ -100,8 +101,10 @@ func (n *NutanixCSI) Apply( n.client, helmChart, ) + case "": + return fmt.Errorf("strategy not provided for Nutanix CSI driver") default: - return fmt.Errorf("strategy %s not implemented", provider.Strategy) + return fmt.Errorf("strategy %s not implemented", *provider.Strategy) } if provider.Credentials != nil { diff --git a/pkg/handlers/generic/lifecycle/csi/snapshotcontroller/handler.go b/pkg/handlers/generic/lifecycle/csi/snapshotcontroller/handler.go index 224e6c19a..53c8e543e 100644 --- a/pkg/handlers/generic/lifecycle/csi/snapshotcontroller/handler.go +++ b/pkg/handlers/generic/lifecycle/csi/snapshotcontroller/handler.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" @@ -136,7 +137,7 @@ func (s *SnapshotControllerHandler) apply( } var strategy addons.Applier - switch snapshotControllerVar.Strategy { + switch ptr.Deref(snapshotControllerVar.Strategy, "") { case v1alpha1.AddonStrategyHelmAddon: helmChart, err := s.helmChartInfoGetter.For(ctx, log, config.SnapshotController) if err != nil { @@ -156,12 +157,15 @@ func (s *SnapshotControllerHandler) apply( config: s.config.crsConfig, client: s.client, } + case "": + resp.SetStatus(runtimehooksv1.ResponseStatusFailure) + resp.SetMessage("strategy not provided for snapshot-controller") default: resp.SetStatus(runtimehooksv1.ResponseStatusFailure) resp.SetMessage( fmt.Sprintf( "unknown snapshot-controller addon deployment strategy %q", - snapshotControllerVar.Strategy, + *snapshotControllerVar.Strategy, ), ) } diff --git a/pkg/handlers/generic/lifecycle/csi/variables_test.go b/pkg/handlers/generic/lifecycle/csi/variables_test.go index 6345a7e77..8f17aceb3 100644 --- a/pkg/handlers/generic/lifecycle/csi/variables_test.go +++ b/pkg/handlers/generic/lifecycle/csi/variables_test.go @@ -36,7 +36,7 @@ func TestVariableValidation_AWSCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderAWSEBS: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -59,7 +59,7 @@ func TestVariableValidation_AWSCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderNutanix: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -83,7 +83,7 @@ func TestVariableValidation_AWSCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderLocalPath: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -107,7 +107,7 @@ func TestVariableValidation_AWSCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ "unknown": { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -141,7 +141,7 @@ func TestVariableValidation_NutanixCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderNutanix: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -164,7 +164,7 @@ func TestVariableValidation_NutanixCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderAWSEBS: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -188,7 +188,7 @@ func TestVariableValidation_NutanixCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderLocalPath: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -212,7 +212,7 @@ func TestVariableValidation_NutanixCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ "unknown": { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -246,7 +246,7 @@ func TestVariableValidation_DockerCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderLocalPath: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -269,7 +269,7 @@ func TestVariableValidation_DockerCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderAWSEBS: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -293,7 +293,7 @@ func TestVariableValidation_DockerCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ v1alpha1.CSIProviderNutanix: { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, @@ -317,7 +317,7 @@ func TestVariableValidation_DockerCSI(t *testing.T) { }, Providers: map[string]v1alpha1.CSIProvider{ "unknown": { - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), StorageClassConfigs: map[string]v1alpha1.StorageClassConfig{ "test-1": {}, }, diff --git a/pkg/handlers/generic/lifecycle/nfd/handler.go b/pkg/handlers/generic/lifecycle/nfd/handler.go index 328d0a3bd..f63ca1546 100644 --- a/pkg/handlers/generic/lifecycle/nfd/handler.go +++ b/pkg/handlers/generic/lifecycle/nfd/handler.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/spf13/pflag" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" @@ -140,7 +141,7 @@ func (n *DefaultNFD) apply( } var strategy addons.Applier - switch cniVar.Strategy { + switch ptr.Deref(cniVar.Strategy, "") { case v1alpha1.AddonStrategyClusterResourceSet: strategy = crsStrategy{ config: n.config.crsConfig, @@ -166,9 +167,12 @@ func (n *DefaultNFD) apply( n.client, helmChart, ) + case "": + resp.SetStatus(runtimehooksv1.ResponseStatusFailure) + resp.SetMessage("strategy not provided for NFD") default: resp.SetStatus(runtimehooksv1.ResponseStatusFailure) - resp.SetMessage(fmt.Sprintf("unknown NFD addon deployment strategy %q", cniVar.Strategy)) + resp.SetMessage(fmt.Sprintf("unknown NFD addon deployment strategy %q", *cniVar.Strategy)) return } diff --git a/pkg/handlers/generic/lifecycle/nfd/variables_test.go b/pkg/handlers/generic/lifecycle/nfd/variables_test.go index 71291e85e..84b0048db 100644 --- a/pkg/handlers/generic/lifecycle/nfd/variables_test.go +++ b/pkg/handlers/generic/lifecycle/nfd/variables_test.go @@ -22,7 +22,7 @@ var testDefs = []capitest.VariableTestDef{{ Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ NFD: &v1alpha1.NFD{ - Strategy: v1alpha1.AddonStrategyClusterResourceSet, + Strategy: ptr.To(v1alpha1.AddonStrategyClusterResourceSet), }, }, }, @@ -33,7 +33,7 @@ var testDefs = []capitest.VariableTestDef{{ Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ NFD: &v1alpha1.NFD{ - Strategy: v1alpha1.AddonStrategyHelmAddon, + Strategy: ptr.To(v1alpha1.AddonStrategyHelmAddon), }, }, }, @@ -44,7 +44,7 @@ var testDefs = []capitest.VariableTestDef{{ Addons: &apivariables.Addons{ GenericAddons: v1alpha1.GenericAddons{ NFD: &v1alpha1.NFD{ - Strategy: "invalid-strategy", + Strategy: ptr.To[v1alpha1.AddonStrategy]("invalid-strategy"), }, }, }, diff --git a/test/e2e/ccm_helpers.go b/test/e2e/ccm_helpers.go index 24798ac94..f28487914 100644 --- a/test/e2e/ccm_helpers.go +++ b/test/e2e/ccm_helpers.go @@ -14,6 +14,7 @@ import ( appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" @@ -73,7 +74,7 @@ func WaitForAWSCCMToBeReadyInWorkloadCluster( workloadClusterClient client.Client, input WaitForCCMToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. ) { - switch input.CCM.Strategy { + switch ptr.Deref(input.CCM.Strategy, "") { case v1alpha1.AddonStrategyClusterResourceSet: crs := &addonsv1.ClusterResourceSet{} Expect(input.ClusterProxy.GetClient().Get( @@ -104,11 +105,13 @@ func WaitForAWSCCMToBeReadyInWorkloadCluster( }, input.HelmReleaseIntervals..., ) + case "": + Fail("Strategy not provided for AWS CCM") default: Fail( fmt.Sprintf( "Do not know how to wait for AWS CCM using strategy %s to be ready", - input.CCM.Strategy, + *input.CCM.Strategy, ), ) } @@ -129,7 +132,7 @@ func WaitForNutanixCCMToBeReadyInWorkloadCluster( workloadClusterClient client.Client, input WaitForCCMToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. ) { - switch input.CCM.Strategy { + switch ptr.Deref(input.CCM.Strategy, "") { case v1alpha1.AddonStrategyHelmAddon: WaitForHelmReleaseProxyReadyForCluster( ctx, @@ -140,11 +143,13 @@ func WaitForNutanixCCMToBeReadyInWorkloadCluster( }, input.HelmReleaseIntervals..., ) + case "": + Fail("Strategy not provided for Nutanix CCM") default: Fail( fmt.Sprintf( "Do not know how to wait for Nutanix CCM using strategy %s to be ready", - input.CCM.Strategy, + *input.CCM.Strategy, ), ) } diff --git a/test/e2e/clusterautoscaler_helpers.go b/test/e2e/clusterautoscaler_helpers.go index a2c881782..22280e817 100644 --- a/test/e2e/clusterautoscaler_helpers.go +++ b/test/e2e/clusterautoscaler_helpers.go @@ -14,6 +14,7 @@ import ( appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" @@ -53,7 +54,7 @@ func WaitForClusterAutoscalerToBeReadyInWorkloadCluster( return } - switch input.ClusterAutoscaler.Strategy { + switch ptr.Deref(input.ClusterAutoscaler.Strategy, "") { case v1alpha1.AddonStrategyClusterResourceSet: crs := &addonsv1.ClusterResourceSet{} Expect(input.ClusterProxy.GetClient().Get( @@ -84,11 +85,13 @@ func WaitForClusterAutoscalerToBeReadyInWorkloadCluster( }, input.HelmReleaseIntervals..., ) + case "": + Fail("Strategy not provided for cluster autoscaler") default: Fail( fmt.Sprintf( "Do not know how to wait for cluster autoscaler using strategy %s to be ready", - input.ClusterAutoscaler.Strategy, + *input.ClusterAutoscaler.Strategy, ), ) } diff --git a/test/e2e/cni_helpers.go b/test/e2e/cni_helpers.go index 6e9f27d0b..bc02c78e5 100644 --- a/test/e2e/cni_helpers.go +++ b/test/e2e/cni_helpers.go @@ -14,6 +14,7 @@ import ( appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" @@ -44,7 +45,7 @@ func WaitForCNIToBeReadyInWorkloadCluster( waitForCalicoToBeReadyInWorkloadCluster( ctx, waitForCalicoToBeReadyInWorkloadClusterInput{ - strategy: input.CNI.Strategy, + strategy: ptr.Deref(input.CNI.Strategy, ""), workloadCluster: input.WorkloadCluster, clusterProxy: input.ClusterProxy, deploymentIntervals: input.DeploymentIntervals, @@ -57,7 +58,7 @@ func WaitForCNIToBeReadyInWorkloadCluster( waitForCiliumToBeReadyInWorkloadCluster( ctx, waitForCiliumToBeReadyInWorkloadClusterInput{ - strategy: input.CNI.Strategy, + strategy: ptr.Deref(input.CNI.Strategy, ""), workloadCluster: input.WorkloadCluster, clusterProxy: input.ClusterProxy, deploymentIntervals: input.DeploymentIntervals, diff --git a/test/e2e/csi_helpers.go b/test/e2e/csi_helpers.go index b66ed5f9f..0e81462e9 100644 --- a/test/e2e/csi_helpers.go +++ b/test/e2e/csi_helpers.go @@ -18,6 +18,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" capie2e "sigs.k8s.io/cluster-api/test/e2e" @@ -56,7 +57,7 @@ func WaitForCSIToBeReadyInWorkloadCluster( waitForLocalPathCSIToBeReadyInWorkloadCluster( ctx, waitForLocalPathCSIToBeReadyInWorkloadClusterInput{ - strategy: providerConfig.Strategy, + strategy: ptr.Deref(providerConfig.Strategy, ""), workloadCluster: input.WorkloadCluster, clusterProxy: input.ClusterProxy, deploymentIntervals: input.DeploymentIntervals, @@ -69,7 +70,7 @@ func WaitForCSIToBeReadyInWorkloadCluster( waitForAWSEBSCSIToBeReadyInWorkloadCluster( ctx, waitForAWSEBSCSIToBeReadyInWorkloadClusterInput{ - strategy: providerConfig.Strategy, + strategy: ptr.Deref(providerConfig.Strategy, ""), workloadCluster: input.WorkloadCluster, clusterProxy: input.ClusterProxy, deploymentIntervals: input.DeploymentIntervals, @@ -83,7 +84,7 @@ func WaitForCSIToBeReadyInWorkloadCluster( waitForNutanixCSIToBeReadyInWorkloadCluster( ctx, waitForNutanixCSIToBeReadyInWorkloadClusterInput{ - strategy: providerConfig.Strategy, + strategy: ptr.Deref(providerConfig.Strategy, ""), workloadCluster: input.WorkloadCluster, clusterProxy: input.ClusterProxy, deploymentIntervals: input.DeploymentIntervals, @@ -118,7 +119,7 @@ func WaitForCSIToBeReadyInWorkloadCluster( waitForSnapshotControllerToBeReadyInWorkloadCluster( ctx, waitForSnapshotControllerToBeReadyInWorkloadClusterInput{ - strategy: input.CSI.SnapshotController.Strategy, + strategy: ptr.Deref(input.CSI.SnapshotController.Strategy, ""), workloadCluster: input.WorkloadCluster, clusterProxy: input.ClusterProxy, deploymentIntervals: input.DeploymentIntervals, diff --git a/test/e2e/nfd_helpers.go b/test/e2e/nfd_helpers.go index 645483270..d0d8fb2a5 100644 --- a/test/e2e/nfd_helpers.go +++ b/test/e2e/nfd_helpers.go @@ -14,6 +14,7 @@ import ( appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" @@ -39,7 +40,7 @@ func WaitForNFDToBeReadyInWorkloadCluster( return } - switch input.NFD.Strategy { + switch ptr.Deref(input.NFD.Strategy, "") { case v1alpha1.AddonStrategyClusterResourceSet: crs := &addonsv1.ClusterResourceSet{} Expect(input.ClusterProxy.GetClient().Get( @@ -70,11 +71,13 @@ func WaitForNFDToBeReadyInWorkloadCluster( }, input.HelmReleaseIntervals..., ) + case "": + Fail("NFD strategy is not set") default: Fail( fmt.Sprintf( "Do not know how to wait for NFD using strategy %s to be ready", - input.NFD.Strategy, + *input.NFD.Strategy, ), ) }