Skip to content

Commit 8d0354a

Browse files
committed
2 parents 47372d8 + 154eed4 commit 8d0354a

File tree

168 files changed

+7940
-1297
lines changed

Some content is hidden

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

168 files changed

+7940
-1297
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ cluster-api
2929
# Ignore output of Makefile sed operations created when generating manifests.
3030
config/default/manager_image_patch_edited.yaml
3131

32+
# Ignore output of e2e kustomization of templates.
33+
test/e2e/data/infrastructure-cloudstack/v1beta*/*yaml
34+
3235
# Test binary, build with `go test -c`
3336
*.test
3437

Makefile

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ config/.flag.mk: bin/controller-gen $(MANIFEST_GEN_INPUTS)
6363
.PHONY: release-manifests
6464
RELEASE_MANIFEST_TARGETS=$(RELEASE_DIR)/infrastructure-components.yaml $(RELEASE_DIR)/metadata.yaml
6565
RELEASE_MANIFEST_INPUTS=bin/kustomize config/.flag.mk $(shell find config)
66+
RELEASE_MANIFEST_SOURCE_BASE ?= config/default
6667
release-manifests: $(RELEASE_MANIFEST_TARGETS) ## Create kustomized release manifest in $RELEASE_DIR (defaults to out).
6768
$(RELEASE_DIR)/%: $(RELEASE_MANIFEST_INPUTS)
6869
@mkdir -p $(RELEASE_DIR)
6970
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml
70-
kustomize build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
71+
kustomize build $(RELEASE_MANIFEST_SOURCE_BASE) > $(RELEASE_DIR)/infrastructure-components.yaml
72+
73+
.PHONY: release-manifests-metrics-port
74+
release-manifests-metrics-port:
75+
make release-manifests RELEASE_MANIFEST_SOURCE_BASE=config/default-with-metrics-port
7176

7277
DEEPCOPY_GEN_TARGETS=$(shell find api -type d -name "v*" -exec echo {}\/zz_generated.deepcopy.go \;)
7378
DEEPCOPY_GEN_INPUTS=$(shell find ./api -name "*test*" -prune -o -name "*zz_generated*" -prune -o -type f -print)
@@ -76,6 +81,14 @@ generate-deepcopy: $(DEEPCOPY_GEN_TARGETS) ## Generate code containing DeepCopy,
7681
api/%/zz_generated.deepcopy.go: bin/controller-gen $(DEEPCOPY_GEN_INPUTS)
7782
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
7883

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+
7992
##@ Build
8093

8194
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
@@ -92,13 +105,13 @@ bin/manager-linux-amd64: $(MANAGER_BIN_INPUTS)
92105
-o bin/manager-linux-amd64 main.go
93106

94107
.PHONY: run
95-
run: generate-deepcopy ## Run a controller from your host.
108+
run: generate-deepcopy generate-conversion ## Run a controller from your host.
96109
go run ./main.go
97110

98111
# Using a flag file here as docker build doesn't produce a target file.
99112
DOCKER_BUILD_INPUTS=$(MANAGER_BIN_INPUTS) Dockerfile
100113
.PHONY: docker-build
101-
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.
102115
.dockerflag.mk: $(DOCKER_BUILD_INPUTS)
103116
docker build -t ${IMG} .
104117
@touch .dockerflag.mk
@@ -132,7 +145,7 @@ lint: bin/golangci-lint bin/staticcheck generate-mocks ## Run linting for the pr
132145
##@ Deployment
133146

134147
.PHONY: deploy
135-
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.
136149
cd config/manager && kustomize edit set image controller=${IMG}
137150
kustomize build config/default | kubectl apply -f -
138151

@@ -142,9 +155,11 @@ undeploy: bin/kustomize ## Undeploy controller from the K8s cluster specified in
142155
##@ Binaries
143156

144157
.PHONY: binaries
145-
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.
146159
bin/controller-gen: ## Install controller-gen to bin.
147160
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]
148163
bin/golangci-lint: ## Install golangci-lint to bin.
149164
GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/[email protected]
150165
bin/staticcheck: ## Install staticcheck to bin.
@@ -173,6 +188,7 @@ clean: ## Clean.
173188
rm -rf $(RELEASE_DIR)
174189
rm -rf bin
175190
rm -rf cluster-api
191+
rm -rf test/e2e/data/infrastructure-cloudstack/*/*yaml
176192

177193
##@ Testing
178194

@@ -181,6 +197,7 @@ export KUBEBUILDER_ASSETS=$(PROJECT_DIR)/bin
181197

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

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

199216
.PHONY: kind-cluster
200217
kind-cluster: cluster-api ## Create a kind cluster with a local Docker repository.
@@ -207,8 +224,7 @@ cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
207224
cp ./hack/tilt-settings.json cluster-api
208225

209226
##@ End-to-End Testing
210-
211-
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/v1beta*/*/cluster-template* test/e2e/data/infrastructure-cloudstack/*/bases/* -type f)
212228
CLUSTER_TEMPLATES_OUTPUT_FILES=$(shell find test/e2e/data/infrastructure-cloudstack -type d -name "cluster-template*" -exec echo {}.yaml \;)
213229
.PHONY: e2e-cluster-templates
214230
e2e-cluster-templates: $(CLUSTER_TEMPLATES_OUTPUT_FILES) ## Generate cluster template files for e2e testing.
@@ -220,6 +236,7 @@ e2e-essentials: bin/ginkgo_v1 e2e-cluster-templates kind-cluster ## Fulfill esse
220236

221237
JOB ?= .*
222238
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 && \
223240
cd test/e2e && \
224241
ginkgo_v1 -v -trace -tags=e2e -focus=$(JOB) -skip=Conformance -nodes=1 -noColor=false ./... -- \
225242
-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"

0 commit comments

Comments
 (0)