Skip to content

Commit 08a0291

Browse files
authored
Merge pull request #120 from rejoshed/feature/multi-endpoint-failure-domains
Add failure domain CRD and Support Multi-Endpoint Deployments
2 parents 99cda28 + 554137b commit 08a0291

File tree

177 files changed

+10433
-1229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+10433
-1229
lines changed

Makefile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ generate-deepcopy: $(DEEPCOPY_GEN_TARGETS) ## Generate code containing DeepCopy,
8181
api/%/zz_generated.deepcopy.go: bin/controller-gen $(DEEPCOPY_GEN_INPUTS)
8282
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
8383

84+
CONVERSION_GEN_TARGET=$(shell find api -type d -name "v*1" -exec echo {}\/zz_generated.conversion.go \;)
85+
CONVERSION_GEN_INPUTS=$(shell find ./api -name "*test*" -prune -o -name "*zz_generated*" -prune -o -type f -print)
86+
.PHONY: generate-conversion
87+
generate-conversion: $(CONVERSION_GEN_TARGET) ## Generate code to convert api/v1beta1 to api/v1beta2
88+
api/%/zz_generated.conversion.go: bin/conversion-gen $(CONVERSION_GEN_INPUTS)
89+
conversion-gen --go-header-file "./hack/boilerplate.go.txt" --input-dirs "./api/v1beta1" \
90+
--output-base "." --output-file-base="zz_generated.conversion" --skip-unsafe=true
91+
8492
##@ Build
8593

8694
MANAGER_BIN_INPUTS=$(shell find ./controllers ./api ./pkg -name "*mock*" -prune -o -name "*test*" -prune -o -type f -print) main.go go.mod go.sum
@@ -97,13 +105,13 @@ bin/manager-linux-amd64: $(MANAGER_BIN_INPUTS)
97105
-o bin/manager-linux-amd64 main.go
98106

99107
.PHONY: run
100-
run: generate-deepcopy ## Run a controller from your host.
108+
run: generate-deepcopy generate-conversion ## Run a controller from your host.
101109
go run ./main.go
102110

103111
# Using a flag file here as docker build doesn't produce a target file.
104112
DOCKER_BUILD_INPUTS=$(MANAGER_BIN_INPUTS) Dockerfile
105113
.PHONY: docker-build
106-
docker-build: generate-deepcopy build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
114+
docker-build: generate-deepcopy generate-conversion build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
107115
.dockerflag.mk: $(DOCKER_BUILD_INPUTS)
108116
docker build -t ${IMG} .
109117
@touch .dockerflag.mk
@@ -137,7 +145,7 @@ lint: bin/golangci-lint bin/staticcheck generate-mocks ## Run linting for the pr
137145
##@ Deployment
138146

139147
.PHONY: deploy
140-
deploy: generate-deepcopy manifests bin/kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
148+
deploy: generate-deepcopy generate-conversion manifests bin/kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
141149
cd config/manager && kustomize edit set image controller=${IMG}
142150
kustomize build config/default | kubectl apply -f -
143151

@@ -147,9 +155,11 @@ undeploy: bin/kustomize ## Undeploy controller from the K8s cluster specified in
147155
##@ Binaries
148156

149157
.PHONY: binaries
150-
binaries: bin/controller-gen bin/kustomize bin/ginkgo bin/golangci-lint bin/staticcheck bin/mockgen bin/kubectl ## Locally install all needed bins.
158+
binaries: bin/controller-gen bin/conversion-gen bin/kustomize bin/ginkgo bin/golangci-lint bin/staticcheck bin/mockgen bin/kubectl ## Locally install all needed bins.
151159
bin/controller-gen: ## Install controller-gen to bin.
152160
GOBIN=$(PROJECT_DIR)/bin go install sigs.k8s.io/controller-tools/cmd/[email protected]
161+
bin/conversion-gen: ## Install conversion-gen to bin.
162+
GOBIN=$(PROJECT_DIR)/bin go install k8s.io/code-generator/cmd/[email protected]
153163
bin/golangci-lint: ## Install golangci-lint to bin.
154164
GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/[email protected]
155165
bin/staticcheck: ## Install staticcheck to bin.
@@ -186,6 +196,7 @@ export KUBEBUILDER_ASSETS=$(PROJECT_DIR)/bin
186196

187197
.PHONY: test
188198
test: generate-mocks lint bin/ginkgo bin/kubectl bin/kube-apiserver bin/etcd ## Run tests. At the moment this is only unit tests.
199+
@./hack/testing_ginkgo_recover_statements.sh --add # Add ginkgo.GinkgoRecover() statements to controllers.
189200
@# The following is a slightly funky way to make sure the ginkgo statements are removed regardless the test results.
190201
@ginkgo_v2 --label-filter="!integ" --cover -coverprofile cover.out --covermode=atomic -v ./api/... ./controllers/... ./pkg/...; EXIT_STATUS=$$?;\
191202
./hack/testing_ginkgo_recover_statements.sh --remove; exit $$EXIT_STATUS
@@ -198,8 +209,8 @@ pkg/mocks/mock%.go: $(shell find ./pkg/cloud -type f -name "*test*" -prune -o -p
198209
##@ Tilt
199210

200211
.PHONY: tilt-up
201-
tilt-up: cluster-api kind-cluster cluster-api/tilt-settings.json manifests cloud-config ## Setup and run tilt for development.
202-
export CLOUDSTACK_B64ENCODED_SECRET=$$(base64 -w0 -i cloud-config 2>/dev/null || base64 -b 0 -i cloud-config) && cd cluster-api && tilt up
212+
tilt-up: cluster-api kind-cluster cluster-api/tilt-settings.json manifests ## Setup and run tilt for development.
213+
cd cluster-api && tilt up
203214

204215
.PHONY: kind-cluster
205216
kind-cluster: cluster-api ## Create a kind cluster with a local Docker repository.
@@ -213,7 +224,7 @@ cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
213224

214225
##@ End-to-End Testing
215226

216-
CLUSTER_TEMPLATES_INPUT_FILES=$(shell find test/e2e/data/infrastructure-cloudstack/*/cluster-template*/* test/e2e/data/infrastructure-cloudstack/*/bases/* -type f)
227+
CLUSTER_TEMPLATES_INPUT_FILES=$(shell find test/e2e/data/infrastructure-cloudstack/v1beta2/*/cluster-template*/* test/e2e/data/infrastructure-cloudstack/*/bases/* -type f)
217228
CLUSTER_TEMPLATES_OUTPUT_FILES=$(shell find test/e2e/data/infrastructure-cloudstack -type d -name "cluster-template*" -exec echo {}.yaml \;)
218229
.PHONY: e2e-cluster-templates
219230
e2e-cluster-templates: $(CLUSTER_TEMPLATES_OUTPUT_FILES) ## Generate cluster template files for e2e testing.
@@ -225,6 +236,7 @@ e2e-essentials: bin/ginkgo_v1 e2e-cluster-templates kind-cluster ## Fulfill esse
225236

226237
JOB ?= .*
227238
run-e2e: e2e-essentials ## Run e2e testing. JOB is an optional REGEXP to select certainn test cases to run. e.g. JOB=PR-Blocking, JOB=Conformance
239+
kubectl apply -f cloud-config.yaml && \
228240
cd test/e2e && \
229241
ginkgo_v1 -v -trace -tags=e2e -focus=$(JOB) -skip=Conformance -nodes=1 -noColor=false ./... -- \
230242
-e2e.artifacts-folder=${PROJECT_DIR}/_artifacts \

PROJECT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ resources:
7777
kind: CloudStackMachineStateChecker
7878
path: sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1
7979
version: v1beta1
80+
- api:
81+
crdVersion: v1
82+
namespaced: true
83+
domain: cluster.x-k8s.io
84+
group: infrastructure
85+
kind: CloudStackFailureDomain
86+
path: sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2
87+
version: v1beta2
8088
version: "3"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
21+
"sigs.k8s.io/controller-runtime/pkg/conversion"
22+
)
23+
24+
func (src *CloudStackAffinityGroup) ConvertTo(dstRaw conversion.Hub) error { // nolint
25+
dst := dstRaw.(*v1beta2.CloudStackAffinityGroup)
26+
return Convert_v1beta1_CloudStackAffinityGroup_To_v1beta2_CloudStackAffinityGroup(src, dst, nil)
27+
}
28+
29+
func (dst *CloudStackAffinityGroup) ConvertFrom(srcRaw conversion.Hub) error { // nolint
30+
src := srcRaw.(*v1beta2.CloudStackAffinityGroup)
31+
return Convert_v1beta2_CloudStackAffinityGroup_To_v1beta1_CloudStackAffinityGroup(src, dst, nil)
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
21+
"sigs.k8s.io/controller-runtime/pkg/conversion"
22+
)
23+
24+
func (src *CloudStackCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint
25+
dst := dstRaw.(*v1beta2.CloudStackCluster)
26+
27+
return Convert_v1beta1_CloudStackCluster_To_v1beta2_CloudStackCluster(src, dst, nil)
28+
}
29+
30+
func (dst *CloudStackCluster) ConvertFrom(srcRaw conversion.Hub) error { // nolint
31+
src := srcRaw.(*v1beta2.CloudStackCluster)
32+
33+
return Convert_v1beta2_CloudStackCluster_To_v1beta1_CloudStackCluster(src, dst, nil)
34+
}

api/v1beta1/cloudstackcluster_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
const (
2727
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
28-
defaultIdentityRefKind = "Secret"
2928
CloudStackClusterLabelName = "cloudstackcluster.infrastructure.cluster.x-k8s.io/name"
3029
NetworkTypeIsolated = "Isolated"
3130
NetworkTypeShared = "Shared"
@@ -49,7 +48,7 @@ type Network struct {
4948
ID string `json:"id,omitempty"`
5049

5150
// Cloudstack Network Type the cluster is built in.
52-
// + optional
51+
// +optional
5352
Type string `json:"type,omitempty"`
5453

5554
// Cloudstack Network Name the cluster is built in.
@@ -61,11 +60,11 @@ type ZoneStatusMap map[string]Zone
6160

6261
type Zone struct {
6362
// Name.
64-
//+optional
63+
// +optional
6564
Name string `json:"name,omitempty"`
6665

6766
// ID.
68-
//+optional
67+
// +optional
6968
ID string `json:"id,omitempty"`
7069

7170
// The network within the Zone to use.
@@ -82,6 +81,7 @@ func (z *Zone) MetaName() string {
8281
return strings.ToLower(s)
8382
}
8483

84+
//+k8s:conversion-gen=false
8585
// CloudStackClusterSpec defines the desired state of CloudStackCluster.
8686
type CloudStackClusterSpec struct {
8787
Zones []Zone `json:"zones"`
@@ -98,10 +98,10 @@ type CloudStackClusterSpec struct {
9898
Domain string `json:"domain,omitempty"`
9999

100100
// +optional
101-
// +k8s:conversion-gen=false
102101
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
103102
}
104103

104+
//+k8s:conversion-gen=false
105105
// The status of the abstract CS k8s (not an actual Cloudstack Cluster) cluster.
106106
type CloudStackClusterStatus struct {
107107

@@ -132,7 +132,7 @@ type CloudStackClusterStatus struct {
132132

133133
//+kubebuilder:object:root=true
134134
//+kubebuilder:subresource:status
135-
135+
//+k8s:conversion-gen=false
136136
// CloudStackCluster is the Schema for the cloudstackclusters API
137137
type CloudStackCluster struct {
138138
metav1.TypeMeta `json:",inline"`
@@ -145,7 +145,7 @@ type CloudStackCluster struct {
145145
}
146146

147147
//+kubebuilder:object:root=true
148-
148+
//+k8s:conversion-gen=false
149149
// CloudStackClusterList contains a list of CloudStackCluster
150150
type CloudStackClusterList struct {
151151
metav1.TypeMeta `json:",inline"`
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
21+
"sigs.k8s.io/controller-runtime/pkg/conversion"
22+
)
23+
24+
func (src *CloudStackIsolatedNetwork) ConvertTo(dstRaw conversion.Hub) error { // nolint
25+
dst := dstRaw.(*v1beta2.CloudStackIsolatedNetwork)
26+
return Convert_v1beta1_CloudStackIsolatedNetwork_To_v1beta2_CloudStackIsolatedNetwork(src, dst, nil)
27+
}
28+
29+
func (dst *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error { // nolint
30+
src := srcRaw.(*v1beta2.CloudStackIsolatedNetwork)
31+
return Convert_v1beta2_CloudStackIsolatedNetwork_To_v1beta1_CloudStackIsolatedNetwork(src, dst, nil)
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
21+
"sigs.k8s.io/controller-runtime/pkg/conversion"
22+
)
23+
24+
func (src *CloudStackMachine) ConvertTo(dstRaw conversion.Hub) error { // nolint
25+
dst := dstRaw.(*v1beta2.CloudStackMachine)
26+
return Convert_v1beta1_CloudStackMachine_To_v1beta2_CloudStackMachine(src, dst, nil)
27+
}
28+
29+
func (dst *CloudStackMachine) ConvertFrom(srcRaw conversion.Hub) error { // nolint
30+
src := srcRaw.(*v1beta2.CloudStackMachine)
31+
return Convert_v1beta2_CloudStackMachine_To_v1beta1_CloudStackMachine(src, dst, nil)
32+
}

api/v1beta1/cloudstackmachine_types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"time"
21+
2022
corev1 "k8s.io/api/core/v1"
2123
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22-
"time"
2324
)
2425

2526
const (
@@ -79,12 +80,14 @@ type CloudStackMachineSpec struct {
7980
ProviderID *string `json:"providerID,omitempty"`
8081

8182
// Optionally settable Zone ID to land the machine in.
83+
// +k8s:conversion-gen=false
8284
ZoneID string `json:"zoneID,omitempty"`
8385

86+
// +k8s:conversion-gen=false
8487
// Optionally settable Zone Name to land the machine in.
8588
ZoneName string `json:"zoneName,omitempty"`
8689

87-
// IdentityRef is a reference to a identity to be used when reconciling this cluster
90+
// IdentityRef is a reference to an identity to be used when reconciling this cluster
8891
// +optional
8992
// +k8s:conversion-gen=false
9093
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
@@ -122,6 +125,7 @@ type InstanceState string
122125
type CloudStackMachineStatus struct {
123126
// Zone ID is used so that the zone can be computed once per reconcile and then propagate.
124127
// +optional
128+
// +k8s:conversion-gen=false
125129
ZoneID string `json:"zoneID,omitempty"`
126130

127131
// Addresses contains a CloudStack VM instance's IP addresses.
@@ -150,7 +154,6 @@ func (s *CloudStackMachineStatus) TimeSinceLastStateChange() time.Duration {
150154

151155
// +kubebuilder:object:root=true
152156
// +kubebuilder:resource:path=cloudstackmachines,scope=Namespaced,categories=cluster-api,shortName=csm
153-
// +kubebuilder:storageversion
154157
// +kubebuilder:subresource:status
155158
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this CloudStackMachine belongs"
156159
// +kubebuilder:printcolumn:name="InstanceState",type="string",JSONPath=".status.instanceState",description="CloudStack instance state"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
21+
"sigs.k8s.io/controller-runtime/pkg/conversion"
22+
)
23+
24+
func (src *CloudStackMachineStateChecker) ConvertTo(dstRaw conversion.Hub) error { // nolint
25+
dst := dstRaw.(*v1beta2.CloudStackMachineStateChecker)
26+
return Convert_v1beta1_CloudStackMachineStateChecker_To_v1beta2_CloudStackMachineStateChecker(src, dst, nil)
27+
}
28+
29+
func (dst *CloudStackMachineStateChecker) ConvertFrom(srcRaw conversion.Hub) error { // nolint
30+
src := srcRaw.(*v1beta2.CloudStackMachineStateChecker)
31+
return Convert_v1beta2_CloudStackMachineStateChecker_To_v1beta1_CloudStackMachineStateChecker(src, dst, nil)
32+
}

0 commit comments

Comments
 (0)