Skip to content

Commit

Permalink
refactor: Clean up API constants, and explain usage (#588)
Browse files Browse the repository at this point in the history
**What problem does this PR solve?**:
We have not explained how we use API constants. We also have good
reasons to remove some constants. This PR does the former, and gets us
closer to the latter.

**Which issue(s) this PR fixes**:
Fixes #

**How Has This Been Tested?**:
<!--
Please describe the tests that you ran to verify your changes.
Provide output from the tests and any manual steps needed to replicate
the tests.
-->

**Special notes for your reviewer**:
<!--
Use this to provide any additional information to the reviewers.
This may include:
- Best way to review the PR.
- Where the author wants the most review attention on.
- etc.
-->
  • Loading branch information
dlipovetsky committed Apr 30, 2024
1 parent 1042107 commit 4e8ab02
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
43 changes: 39 additions & 4 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,52 @@ package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"

nutanixv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
)

// All kubebuilder "Enum" build tag values are available in the OpenAPI spec.
// So that all these values are available to users of the api package, we
// we define a constant for each of the values.
//
// TODO: Generate these constants from the kubebuilder build tags, if possible.
const (
AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
AddonStrategyHelmAddon AddonStrategy = "HelmAddon"
VolumeBindingImmediate = storagev1.VolumeBindingImmediate
VolumeBindingWaitForFirstConsumer = storagev1.VolumeBindingWaitForFirstConsumer
CNIProviderCalico = "Calico"
CNIProviderCilium = "Cilium"

CSIProviderAWSEBS = "aws-ebs"
CSIProviderNutanix = "nutanix"

VirtualIPProviderKubeVIP = "KubeVIP"

AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
AddonStrategyHelmAddon AddonStrategy = "HelmAddon"

VolumeBindingImmediate = storagev1.VolumeBindingImmediate
VolumeBindingWaitForFirstConsumer = storagev1.VolumeBindingWaitForFirstConsumer

VolumeReclaimRecycle = corev1.PersistentVolumeReclaimRecycle
VolumeReclaimDelete = corev1.PersistentVolumeReclaimDelete
VolumeReclaimRetain = corev1.PersistentVolumeReclaimRetain

NutanixBootTypeLegacy = nutanixv1.NutanixBootTypeLegacy
NutanixBootTypeUEFI = nutanixv1.NutanixBootTypeUEFI
)

// FIXME: Remove StorageProvisioner from the API. Users do not provide this
// value; we derive it from the CSI provider.
type StorageProvisioner string

const (
AWSEBSProvisioner StorageProvisioner = "ebs.csi.aws.com"
NutanixProvisioner StorageProvisioner = "csi.nutanix.com"
)

// FIXME: Remove the CCM providers from the API. Users do not provider this
// value; we derive it from the cluster infrastructure.
const (
CCMProviderAWS = "aws"
CCMProviderNutanix = "nutanix"
)

type Addons struct {
Expand Down
15 changes: 0 additions & 15 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
)

type StorageProvisioner string

const (
CNIProviderCalico = "Calico"
CNIProviderCilium = "Cilium"
AWSEBSProvisioner StorageProvisioner = "ebs.csi.aws.com"
NutanixProvisioner StorageProvisioner = "csi.nutanix.com"

CSIProviderAWSEBS = "aws-ebs"
CSIProviderNutanix = "nutanix"

CCMProviderAWS = "aws"
CCMProviderNutanix = "nutanix"
)

var (
DefaultDockerCertSANs = []string{
"localhost",
Expand Down
6 changes: 0 additions & 6 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

package v1alpha1

const (
APIServerPort = 6443

VirtualIPProviderKubeVIP = "KubeVIP"
)

// ObjectMeta is metadata that all persisted resources must have, which includes all objects
// users must create. This is a copy of customizable fields from metav1.ObjectMeta.
//
Expand Down
1 change: 1 addition & 0 deletions pkg/handlers/generic/lifecycle/ccm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (c *CCMHandler) AfterControlPlaneInitialized(
return
}

// There's a 1:1 mapping of infra to CCM provider. We derive the CCM provider from the infra.
infraKind := req.Cluster.Spec.InfrastructureRef.Kind
log.Info(fmt.Sprintf("finding CCM handler for %s", infraKind))
var handler CCMProvider
Expand Down
1 change: 1 addition & 0 deletions pkg/handlers/generic/lifecycle/csi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (c *CSIHandler) AfterControlPlaneInitialized(
}
}

// There's a 1:N mapping of infra to CSI providers. The user chooses the provider.
for _, provider := range csiProviders.Providers {
handler, ok := c.ProviderHandler[provider.Name]
if !ok {
Expand Down

0 comments on commit 4e8ab02

Please sign in to comment.