Skip to content

Commit 2047c66

Browse files
authored
Merge pull request #297 from shiftstack/immutable-resources
Make ResourceSpec immutable until they are truly mutable
2 parents e52c93b + d8b59f7 commit 2047c66

16 files changed

Lines changed: 42 additions & 0 deletions

api/v1alpha1/image_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ type ImageHash struct {
277277
// +kubebuilder:validation:XValidation:rule="has(self.tags) ? self.tags == oldSelf.tags : !has(oldSelf.tags)",message="tags is immutable"
278278
// +kubebuilder:validation:XValidation:rule="has(self.visibility) ? self.visibility == oldSelf.visibility : !has(oldSelf.visibility)",message="visibility is immutable"
279279
// +kubebuilder:validation:XValidation:rule="has(self.properties) ? self.properties == oldSelf.properties : !has(oldSelf.properties)",message="properties is immutable"
280+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ImageResourceSpec is immutable"
280281
type ImageResourceSpec struct {
281282
// name will be the name of the created Glance image. If not specified, the
282283
// name of the Image object will be used.

api/v1alpha1/network_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type DNSDomain string
5454
type MTU int32
5555

5656
// NetworkResourceSpec contains the desired state of a network
57+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="NetworkResourceSpec is immutable"
5758
type NetworkResourceSpec struct {
5859
// name will be the name of the created resource. If not specified, the
5960
// name of the ORC object will be used.

api/v1alpha1/port_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type FixedIPStatus struct {
8888
SubnetID string `json:"subnetID,omitempty"`
8989
}
9090

91+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="PortResourceSpec is immutable"
9192
type PortResourceSpec struct {
9293
// name is a human-readable name of the port. If not set, the object's name will be used.
9394
// +optional

api/v1alpha1/router_interface_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const (
7474
)
7575

7676
// +kubebuilder:validation:XValidation:rule="self.type == 'Subnet' ? has(self.subnetRef) : !has(self.subnetRef)",message="subnetRef is required when type is 'Subnet' and not permitted otherwise"
77+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="RouterInterfaceResourceSpec is immutable"
7778
type RouterInterfaceSpec struct {
7879
// type specifies the type of the router interface.
7980
// +required

api/v1alpha1/router_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type ExternalGatewayStatus struct {
4444
NetworkID string `json:"networkID,omitempty"`
4545
}
4646

47+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="RouterResourceSpec is immutable"
4748
type RouterResourceSpec struct {
4849
// name is a human-readable name of the router. If not set, the
4950
// object's name will be used.

api/v1alpha1/securitygroup_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,24 @@ type SecurityGroupResourceSpec struct {
188188
// name will be the name of the created resource. If not specified, the
189189
// name of the ORC object will be used.
190190
// +optional
191+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Property is immutable"
191192
Name *OpenStackName `json:"name,omitempty"`
192193

193194
// description is a human-readable description for the resource.
194195
// +optional
196+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Property is immutable"
195197
Description *NeutronDescription `json:"description,omitempty"`
196198

197199
// tags is a list of tags which will be applied to the security group.
198200
// +kubebuilder:validation:MaxItems:=32
199201
// +listType=set
200202
// +optional
203+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Property is immutable"
201204
Tags []NeutronTag `json:"tags,omitempty"`
202205

203206
// stateful indicates if the security group is stateful or stateless.
204207
// +optional
208+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Property is immutable"
205209
Stateful *bool `json:"stateful,omitempty"`
206210

207211
// rules is a list of security group rules belonging to this SG.

api/v1alpha1/server_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type ServerPortSpec struct {
6161
}
6262

6363
// ServerResourceSpec contains the desired state of a server
64+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ServerResourceSpec is immutable"
6465
type ServerResourceSpec struct {
6566
// name will be the name of the created resource. If not specified, the
6667
// name of the ORC object will be used.

api/v1alpha1/subnet_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type SubnetFilter struct {
5959
FilterByNeutronTags `json:",inline"`
6060
}
6161

62+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="SubnetResourceSpec is immutable"
6263
type SubnetResourceSpec struct {
6364
// name is a human-readable name of the subnet. If not set, the object's name will be used.
6465
// +optional

config/crd/bases/openstack.k-orc.cloud_images.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ spec:
453453
- message: properties is immutable
454454
rule: 'has(self.properties) ? self.properties == oldSelf.properties
455455
: !has(oldSelf.properties)'
456+
- message: ImageResourceSpec is immutable
457+
rule: self == oldSelf
456458
required:
457459
- cloudCredentialsRef
458460
type: object

config/crd/bases/openstack.k-orc.cloud_networks.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ spec:
286286
type: array
287287
x-kubernetes-list-type: set
288288
type: object
289+
x-kubernetes-validations:
290+
- message: NetworkResourceSpec is immutable
291+
rule: self == oldSelf
289292
required:
290293
- cloudCredentialsRef
291294
type: object

0 commit comments

Comments
 (0)