Skip to content

Commit 35bbcdc

Browse files
committed
Add syncWithACS to control creation of external managed cluster on ACS
1 parent 7ce6f8a commit 35bbcdc

File tree

8 files changed

+44
-111
lines changed

8 files changed

+44
-111
lines changed

api/v1beta3/cloudstackcluster_types.go

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

3535
// The kubernetes control plane endpoint.
3636
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
37+
38+
SyncWithACS bool `json:"syncWithACS,omitempty"`
3739
}
3840

3941
// The status of the CloudStackCluster object.

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

+2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ spec:
412412
- zone
413413
type: object
414414
type: array
415+
syncWithACS:
416+
type: boolean
415417
required:
416418
- controlPlaneEndpoint
417419
- failureDomains

controllers/cloudstackcluster_controller.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,18 @@ func (r *CloudStackClusterReconciliationRunner) GetOrCreateUnmanagedCluster() (c
105105
if r.ShouldReturn(res, err) {
106106
return res, err
107107
}
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
108+
109+
if r.CSCluster.Spec.SyncWithACS {
110+
111+
err = r.CSUser.GetOrCreateUnmanagedCluster(r.CAPICluster, r.ReconciliationSubject, &r.FailureDomains.Items[0].Spec)
112+
if err != nil {
113+
if strings.Contains(err.Error(), "Kubernetes Service plugin is disabled") {
114+
r.Log.Info("Kubernetes Service plugin is disabled on CloudStack. Skipping ExternalManaged kubernetes cluster creation")
115+
return ctrl.Result{}, nil
116+
}
117+
// Not requeueing the failure to support CloudStack v4.18 and before
118+
r.Log.Info(fmt.Sprintf("Failed creating ExternalManaged kubernetes cluster on CloudStack. Error: %s", err.Error()))
113119
}
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()))
116120
}
117121
return ctrl.Result{}, nil
118122
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/ReneKroon/ttlcache v1.7.0
7-
github.com/apache/cloudstack-go/v2 v2.15.0
7+
github.com/apache/cloudstack-go/v2 v2.16.0
88
github.com/go-logr/logr v1.2.4
99
github.com/golang/mock v1.6.0
1010
github.com/hashicorp/go-multierror v1.1.1

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
2626
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 h1:yL7+Jz0jTC6yykIK/Wh74gnTJnrGr5AyrNMXuA0gves=
2727
github.com/apache/cloudstack-go/v2 v2.15.0 h1:oojn1qx0+wBwrFSSmA2rL8XjWd4BXqwYo0RVCrAXoHk=
2828
github.com/apache/cloudstack-go/v2 v2.15.0/go.mod h1:Mc+tXpujtslBuZFk5atoGT2LanVxOrXS2GGgidAoz1A=
29+
github.com/apache/cloudstack-go/v2 v2.16.0 h1:qK4/mtgmhzFU99WHAHM/1FhAM3cWV8gplOAGODwHyPM=
30+
github.com/apache/cloudstack-go/v2 v2.16.0/go.mod h1:EPMwvwKMvmIFajmDCqSR747l/439DuKvKY8jbFOE/qE=
2931
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
3032
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
3133
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

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)

test/e2e/go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ go 1.19
44

55
require (
66
github.com/Shopify/toxiproxy/v2 v2.5.0
7-
github.com/apache/cloudstack-go/v2 v2.15.0
7+
github.com/apache/cloudstack-go/v2 v2.16.0
88
github.com/blang/semver v3.5.1+incompatible
9+
github.com/onsi/ginkgo v1.16.5
910
github.com/onsi/ginkgo/v2 v2.11.0
1011
github.com/onsi/gomega v1.27.8
1112
gopkg.in/yaml.v3 v3.0.1
@@ -79,6 +80,7 @@ require (
7980
github.com/modern-go/reflect2 v1.0.2 // indirect
8081
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
8182
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
83+
github.com/nxadm/tail v1.4.8 // indirect
8284
github.com/opencontainers/go-digest v1.0.0 // indirect
8385
github.com/opencontainers/image-spec v1.0.2 // indirect
8486
github.com/pelletier/go-toml v1.9.5 // indirect
@@ -112,6 +114,7 @@ require (
112114
google.golang.org/protobuf v1.30.0 // indirect
113115
gopkg.in/inf.v0 v0.9.1 // indirect
114116
gopkg.in/ini.v1 v1.67.0 // indirect
117+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
115118
gopkg.in/yaml.v2 v2.4.0 // indirect
116119
k8s.io/apiextensions-apiserver v0.26.1 // indirect
117120
k8s.io/apiserver v0.26.1 // indirect

0 commit comments

Comments
 (0)