Skip to content

Commit 964e914

Browse files
committed
merge v1beta2 onto multiple ep
2 parents 23ef8c5 + 8c09d53 commit 964e914

35 files changed

+1955
-59
lines changed

Makefile

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

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

7785
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 +96,13 @@ bin/manager-linux-amd64: $(MANAGER_BIN_INPUTS)
8896
-o bin/manager-linux-amd64 main.go
8997

9098
.PHONY: run
91-
run: generate-deepcopy ## Run a controller from your host.
99+
run: generate-deepcopy generate-conversion ## Run a controller from your host.
92100
go run ./main.go
93101

94102
# Using a flag file here as docker build doesn't produce a target file.
95103
DOCKER_BUILD_INPUTS=$(MANAGER_BIN_INPUTS) Dockerfile
96104
.PHONY: docker-build
97-
docker-build: generate-deepcopy build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
105+
docker-build: generate-deepcopy generate-conversion build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
98106
.dockerflag.mk: $(DOCKER_BUILD_INPUTS)
99107
docker build -t ${IMG} .
100108
@touch .dockerflag.mk
@@ -128,7 +136,7 @@ lint: bin/golangci-lint bin/staticcheck generate-mocks ## Run linting for the pr
128136
##@ Deployment
129137

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

@@ -138,9 +146,11 @@ undeploy: bin/kustomize ## Undeploy controller from the K8s cluster specified in
138146
##@ Binaries
139147

140148
.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.
149+
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.
142150
bin/controller-gen: ## Install controller-gen to bin.
143151
GOBIN=$(PROJECT_DIR)/bin go install sigs.k8s.io/controller-tools/cmd/[email protected]
152+
bin/conversion-gen: ## Install conversion-gen to bin.
153+
GOBIN=$(PROJECT_DIR)/bin go install k8s.io/code-generator/cmd/[email protected]
144154
bin/golangci-lint: ## Install golangci-lint to bin.
145155
GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/[email protected]
146156
bin/staticcheck: ## Install staticcheck to bin.
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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
const CloudstackMachineAnnotationPrefix string = "cloudstackmachine.infrastructure.cluster.x-k8s.io/"
25+
26+
func (src *CloudStackMachine) ConvertTo(dstRaw conversion.Hub) error { // nolint
27+
dst := dstRaw.(*v1beta2.CloudStackMachine)
28+
err := Convert_v1beta1_CloudStackMachine_To_v1beta2_CloudStackMachine(src, dst, nil)
29+
if err != nil {
30+
return err
31+
}
32+
// need to save zoneId and zoneName to v1beta2s annotation in metadata
33+
dst.ObjectMeta.Annotations[CloudstackMachineAnnotationPrefix+"zoneid"] = src.Spec.ZoneID
34+
dst.ObjectMeta.Annotations[CloudstackMachineAnnotationPrefix+"zonename"] = src.Spec.ZoneName
35+
36+
// need to save failuredomainname in v1beta1's annotation to v1beta2's spec
37+
if len(src.ObjectMeta.Annotations[CloudstackMachineAnnotationPrefix+"failuredomainname"]) > 0 {
38+
dst.Spec.FailureDomainName = src.ObjectMeta.Annotations[CloudstackMachineAnnotationPrefix+"failuredomainname"]
39+
} else {
40+
defaultDomainName, err := GetDefaultFailureDomainName(src.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"], src.Spec.ZoneID, src.Spec.ZoneName)
41+
if err != nil {
42+
return err
43+
}
44+
dst.Spec.FailureDomainName = defaultDomainName
45+
}
46+
return nil
47+
}
48+
49+
func (dst *CloudStackMachine) ConvertFrom(srcRaw conversion.Hub) error { // nolint
50+
src := srcRaw.(*v1beta2.CloudStackMachine)
51+
err := Convert_v1beta2_CloudStackMachine_To_v1beta1_CloudStackMachine(src, dst, nil)
52+
if err != nil {
53+
return err
54+
}
55+
// need to restore zoneid and zonename from v1beta2's annotation in metadata
56+
dst.Spec.ZoneID = src.ObjectMeta.Annotations[CloudstackMachineAnnotationPrefix+"zoneid"]
57+
dst.Spec.ZoneName = src.ObjectMeta.Annotations[CloudstackMachineAnnotationPrefix+"zonename"]
58+
59+
// need to save failuredomainname in v1beta1's annotation
60+
dst.ObjectMeta.Annotations[CloudstackMachineAnnotationPrefix+"failuredomainname"] = src.Spec.FailureDomainName
61+
return nil
62+
}

api/v1beta1/cloudstackmachine_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ type CloudStackMachineSpec struct {
7979
// +optional
8080
ProviderID *string `json:"providerID,omitempty"`
8181

82+
// +k8s:conversion-gen=false
8283
// Optionally settable Zone ID to land the machine in.
8384
ZoneID string `json:"zoneID,omitempty"`
8485

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

88-
// 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
8991
// +optional
90-
// +k8s:conversion-gen=false
9192
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
9293
}
9394

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+
}
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 *CloudStackZone) ConvertTo(dstRaw conversion.Hub) error { // nolint
25+
dst := dstRaw.(*v1beta2.CloudStackZone)
26+
return Convert_v1beta1_CloudStackZone_To_v1beta2_CloudStackZone(src, dst, nil)
27+
}
28+
29+
func (dst *CloudStackZone) ConvertFrom(srcRaw conversion.Hub) error { // nolint
30+
src := srcRaw.(*v1beta2.CloudStackZone)
31+
return Convert_v1beta2_CloudStackZone_To_v1beta1_CloudStackZone(src, dst, nil)
32+
}

0 commit comments

Comments
 (0)