Skip to content

Commit 61adadc

Browse files
committed
changes per comments
1 parent 1694fd0 commit 61adadc

File tree

9 files changed

+27
-53
lines changed

9 files changed

+27
-53
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ binaries: bin/controller-gen bin/conversion-gen bin/kustomize bin/ginkgo bin/gol
154154
bin/controller-gen: ## Install controller-gen to bin.
155155
GOBIN=$(PROJECT_DIR)/bin go install sigs.k8s.io/controller-tools/cmd/[email protected]
156156
bin/conversion-gen: ## Install conversion-gen to bin.
157-
GOBIN=$(PROJECT_DIR)/bin go install k8s.io/code-generator/cmd/[email protected]
157+
GOBIN=$(PROJECT_DIR)/bin go install k8s.io/code-generator/cmd/[email protected]
158158
bin/golangci-lint: ## Install golangci-lint to bin.
159159
GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/[email protected]
160160
bin/staticcheck: ## Install staticcheck to bin.

api/v1beta1/cloudstackcluster_types.go

Lines changed: 5 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.
@@ -132,7 +132,7 @@ type CloudStackClusterStatus struct {
132132

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

147147
//+kubebuilder:object:root=true
148-
// +k8s:conversion-gen=false
149-
148+
//+k8s:conversion-gen=false
150149
// CloudStackClusterList contains a list of CloudStackCluster
151150
type CloudStackClusterList struct {
152151
metav1.TypeMeta `json:",inline"`

api/v1beta1/conversion.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
corev1 "k8s.io/api/core/v1"
2525
conv "k8s.io/apimachinery/pkg/conversion"
2626
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
27-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2827
"sigs.k8s.io/controller-runtime/pkg/client"
2928
)
3029

@@ -109,7 +108,7 @@ func getFailureDomains(csCluster *CloudStackCluster) ([]v1beta2.CloudStackFailur
109108
Domain: csCluster.Spec.Domain,
110109
Account: csCluster.Spec.Account,
111110
ACSEndpoint: corev1.SecretReference{
112-
Namespace: csCluster.ObjectMeta.Namespace,
111+
Namespace: csCluster.Namespace,
113112
Name: DefaultEndpointCredential,
114113
},
115114
})
@@ -134,32 +133,21 @@ func GetDefaultFailureDomainName(namespace string, clusterName string, zoneID st
134133
return zoneID + "-" + clusterName, nil
135134
}
136135

137-
zoneID, err = fetchZoneIDUsingK8s(namespace, clusterName, zoneName)
136+
zoneID, err = fetchZoneIDUsingK8s(namespace, zoneName)
138137
if err != nil {
139138
return "", nil
140139
}
141140
return zoneID + "-" + clusterName, nil
142141
}
143142

144-
func fetchZoneIDUsingK8s(namespace string, clusterName string, zoneName string) (string, error) {
145-
zones := &CloudStackZoneList{}
146-
capiClusterLabel := map[string]string{clusterv1.ClusterLabelName: clusterName}
147-
if err := v1beta2.K8sClient.List(
148-
context.TODO(),
149-
zones,
150-
client.InNamespace(namespace),
151-
client.MatchingLabels(capiClusterLabel),
152-
); err != nil {
143+
func fetchZoneIDUsingK8s(namespace string, zoneName string) (string, error) {
144+
zone := &CloudStackZone{}
145+
key := client.ObjectKey{Name: zoneName, Namespace: namespace}
146+
if err := v1beta2.K8sClient.Get(context.TODO(), key, zone); err != nil {
153147
return "", err
154148
}
155149

156-
for _, zone := range zones.Items {
157-
if zone.Spec.Name == zoneName {
158-
return zone.Spec.ID, nil
159-
}
160-
}
161-
162-
return "", errors.Errorf("failed to generate default failureDomainName: zone id not found for zone name: %s", zoneName)
150+
return zone.Spec.ID, nil
163151
}
164152

165153
func fetchZoneIDUsingCloudStack(namespace string, zoneName string) (string, error) {

api/v1beta2/cloudstackisolatednetwork_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type CloudStackIsolatedNetworkSpec struct {
3939
// The kubernetes control plane endpoint.
4040
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
4141

42-
// +k8s:conversion-gen=false
42+
//+k8s:conversion-gen=false
4343
// FailureDomain -- the FailureDomain the network is placed in.
4444
FailureDomain CloudStackFailureDomainSpec `json:"failureDomain"`
4545
}

config/crd/kustomization.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ resources:
1818
patchesStrategicMerge:
1919
# patches here are for enabling the conversion webhook for each CRD
2020
- patches/webhook_in_cloudstackclusters.yaml
21-
#- patches/webhook_in_cloudstackmachines.yaml
22-
#- patches/webhook_in_cloudstackmachinetemplates.yaml
23-
#- patches/webhook_in_cloudstackisolatednetworks.yaml
24-
#- patches/webhook_in_cloudstackzones.yaml
25-
#- patches/webhook_in_cloudstackaffinitygroups.yaml
26-
#- patches/webhook_in_cloudstackmachinestatecheckers.yaml
27-
#- patches/webhook_in_cloudstackfailuredomains.yaml
21+
- patches/webhook_in_cloudstackmachines.yaml
22+
- patches/webhook_in_cloudstackmachinetemplates.yaml
23+
- patches/webhook_in_cloudstackisolatednetworks.yaml
24+
- patches/webhook_in_cloudstackzones.yaml
25+
- patches/webhook_in_cloudstackaffinitygroups.yaml
26+
- patches/webhook_in_cloudstackmachinestatecheckers.yaml
27+
- patches/webhook_in_cloudstackfailuredomains.yaml
2828
#+kubebuilder:scaffold:crdkustomizewebhookpatch
2929

3030
# patches here are for enabling the CA injection for each CRD
3131
- patches/cainjection_in_cloudstackclusters.yaml
3232
- patches/cainjection_in_cloudstackmachines.yaml
3333
- patches/cainjection_in_cloudstackmachinetemplates.yaml
34-
#- patches/cainjection_in_cloudstackisolatednetworks.yaml
35-
#- patches/cainjection_in_cloudstackzones.yaml
36-
#- patches/cainjection_in_cloudstackaffinitygroups.yaml
37-
#- patches/cainjection_in_cloudstackmachinestatecheckers.yaml
38-
#- patches/cainjection_in_cloudstackfailuredomains.yaml
34+
- patches/cainjection_in_cloudstackisolatednetworks.yaml
35+
- patches/cainjection_in_cloudstackzones.yaml
36+
- patches/cainjection_in_cloudstackaffinitygroups.yaml
37+
- patches/cainjection_in_cloudstackmachinestatecheckers.yaml
38+
- patches/cainjection_in_cloudstackfailuredomains.yaml
3939
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
4040

4141
# the following config is for teaching kustomize how to do kustomization for CRDs.

config/crd/patches/cainjection_in_cloudstackclusters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
7-
name: cloudstackclusters.infrastructure.cluster.x-k8s.io
7+
name: cloudstackclusters.infrastructure.cluster.x-k8s.io

config/samples/infrastructure_v1beta2_cloudstackcluster.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ require (
1313
github.com/prometheus/client_golang v1.11.0
1414
github.com/smallfish/simpleyaml v0.1.0
1515
github.com/spf13/pflag v1.0.5
16-
gopkg.in/ini.v1 v1.63.2
1716
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
1817
k8s.io/api v0.23.0
1918
k8s.io/apimachinery v0.23.0
2019
k8s.io/client-go v0.23.0
21-
k8s.io/code-generator v0.23.0 // indirect
2220
k8s.io/klog/v2 v2.30.0
2321
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
2422
sigs.k8s.io/cluster-api v1.0.0

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
661661
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
662662
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
663663
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
664-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
665664
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
666665
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
667666
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -911,7 +910,6 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
911910
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
912911
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
913912
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM=
914-
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
915913
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
916914
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
917915
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -1065,7 +1063,6 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
10651063
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
10661064
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
10671065
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
1068-
gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
10691066
gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
10701067
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
10711068
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
@@ -1114,15 +1111,13 @@ k8s.io/client-go v0.23.0/go.mod h1:hrDnpnK1mSr65lHHcUuIZIXDgEbzc7/683c6hyG4jTA=
11141111
k8s.io/cluster-bootstrap v0.22.2 h1:jP6Nkp3CdSfr50cAn/7WGsNS52zrwMhvr0V+E3Vkh/w=
11151112
k8s.io/cluster-bootstrap v0.22.2/go.mod h1:ZkmQKprEqvrUccMnbRHISsMscA1dsQ8SffM9nHq6CgE=
11161113
k8s.io/code-generator v0.22.2/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpxa+o=
1117-
k8s.io/code-generator v0.23.0 h1:lhyd2KJVCEmpjaCpuoooGs+e3xhPwpYvupnNRidO0Ds=
11181114
k8s.io/code-generator v0.23.0/go.mod h1:vQvOhDXhuzqiVfM/YHp+dmg10WDZCchJVObc9MvowsE=
11191115
k8s.io/component-base v0.22.2/go.mod h1:5Br2QhI9OTe79p+TzPe9JKNQYvEKbq9rTJDWllunGug=
11201116
k8s.io/component-base v0.23.0 h1:UAnyzjvVZ2ZR1lF35YwtNY6VMN94WtOnArcXBu34es8=
11211117
k8s.io/component-base v0.23.0/go.mod h1:DHH5uiFvLC1edCpvcTDV++NKULdYYU6pR9Tt3HIKMKI=
11221118
k8s.io/component-helpers v0.22.2/go.mod h1:+N61JAR9aKYSWbnLA88YcFr9K/6ISYvRNybX7QW7Rs8=
11231119
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
11241120
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
1125-
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c h1:GohjlNKauSai7gN4wsJkeZ3WAJx4Sh+oT/b5IYn5suA=
11261121
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
11271122
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
11281123
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=

0 commit comments

Comments
 (0)