Skip to content

Commit 9083648

Browse files
committed
Add syncWithACS to control creation of external managed cluster on ACS
1 parent b7feb18 commit 9083648

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

api/v1beta1/conversion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Convert_v1beta1_CloudStackCluster_To_v1beta3_CloudStackCluster(in *CloudSta
5151
//nolint:golint,revive,stylecheck
5252
func Convert_v1beta3_CloudStackCluster_To_v1beta1_CloudStackCluster(in *v1beta3.CloudStackCluster, out *CloudStackCluster, scope conv.Scope) error {
5353
if len(in.Spec.FailureDomains) < 1 {
54-
return fmt.Errorf("v1beta3 to v1beta1 conversion not supported when < 1 failure domain is provided. Input CloudStackCluster spec %s", in.Spec)
54+
return fmt.Errorf("v1beta3 to v1beta1 conversion not supported when < 1 failure domain is provided. Input CloudStackCluster spec %s", fmt.Sprintf("%v", in.Spec))
5555
}
5656
out.ObjectMeta = in.ObjectMeta
5757
out.Spec = CloudStackClusterSpec{

api/v1beta3/cloudstackcluster_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type CloudStackClusterSpec struct {
3434

3535
// The kubernetes control plane endpoint.
3636
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
37+
38+
// SyncWithACS determines if an externalManaged CKS cluster should be created on ACS.
39+
// +optional
40+
SyncWithACS bool `json:"syncWithACS"`
3741
}
3842

3943
// The status of the CloudStackCluster object.

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackclusters.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ spec:
415415
- zone
416416
type: object
417417
type: array
418+
syncWithACS:
419+
description: SyncWithACS determines if an externalManaged CKS cluster
420+
should be created on ACS.
421+
type: boolean
418422
required:
419423
- controlPlaneEndpoint
420424
- failureDomains

controllers/cloudstackcluster_controller.go

+14-11
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,21 @@ func (r *CloudStackClusterReconciliationRunner) Reconcile() (res ctrl.Result, re
101101

102102
// GetOrCreateUnmanagedCluster checks if an unmanaged cluster is present in Cloudstack else creates one.
103103
func (r *CloudStackClusterReconciliationRunner) GetOrCreateUnmanagedCluster() (ctrl.Result, error) {
104-
res, err := r.AsFailureDomainUser(&r.CSCluster.Spec.FailureDomains[0])()
105-
if r.ShouldReturn(res, err) {
106-
return res, err
107-
}
108-
err = r.CSUser.GetOrCreateUnmanagedCluster(r.CAPICluster, r.ReconciliationSubject, &r.FailureDomains.Items[0].Spec)
109-
if err != nil {
110-
if strings.Contains(err.Error(), "Kubernetes Service plugin is disabled") {
111-
r.Log.Info("Kubernetes Service plugin is disabled on CloudStack. Skipping ExternalManaged kubernetes cluster creation")
112-
return ctrl.Result{}, nil
104+
if r.CSCluster.Spec.SyncWithACS {
105+
res, err := r.AsFailureDomainUser(&r.CSCluster.Spec.FailureDomains[0])()
106+
if r.ShouldReturn(res, err) {
107+
return res, err
108+
}
109+
110+
err = r.CSUser.GetOrCreateUnmanagedCluster(r.CAPICluster, r.ReconciliationSubject, &r.FailureDomains.Items[0].Spec)
111+
if err != nil {
112+
if strings.Contains(err.Error(), "Kubernetes Service plugin is disabled") {
113+
r.Log.Info("Kubernetes Service plugin is disabled on CloudStack. Skipping ExternalManaged kubernetes cluster creation")
114+
return ctrl.Result{}, nil
115+
}
116+
// Not requeueing the failure to support CloudStack v4.18 and before
117+
r.Log.Info(fmt.Sprintf("Failed creating ExternalManaged kubernetes cluster on CloudStack. Error: %s", err.Error()))
113118
}
114-
// Not requeueing the failure to support CloudStack v4.18 and before
115-
r.Log.Info(fmt.Sprintf("Failed creating ExternalManaged kubernetes cluster on CloudStack. Error: %s", err.Error()))
116119
}
117120
return ctrl.Result{}, nil
118121
}

pkg/cloud/cluster.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func (c *client) GetOrCreateUnmanagedCluster(cluster *clusterv1.Cluster, csClust
8585
}
8686
accountName = user.Account
8787
}
88-
params := c.cs.Kubernetes.NewCreateKubernetesClusterParams(fmt.Sprintf("%s managed by CAPC", clusterName), clusterName, fd.Zone.ID)
88+
// NewCreateKubernetesClusterParams(description string, kubernetesversionid string, name string, serviceofferingid string, size int64, zoneid string) *CreateKubernetesClusterParams
89+
params := c.cs.Kubernetes.NewCreateKubernetesClusterParams(fmt.Sprintf("%s managed by CAPC", clusterName), "", clusterName, "", 0, fd.Zone.ID)
8990

9091
setIfNotEmpty(accountName, params.SetAccount)
9192
setIfNotEmpty(domain.ID, params.SetDomainid)

0 commit comments

Comments
 (0)