Skip to content

Commit 9012d97

Browse files
committed
v1beta2 initial step - 0
1 parent b9dc417 commit 9012d97

File tree

61 files changed

+4878
-78
lines changed

Some content is hidden

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

61 files changed

+4878
-78
lines changed

Makefile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Image URL to use all building/pushing image targets
22
IMG ?= public.ecr.aws/a4z9h2b1/cluster-api-provider-capc:latest
33
IMG_LOCAL ?= localhost:5000/cluster-api-provider-cloudstack:latest
4+
CRD_OPTIONS ?= "crd"
45

56
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
67
ifeq (,$(shell go env GOBIN))
@@ -72,6 +73,14 @@ generate-deepcopy: $(DEEPCOPY_GEN_TARGETS) ## Generate code containing DeepCopy,
7273
api/%/zz_generated.deepcopy.go: bin/controller-gen $(DEEPCOPY_GEN_INPUTS)
7374
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
7475

76+
CONVERSION_GEN_TARGET=$(shell find api -type d -name "v*" -exec echo {}\/zz_generated.conversion.go \;)
77+
CONVERSION_GEN_INPUTS=$(shell find ./api -name "*test*" -prune -o -name "*zz_generated*" -prune -o -type f -print)
78+
.PHONY: generate-conversion
79+
generate-conversion: $(CONVERSION_GEN_TARGET) ## Generate code to convert api/v1beta1 to api/v1beta2
80+
api/%/zz_generated.conversion.go: bin/conversion-gen $(CONVERSION_GEN_INPUTS)
81+
conversion-gen --go-header-file "./hack/boilerplate.go.txt" --input-dirs "./api/v1beta1" \
82+
--output-base "." --output-file-base="zz_generated.conversion" --skip-unsafe=true
83+
7584
##@ Build
7685

7786
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
@@ -88,13 +97,13 @@ bin/manager-linux-amd64: $(MANAGER_BIN_INPUTS)
8897
-o bin/manager-linux-amd64 main.go
8998

9099
.PHONY: run
91-
run: generate-deepcopy ## Run a controller from your host.
100+
run: generate-deepcopy generate-conversion ## Run a controller from your host.
92101
go run ./main.go
93102

94103
# Using a flag file here as docker build doesn't produce a target file.
95104
DOCKER_BUILD_INPUTS=$(MANAGER_BIN_INPUTS) Dockerfile
96105
.PHONY: docker-build
97-
docker-build: generate-deepcopy build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
106+
docker-build: generate-deepcopy generate-conversion build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
98107
.dockerflag.mk: $(DOCKER_BUILD_INPUTS)
99108
docker build -t ${IMG} .
100109
@touch .dockerflag.mk
@@ -128,7 +137,7 @@ lint: bin/golangci-lint bin/staticcheck generate-mocks ## Run linting for the pr
128137
##@ Deployment
129138

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

@@ -138,9 +147,11 @@ undeploy: bin/kustomize ## Undeploy controller from the K8s cluster specified in
138147
##@ Binaries
139148

140149
.PHONY: binaries
141-
binaries: bin/controller-gen bin/kustomize bin/ginkgo bin/golangci-lint bin/staticcheck bin/mockgen bin/kubectl ## Locally install all needed bins.
150+
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.
142151
bin/controller-gen: ## Install controller-gen to bin.
143152
GOBIN=$(PROJECT_DIR)/bin go install sigs.k8s.io/controller-tools/cmd/[email protected]
153+
bin/conversion-gen: ## Install conversion-gen to bin.
154+
GOBIN=$(PROJECT_DIR)/bin go install k8s.io/code-generator/cmd/[email protected]
144155
bin/golangci-lint: ## Install golangci-lint to bin.
145156
GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/[email protected]
146157
bin/staticcheck: ## Install staticcheck to bin.
@@ -183,7 +194,7 @@ test: generate-mocks lint bin/ginkgo bin/kubectl bin/kube-apiserver bin/etcd ##
183194
./hack/testing_ginkgo_recover_statements.sh --remove; exit $$EXIT_STATUS
184195

185196
.PHONY: generate-mocks
186-
generate-mocks: bin/mockgen generate-deepcopy pkg/mocks/mock_client.go $(shell find ./pkg/mocks -type f -name "mock*.go") ## Generate mocks needed for testing. Primarily mocks of the cloud package.
197+
generate-mocks: bin/mockgen generate-deepcopy generate-conversion pkg/mocks/mock_client.go $(shell find ./pkg/mocks -type f -name "mock*.go") ## Generate mocks needed for testing. Primarily mocks of the cloud package.
187198
pkg/mocks/mock%.go: $(shell find ./pkg/cloud -type f -name "*test*" -prune -o -print)
188199
go generate ./...
189200

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: CloudStackCluster
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
)
2525

2626
const (
27-
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
28-
defaultIdentityRefKind = "Secret"
27+
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
28+
//defaultIdentityRefKind = "Secret"
2929
CloudStackClusterLabelName = "cloudstackcluster.infrastructure.cluster.x-k8s.io/name"
3030
NetworkTypeIsolated = "Isolated"
3131
NetworkTypeShared = "Shared"
@@ -82,6 +82,7 @@ func (z *Zone) MetaName() string {
8282
return strings.ToLower(s)
8383
}
8484

85+
//+k8s:conversion-gen=false
8586
// CloudStackClusterSpec defines the desired state of CloudStackCluster.
8687
type CloudStackClusterSpec struct {
8788
Zones []Zone `json:"zones"`
@@ -98,10 +99,10 @@ type CloudStackClusterSpec struct {
9899
Domain string `json:"domain,omitempty"`
99100

100101
// +optional
101-
// +k8s:conversion-gen=false
102102
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
103103
}
104104

105+
//+k8s:conversion-gen=false
105106
// The status of the abstract CS k8s (not an actual Cloudstack Cluster) cluster.
106107
type CloudStackClusterStatus struct {
107108

@@ -132,7 +133,7 @@ type CloudStackClusterStatus struct {
132133

133134
//+kubebuilder:object:root=true
134135
//+kubebuilder:subresource:status
135-
136+
// +k8s:conversion-gen=false
136137
// CloudStackCluster is the Schema for the cloudstackclusters API
137138
type CloudStackCluster struct {
138139
metav1.TypeMeta `json:",inline"`
@@ -145,6 +146,7 @@ type CloudStackCluster struct {
145146
}
146147

147148
//+kubebuilder:object:root=true
149+
// +k8s:conversion-gen=false
148150

149151
// CloudStackClusterList contains a list of CloudStackCluster
150152
type CloudStackClusterList struct {
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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ type CloudStackMachineSpec struct {
8383
// Optionally settable Zone Name to land the machine in.
8484
ZoneName string `json:"zoneName,omitempty"`
8585

86-
// IdentityRef is a reference to a identity to be used when reconciling this cluster
86+
// IdentityRef is a reference to an identity to be used when reconciling this cluster
8787
// +optional
88-
// +k8s:conversion-gen=false
8988
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
9089
}
9190

@@ -136,7 +135,6 @@ type CloudStackMachineStatus struct {
136135

137136
// +kubebuilder:object:root=true
138137
// +kubebuilder:resource:path=cloudstackmachines,scope=Namespaced,categories=cluster-api,shortName=csm
139-
// +kubebuilder:storageversion
140138
// +kubebuilder:subresource:status
141139
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this CloudStackMachine belongs"
142140
// +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+
}
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 *CloudStackMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { // nolint
25+
dst := dstRaw.(*v1beta2.CloudStackMachineTemplate)
26+
return Convert_v1beta1_CloudStackMachineTemplate_To_v1beta2_CloudStackMachineTemplate(src, dst, nil)
27+
}
28+
29+
func (dst *CloudStackMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error { // nolint
30+
src := srcRaw.(*v1beta2.CloudStackMachineTemplate)
31+
return Convert_v1beta2_CloudStackMachineTemplate_To_v1beta1_CloudStackMachineTemplate(src, dst, nil)
32+
}

0 commit comments

Comments
 (0)