Skip to content

Commit a672b8f

Browse files
committed
refactor: various cleanups from code review
1 parent d454b72 commit a672b8f

File tree

2 files changed

+10
-10
lines changed
  • common/pkg/capi/utils
  • pkg/handlers/generic/mutation/extraapiservercertsans

2 files changed

+10
-10
lines changed

common/pkg/capi/utils/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ func ManagementCluster(ctx context.Context, c client.Client) (*clusterv1.Cluster
4545

4646
return cluster, nil
4747
}
48+
49+
func GetProvider(cluster *clusterv1.Cluster) string {
50+
if cluster == nil {
51+
return ""
52+
}
53+
return cluster.GetLabels()[clusterv1.ProviderNameLabel]
54+
}

pkg/handlers/generic/mutation/extraapiservercertsans/inject.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1010
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
11-
"k8s.io/apimachinery/pkg/runtime"
1211
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1312
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
1413
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
@@ -21,6 +20,7 @@ import (
2120
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
2221
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
2322
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
23+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/utils"
2424
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
2525
)
2626

@@ -35,10 +35,6 @@ type extraAPIServerCertSANsPatchHandler struct {
3535
}
3636

3737
func NewPatch() *extraAPIServerCertSANsPatchHandler {
38-
scheme := runtime.NewScheme()
39-
_ = clusterv1.AddToScheme(scheme)
40-
_ = bootstrapv1.AddToScheme(scheme)
41-
_ = controlplanev1.AddToScheme(scheme)
4238
return newExtraAPIServerCertSANsPatchHandler(clusterconfig.MetaVariableName, VariableName)
4339
}
4440

@@ -118,13 +114,10 @@ func (h *extraAPIServerCertSANsPatchHandler) Mutate(
118114
}
119115

120116
func getDefaultAPIServerSANs(cluster *clusterv1.Cluster) []string {
121-
if cluster == nil {
122-
return nil
123-
}
124-
switch cluster.GetLabels()[clusterv1.ProviderNameLabel] {
117+
switch utils.GetProvider(cluster) {
125118
case "docker":
126119
return v1alpha1.DefaultDockerCertSANs
127120
default:
128-
return []string{}
121+
return nil
129122
}
130123
}

0 commit comments

Comments
 (0)