Skip to content

Commit bf8d4c1

Browse files
authored
Merge pull request #2 from wanyufe/multiple-endpoints
Multiple endpoints
2 parents 61f6d61 + 20db3dc commit bf8d4c1

38 files changed

+1798
-67
lines changed

Makefile

Lines changed: 16 additions & 6 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.
@@ -199,8 +209,8 @@ pkg/mocks/mock%.go: $(shell find ./pkg/cloud -type f -name "*test*" -prune -o -p
199209
##@ Tilt
200210

201211
.PHONY: tilt-up
202-
tilt-up: cluster-api kind-cluster cluster-api/tilt-settings.json manifests cloud-config ## Setup and run tilt for development.
203-
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
204214

205215
.PHONY: kind-cluster
206216
kind-cluster: cluster-api ## Create a kind cluster with a local Docker repository.
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Network struct {
4848
ID string `json:"id,omitempty"`
4949

5050
// Cloudstack Network Type the cluster is built in.
51-
// + optional
51+
// +optional
5252
Type string `json:"type,omitempty"`
5353

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

6161
type Zone struct {
6262
// Name.
63-
//+optional
63+
// +optional
6464
Name string `json:"name,omitempty"`
6565

6666
// ID.
67-
//+optional
67+
// +optional
6868
ID string `json:"id,omitempty"`
6969

7070
// The network within the Zone to use.
@@ -81,6 +81,7 @@ func (z *Zone) MetaName() string {
8181
return strings.ToLower(s)
8282
}
8383

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

99100
// +optional
100-
// +k8s:conversion-gen=false
101101
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
102102
}
103103

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

@@ -131,7 +132,7 @@ type CloudStackClusterStatus struct {
131132

132133
//+kubebuilder:object:root=true
133134
//+kubebuilder:subresource:status
134-
135+
//+k8s:conversion-gen=false
135136
// CloudStackCluster is the Schema for the cloudstackclusters API
136137
type CloudStackCluster struct {
137138
metav1.TypeMeta `json:",inline"`
@@ -144,7 +145,7 @@ type CloudStackCluster struct {
144145
}
145146

146147
//+kubebuilder:object:root=true
147-
148+
//+k8s:conversion-gen=false
148149
// CloudStackClusterList contains a list of CloudStackCluster
149150
type CloudStackClusterList struct {
150151
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ type CloudStackMachineSpec struct {
8080
ProviderID *string `json:"providerID,omitempty"`
8181

8282
// Optionally settable Zone ID to land the machine in.
83+
// +k8s:conversion-gen=false
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
9092
// +k8s:conversion-gen=false
9193
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
@@ -123,6 +125,7 @@ type InstanceState string
123125
type CloudStackMachineStatus struct {
124126
// Zone ID is used so that the zone can be computed once per reconcile and then propagate.
125127
// +optional
128+
// +k8s:conversion-gen=false
126129
ZoneID string `json:"zoneID,omitempty"`
127130

128131
// Addresses contains a CloudStack VM instance's IP addresses.
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+
}

api/v1beta1/cloudstackzone_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type CloudStackZoneStatus struct {
4646

4747
//+kubebuilder:object:root=true
4848
//+kubebuilder:subresource:status
49-
49+
//+k8s:conversion-gen=false
5050
// CloudStackZone is the Schema for the cloudstackzones API
5151
type CloudStackZone struct {
5252
metav1.TypeMeta `json:",inline"`

0 commit comments

Comments
 (0)