Skip to content

fix: add omitempty to addon strategy #795

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

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -109,22 +109,22 @@ 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.
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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 0 additions & 10 deletions api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -86,8 +84,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
cni:
description: CNI required for providing CNI configuration.
Expand All @@ -107,7 +103,6 @@ spec:
type: string
required:
- provider
- strategy
type: object
csi:
properties:
Expand Down Expand Up @@ -187,7 +182,6 @@ spec:
type: string
required:
- storageClassConfigs
- strategy
type: object
required:
- aws-ebs
Expand All @@ -202,8 +196,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
required:
- defaultStorage
Expand All @@ -219,8 +211,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
serviceLoadBalancer:
properties:
Expand Down
10 changes: 0 additions & 10 deletions api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -86,8 +84,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
cni:
description: CNI required for providing CNI configuration.
Expand All @@ -107,7 +103,6 @@ spec:
type: string
required:
- provider
- strategy
type: object
csi:
properties:
Expand Down Expand Up @@ -187,7 +182,6 @@ spec:
type: string
required:
- storageClassConfigs
- strategy
type: object
required:
- local-path
Expand All @@ -202,8 +196,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
required:
- defaultStorage
Expand All @@ -219,8 +211,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
serviceLoadBalancer:
properties:
Expand Down
10 changes: 0 additions & 10 deletions api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -86,8 +84,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
cni:
description: CNI required for providing CNI configuration.
Expand All @@ -107,7 +103,6 @@ spec:
type: string
required:
- provider
- strategy
type: object
csi:
properties:
Expand Down Expand Up @@ -187,7 +182,6 @@ spec:
type: string
required:
- storageClassConfigs
- strategy
type: object
required:
- nutanix
Expand All @@ -202,8 +196,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
required:
- defaultStorage
Expand All @@ -219,8 +211,6 @@ spec:
- ClusterResourceSet
- HelmAddon
type: string
required:
- strategy
type: object
serviceLoadBalancer:
properties:
Expand Down
42 changes: 37 additions & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pkg/handlers/generic/lifecycle/ccm/aws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Loading
Loading