Skip to content

Commit 51b0661

Browse files
author
Joshua Reed
committed
Merge branch 'main' into feature/subdomain-user-operations
2 parents 71d594c + 0507507 commit 51b0661

30 files changed

+755
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ nginx.conf
1111
nginx.conf.bak
1212

1313
pkg/mocks/*
14+
pkg/cloud/gomock_reflect_*
1415
!pkg/mocks/.keep
1516

1617
# Various build/test artifacts.

PROJECT

+9
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,13 @@ resources:
6868
kind: CloudStackAffinityGroup
6969
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
7070
version: v1beta1
71+
- api:
72+
crdVersion: v1
73+
namespaced: true
74+
controller: true
75+
domain: cluster.x-k8s.io
76+
group: infrastructure
77+
kind: CloudStackMachineStateChecker
78+
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
79+
version: v1beta1
7180
version: "3"

api/v1beta1/cloudstackmachine_types.go

+16
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ type CloudStackMachineSpec struct {
4848
// CloudStack template to use.
4949
Template CloudStackResourceIdentifier `json:"template"`
5050

51+
// CloudStack disk offering to use.
52+
// +optional
53+
DiskOffering CloudStackResourceDiskOffering `json:"diskOffering,omitempty"`
54+
5155
// CloudStack ssh key to use.
5256
// +optional
5357
SSHKey string `json:"sshKey"`
@@ -95,6 +99,18 @@ type CloudStackResourceIdentifier struct {
9599
Name string `json:"name,omitempty"`
96100
}
97101

102+
type CloudStackResourceDiskOffering struct {
103+
CloudStackResourceIdentifier `json:",inline"`
104+
// mount point the data disk uses to mount. The actual partition, mkfs and mount are done by cloud-init generated by kubeadmConfig.
105+
MountPath string `json:"mountPath"`
106+
// device name of data disk, for example /dev/vdb
107+
Device string `json:"device"`
108+
// filesystem used by data disk, for example, ext4, xfs
109+
Filesystem string `json:"filesystem"`
110+
// label of data disk, used by mkfs as label parameter
111+
Label string `json:"label"`
112+
}
113+
98114
// TODO: Review the use of this field/type.
99115
type InstanceState string
100116

api/v1beta1/cloudstackmachine_webhook.go

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) error {
8282
oldSpec := oldMachine.Spec
8383

8484
errorList = webhookutil.EnsureBothFieldsAreEqual(r.Spec.Offering.ID, r.Spec.Offering.Name, oldSpec.Offering.ID, oldSpec.Offering.Name, "offering", errorList)
85+
errorList = webhookutil.EnsureBothFieldsAreEqual(r.Spec.DiskOffering.ID, r.Spec.DiskOffering.Name, oldSpec.DiskOffering.ID, oldSpec.DiskOffering.Name, "diskOffering", errorList)
86+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.DiskOffering.MountPath, oldSpec.DiskOffering.MountPath, "mountPath", errorList)
87+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.DiskOffering.Device, oldSpec.DiskOffering.Device, "device", errorList)
88+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.DiskOffering.Filesystem, oldSpec.DiskOffering.Filesystem, "filesystem", errorList)
89+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.DiskOffering.Label, oldSpec.DiskOffering.Label, "label", errorList)
8590
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
8691
errorList = webhookutil.EnsureBothFieldsAreEqual(r.Spec.Template.ID, r.Spec.Template.Name, oldSpec.Template.ID, oldSpec.Template.Name, "template", errorList)
8792
errorList = webhookutil.EnsureStringStringMapFieldsAreEqual(&r.Spec.Details, &oldSpec.Details, "details", errorList)

api/v1beta1/cloudstackmachine_webhook_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ var _ = Describe("CloudStackMachine webhook", func() {
4141
Expect(k8sClient.Create(ctx, dummies.CSMachine1)).Should(Succeed())
4242
})
4343

44+
It("should accept a CloudStackMachine with disk Offering attribute", func() {
45+
dummies.CSMachine1.Spec.DiskOffering = dummies.DiskOffering2
46+
Expect(k8sClient.Create(ctx, dummies.CSMachine1)).Should(Succeed())
47+
})
48+
4449
It("should reject a CloudStackMachine with missing Offering attribute", func() {
4550
dummies.CSMachine1.Spec.Offering = v1beta1.CloudStackResourceIdentifier{ID: "", Name: ""}
4651
Expect(k8sClient.Create(ctx, dummies.CSMachine1)).
@@ -77,6 +82,12 @@ var _ = Describe("CloudStackMachine webhook", func() {
7782
Should(MatchError(MatchRegexp(forbiddenRegex, "template")))
7883
})
7984

85+
It("should reject VM disk offering updates to the CloudStackMachine", func() {
86+
dummies.CSMachine1.Spec.DiskOffering = dummies.DiskOffering2
87+
Ω(k8sClient.Update(ctx, dummies.CSMachine1)).
88+
Should(MatchError(MatchRegexp(forbiddenRegex, "diskOffering")))
89+
})
90+
8091
It("should reject updates to VM details of the CloudStackMachine", func() {
8192
dummies.CSMachine1.Spec.Details = map[string]string{"memoryOvercommitRatio": "1.5"}
8293
Ω(k8sClient.Update(ctx, dummies.CSMachine1)).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// CloudStackMachineStateCheckerSpec
24+
type CloudStackMachineStateCheckerSpec struct {
25+
// CloudStack machine instance ID
26+
InstanceID string `json:"instanceID,omitempty"`
27+
}
28+
29+
// CloudStackMachineStateCheckerStatus defines the observed state of CloudStackMachineStateChecker
30+
type CloudStackMachineStateCheckerStatus struct {
31+
// Reflects the readiness of the Machine State Checker.
32+
Ready bool `json:"ready"`
33+
}
34+
35+
//+kubebuilder:object:root=true
36+
//+kubebuilder:subresource:status
37+
38+
// CloudStackMachineStateChecker is the Schema for the cloudstackmachinestatecheckers API
39+
type CloudStackMachineStateChecker struct {
40+
metav1.TypeMeta `json:",inline"`
41+
metav1.ObjectMeta `json:"metadata,omitempty"`
42+
43+
Spec CloudStackMachineStateCheckerSpec `json:"spec,omitempty"`
44+
Status CloudStackMachineStateCheckerStatus `json:"status,omitempty"`
45+
}
46+
47+
//+kubebuilder:object:root=true
48+
49+
// CloudStackMachineStateCheckerList contains a list of CloudStackMachineStateChecker
50+
type CloudStackMachineStateCheckerList struct {
51+
metav1.TypeMeta `json:",inline"`
52+
metav1.ListMeta `json:"metadata,omitempty"`
53+
Items []CloudStackMachineStateChecker `json:"items"`
54+
}
55+
56+
func init() {
57+
SchemeBuilder.Register(&CloudStackMachineStateChecker{}, &CloudStackMachineStateCheckerList{})
58+
}

api/v1beta1/cloudstackmachinetemplate_webhook.go

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) error {
9797

9898
errorList := field.ErrorList(nil)
9999
errorList = webhookutil.EnsureBothFieldsAreEqual(spec.Offering.ID, spec.Offering.Name, oldSpec.Offering.ID, oldSpec.Offering.Name, "offering", errorList)
100+
errorList = webhookutil.EnsureBothFieldsAreEqual(spec.DiskOffering.ID, spec.DiskOffering.Name, oldSpec.DiskOffering.ID, oldSpec.DiskOffering.Name, "diskOffering", errorList)
100101
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
101102
errorList = webhookutil.EnsureBothFieldsAreEqual(spec.Template.ID, spec.Template.Name, oldSpec.Template.ID, oldSpec.Template.Name, "template", errorList)
102103
errorList = webhookutil.EnsureStringStringMapFieldsAreEqual(&spec.Details, &oldSpec.Details, "details", errorList)

api/v1beta1/cloudstackmachinetemplate_webhook_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ var _ = Describe("CloudStackMachineTemplate webhook", func() {
4141
Expect(k8sClient.Create(ctx, dummies.CSMachineTemplate1)).Should(Succeed())
4242
})
4343

44+
It("Should accept a CloudStackMachineTemplate when missing the VM Disk Offering attribute", func() {
45+
dummies.CSMachineTemplate1.Spec.Spec.Spec.DiskOffering = v1beta1.CloudStackResourceDiskOffering{
46+
CloudStackResourceIdentifier: v1beta1.CloudStackResourceIdentifier{Name: "", ID: ""},
47+
}
48+
Expect(k8sClient.Create(ctx, dummies.CSMachineTemplate1)).Should(Succeed())
49+
})
50+
4451
It("Should reject a CloudStackMachineTemplate when missing the VM Offering attribute", func() {
4552
dummies.CSMachineTemplate1.Spec.Spec.Spec.Offering = v1beta1.CloudStackResourceIdentifier{Name: "", ID: ""}
4653
Expect(k8sClient.Create(ctx, dummies.CSMachineTemplate1)).
@@ -71,6 +78,13 @@ var _ = Describe("CloudStackMachineTemplate webhook", func() {
7178
Should(MatchError(MatchRegexp(forbiddenRegex, "template")))
7279
})
7380

81+
It("should reject VM disk offering updates to the CloudStackMachineTemplate", func() {
82+
dummies.CSMachineTemplate1.Spec.Spec.Spec.DiskOffering = v1beta1.CloudStackResourceDiskOffering{
83+
CloudStackResourceIdentifier: v1beta1.CloudStackResourceIdentifier{Name: "DiskOffering2"}}
84+
Ω(k8sClient.Update(ctx, dummies.CSMachineTemplate1)).
85+
Should(MatchError(MatchRegexp(forbiddenRegex, "diskOffering")))
86+
})
87+
7488
It("should reject VM offering updates to the CloudStackMachineTemplate", func() {
7589
dummies.CSMachineTemplate1.Spec.Spec.Spec.Offering = v1beta1.CloudStackResourceIdentifier{Name: "Offering2"}
7690
Ω(k8sClient.Update(ctx, dummies.CSMachineTemplate1)).

api/v1beta1/zz_generated.deepcopy.go

+106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackmachines.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,36 @@ spec:
113113
type: string
114114
description: Optional details map for deployVirtualMachine
115115
type: object
116+
diskOffering:
117+
description: CloudStack disk offering to use.
118+
properties:
119+
device:
120+
description: device name of data disk, for example /dev/vdb
121+
type: string
122+
filesystem:
123+
description: filesystem used by data disk, for example, ext4,
124+
xfs
125+
type: string
126+
id:
127+
description: Cloudstack resource ID.
128+
type: string
129+
label:
130+
description: label of data disk, used by mkfs as label parameter
131+
type: string
132+
mountPath:
133+
description: mount point the data disk uses to mount. The actual
134+
partition, mkfs and mount are done by cloud-init generated by
135+
kubeadmConfig.
136+
type: string
137+
name:
138+
description: Cloudstack resource Name
139+
type: string
140+
required:
141+
- device
142+
- filesystem
143+
- label
144+
- mountPath
145+
type: object
116146
id:
117147
description: ID.
118148
type: string

0 commit comments

Comments
 (0)