Skip to content

Commit cb94a32

Browse files
author
Joshua Reed
committed
Major moves toward multizone, but still broken.
1 parent 15e12ad commit cb94a32

12 files changed

+350
-266
lines changed

api/v1beta1/cloudstackcluster_types.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ type CloudStackIdentityReference struct {
4141

4242
type Network struct {
4343
// Cloudstack Network ID the cluster is built in.
44-
Id string `json:"networkID,omitempty"`
44+
Id string `json:"id,omitempty"`
4545

4646
// Cloudstack Network Type the cluster is built in.
4747
// + optional
48-
Type string `json:"networkType,omitempty"`
48+
Type string `json:"type,omitempty"`
4949

5050
// Name of the infrastructure identity to be used.
5151
// +optional
@@ -87,6 +87,11 @@ type CloudStackClusterSpec struct {
8787

8888
// The status of the abstract CS k8s (not an actual Cloudstack Cluster) cluster.
8989
type CloudStackClusterStatus struct {
90+
91+
// The status of the cluster's ACS Zones.
92+
// +optional
93+
Zones map[string]Zone `json:"zones,omitempty"`
94+
9095
// Reflects the readiness of the CS cluster.
9196
Ready bool `json:"ready"`
9297

@@ -96,6 +101,9 @@ type CloudStackClusterStatus struct {
96101
// The CS public IP ID to use for the k8s endpoint.
97102
PublicIPID string `json:"publicIPID,omitempty"`
98103

104+
// The Id of the network the PublicIP is in.
105+
PublicIPNetworkId string `json:"publicIPNetworkId,omitempty"`
106+
99107
// The ID of the lb rule used to assign VMs to the lb.
100108
LBRuleID string `json:"loadBalancerRuleID,omitempty"`
101109
}

api/v1beta1/cloudstackcluster_webhook.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ func (r *CloudStackCluster) ValidateCreate() error {
6666
errorList = append(errorList, field.Required(field.NewPath("spec", "account"), "specifying account requires additionally specifying domain"))
6767
}
6868

69+
// errorList = webhook_utilities.EnsureFieldExists(r.Spec.Zones, "Zone", errorList)
70+
6971
// Zone and Network are required fields
70-
errorList = webhookutil.EnsureFieldExists(r.Spec.Zone, "Zone", errorList)
71-
errorList = webhookutil.EnsureFieldExists(r.Spec.Network, "Network", errorList)
72+
if len(r.Spec.Zones) <= 0 {
73+
errorList = append(errorList, field.Required(field.NewPath("spec", "Zones"), "asdfasdfasdf"))
74+
}
7275

7376
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
7477
}
@@ -94,8 +97,8 @@ func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) error {
9497
}
9598

9699
// No spec fields may be changed
97-
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Zone, oldSpec.Zone, "zone", errorList)
98-
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Network, oldSpec.Network, "network", errorList)
100+
// errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.Zone, oldSpec.Zone, "zone", errorList)
101+
// errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.Network, oldSpec.Network, "network", errorList)
99102
if oldSpec.ControlPlaneEndpoint.Host != "" { // Need to allow one time endpoint setting via CAPC cluster controller.
100103
errorList = webhookutil.EnsureStringFieldsAreEqual(
101104
spec.ControlPlaneEndpoint.Host, oldSpec.ControlPlaneEndpoint.Host, "controlplaneendpointhost", errorList)

api/v1beta1/cloudstackcluster_webhook_test.go

Lines changed: 51 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
. "github.com/onsi/ginkgo"
2323
. "github.com/onsi/gomega"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2625
)
2726

2827
var _ = Describe("CloudStackCluster webhooks", func() {
@@ -33,83 +32,59 @@ var _ = Describe("CloudStackCluster webhooks", func() {
3332
clusterNamespace = "default"
3433
clusterID = "0"
3534
identitySecretName = "IdentitySecret"
36-
zone = "Zone"
35+
zoneName = "Zone"
3736
network = "Network"
3837
)
3938

39+
var ( // Shared base test vars.
40+
cloudStackCluster *CloudStackCluster
41+
testZone1 Zone
42+
testZone2 Zone
43+
)
44+
45+
BeforeEach(func() { // Reset test vars to initial state.
46+
testZone1 = Zone{Name: zoneName}
47+
testZone2 = Zone{Name: zoneName}
48+
cloudStackCluster = &CloudStackCluster{
49+
TypeMeta: metav1.TypeMeta{
50+
APIVersion: apiVersion,
51+
Kind: clusterKind,
52+
},
53+
ObjectMeta: metav1.ObjectMeta{
54+
Name: clusterName,
55+
Namespace: clusterNamespace,
56+
},
57+
Spec: CloudStackClusterSpec{
58+
IdentityRef: &CloudStackIdentityReference{
59+
Kind: defaultIdentityRefKind,
60+
Name: identitySecretName,
61+
},
62+
Zones: []Zone{testZone1, testZone2},
63+
},
64+
}
65+
66+
})
67+
4068
Context("When creating a CloudStackCluster with all validated attributes", func() {
4169
It("Should succeed", func() {
4270
ctx := context.Background()
43-
cloudStackCluster := &CloudStackCluster{
44-
TypeMeta: metav1.TypeMeta{
45-
APIVersion: apiVersion,
46-
Kind: clusterKind,
47-
},
48-
ObjectMeta: metav1.ObjectMeta{
49-
Name: clusterName,
50-
Namespace: clusterNamespace,
51-
UID: clusterID,
52-
},
53-
Spec: CloudStackClusterSpec{
54-
IdentityRef: &CloudStackIdentityReference{
55-
Kind: defaultIdentityRefKind,
56-
Name: identitySecretName,
57-
},
58-
Zone: zone,
59-
Network: network,
60-
},
61-
}
62-
Expect(k8sClient.Create(ctx, cloudStackCluster)).Should(Succeed())
71+
Ω(k8sClient.Create(ctx, cloudStackCluster)).Should(Succeed())
6372
})
6473
})
6574

6675
Context("When creating a CloudStackCluster with missing Network attribute", func() {
6776
It("Should be rejected by the validating webhooks", func() {
6877
ctx := context.Background()
69-
cloudStackCluster := &CloudStackCluster{
70-
TypeMeta: metav1.TypeMeta{
71-
APIVersion: apiVersion,
72-
Kind: clusterKind,
73-
},
74-
ObjectMeta: metav1.ObjectMeta{
75-
Name: clusterName,
76-
Namespace: clusterNamespace,
77-
UID: clusterID,
78-
},
79-
Spec: CloudStackClusterSpec{
80-
IdentityRef: &CloudStackIdentityReference{
81-
Kind: defaultIdentityRefKind,
82-
Name: identitySecretName,
83-
},
84-
Zone: zone,
85-
},
86-
}
87-
Expect(k8sClient.Create(ctx, cloudStackCluster).Error()).Should(MatchRegexp("admission webhook.*denied the request.*Required value\\: Network"))
78+
Ω(k8sClient.Create(ctx, cloudStackCluster).Error()).
79+
Should(MatchRegexp("admission webhook.*denied the request.*Required value\\: Network"))
8880
})
8981
})
9082

9183
Context("When creating a CloudStackCluster with missing Zone attribute", func() {
9284
It("Should be rejected by the validating webhooks", func() {
9385
ctx := context.Background()
94-
cloudStackCluster := &CloudStackCluster{
95-
TypeMeta: metav1.TypeMeta{
96-
APIVersion: apiVersion,
97-
Kind: clusterKind,
98-
},
99-
ObjectMeta: metav1.ObjectMeta{
100-
Name: clusterName,
101-
Namespace: clusterNamespace,
102-
UID: clusterID,
103-
},
104-
Spec: CloudStackClusterSpec{
105-
IdentityRef: &CloudStackIdentityReference{
106-
Kind: defaultIdentityRefKind,
107-
Name: identitySecretName,
108-
},
109-
Network: network,
110-
},
111-
}
112-
Expect(k8sClient.Create(ctx, cloudStackCluster).Error()).Should(MatchRegexp("admission webhook.*denied the request.*Required value\\: Zone"))
86+
Ω(k8sClient.Create(ctx, cloudStackCluster).Error()).
87+
Should(MatchRegexp("admission webhook.*denied the request.*Required value\\: Zone"))
11388
})
11489
})
11590

@@ -121,26 +96,8 @@ var _ = Describe("CloudStackCluster webhooks", func() {
12196

12297
It("Should be rejected by the validating webhooks", func() {
12398
ctx := context.Background()
124-
cloudStackCluster := &CloudStackCluster{
125-
TypeMeta: metav1.TypeMeta{
126-
APIVersion: apiVersion,
127-
Kind: clusterKind,
128-
},
129-
ObjectMeta: metav1.ObjectMeta{
130-
Name: clusterName,
131-
Namespace: clusterNamespace,
132-
UID: clusterID,
133-
},
134-
Spec: CloudStackClusterSpec{
135-
IdentityRef: &CloudStackIdentityReference{
136-
Kind: configMapKind,
137-
Name: configMapName,
138-
},
139-
Zone: zone,
140-
Network: network,
141-
},
142-
}
143-
Expect(k8sClient.Create(ctx, cloudStackCluster).Error()).Should(MatchRegexp("admission webhook.*denied the request.*Forbidden\\: must be a Secret"))
99+
Ω(k8sClient.Create(ctx, cloudStackCluster).Error()).
100+
Should(MatchRegexp("admission webhook.*denied the request.*Forbidden\\: must be a Secret"))
144101
})
145102

146103
Context("When updating a CloudStackCluster", func() {
@@ -152,59 +109,44 @@ var _ = Describe("CloudStackCluster webhooks", func() {
152109

153110
BeforeEach(func() {
154111
ctx = context.Background()
155-
cloudStackCluster = &CloudStackCluster{
156-
TypeMeta: metav1.TypeMeta{
157-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
158-
Kind: "CloudStackCluster",
159-
},
160-
ObjectMeta: metav1.ObjectMeta{
161-
Name: "test-cluster2",
162-
Namespace: clusterNamespace,
163-
},
164-
Spec: CloudStackClusterSpec{
165-
IdentityRef: &CloudStackIdentityReference{
166-
Kind: defaultIdentityRefKind,
167-
Name: identitySecretName,
168-
},
169-
Zone: zone,
170-
Network: network,
171-
// Need CP Endpoint not to be nil before test or webhook will allow modification.
172-
ControlPlaneEndpoint: clusterv1.APIEndpoint{Host: "fakeIP", Port: int32(1234)},
173-
},
174-
}
175112
cloudStackClusterUpdate = &CloudStackCluster{}
176113
})
177114

178115
It("Should be rejected by the validating webhooks", func() {
179-
Expect(k8sClient.Create(ctx, cloudStackCluster)).Should(Succeed())
116+
Ω(k8sClient.Create(ctx, cloudStackCluster)).Should(Succeed())
180117

181118
forbiddenRegex := "admission webhook.*denied the request.*Forbidden\\: %s"
182119

183120
cloudStackCluster.DeepCopyInto(cloudStackClusterUpdate)
184-
cloudStackClusterUpdate.Spec.Zone = "Zone2"
185-
Expect(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).Should(MatchRegexp(forbiddenRegex, "zone"))
121+
cloudStackClusterUpdate.Spec.Zones = []Zone{testZone2}
122+
Ω(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).
123+
Should(MatchRegexp(forbiddenRegex, "zone"))
186124

187125
cloudStackCluster.DeepCopyInto(cloudStackClusterUpdate)
188-
cloudStackClusterUpdate.Spec.Network = "Network2"
189-
Expect(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).Should(MatchRegexp(forbiddenRegex, "network"))
126+
//cloudStackClusterUpdate.Spec.Network = "Network2"
127+
Ω(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).
128+
Should(MatchRegexp(forbiddenRegex, "network"))
190129

191130
cloudStackCluster.DeepCopyInto(cloudStackClusterUpdate)
192131
cloudStackClusterUpdate.Spec.ControlPlaneEndpoint.Host = "1.1.1.1"
193-
Expect(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).Should(MatchRegexp(forbiddenRegex, "controlplaneendpointhost"))
132+
Ω(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).
133+
Should(MatchRegexp(forbiddenRegex, "controlplaneendpointhost"))
194134

195135
cloudStackCluster.DeepCopyInto(cloudStackClusterUpdate)
196136
cloudStackClusterUpdate.Spec.IdentityRef.Kind = "ConfigMap"
197-
Expect(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).Should(MatchRegexp(forbiddenRegex, "identityRef\\.Kind"))
137+
Ω(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).
138+
Should(MatchRegexp(forbiddenRegex, "identityRef\\.Kind"))
198139

199140
cloudStackCluster.DeepCopyInto(cloudStackClusterUpdate)
200141
cloudStackClusterUpdate.Spec.IdentityRef.Name = configMapName
201-
Expect(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).Should(MatchRegexp(forbiddenRegex, "identityRef\\.Name"))
142+
Ω(k8sClient.Update(ctx, cloudStackClusterUpdate).Error()).
143+
Should(MatchRegexp(forbiddenRegex, "identityRef\\.Name"))
202144
})
203145

204146
It("Should reject changing the port", func() {
205147
cloudStackCluster.DeepCopyInto(cloudStackClusterUpdate)
206148
cloudStackClusterUpdate.Spec.ControlPlaneEndpoint.Port = int32(1234)
207-
Expect(k8sClient.Update(ctx, cloudStackClusterUpdate)).ShouldNot(Succeed()) //(forbiddenRegex, "controlplaneendpointport"))
149+
Ω(k8sClient.Update(ctx, cloudStackClusterUpdate)).ShouldNot(Succeed())
208150
})
209151
})
210152
})

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)