Skip to content

Commit

Permalink
Allow webhook changes to OpenStackCluster.Spec.Bastion
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Giese <tobias.giese@daimler.com>
  • Loading branch information
tobiasgiese committed Dec 5, 2021
1 parent 006d55a commit 5be9181
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha4/openstackcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (r *OpenStackCluster) ValidateUpdate(oldRaw runtime.Object) error {
r.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{}
}

// Allow changes to the bastion spec.
r.Spec.Bastion = &Bastion{}
old.Spec.Bastion = &Bastion{}

if !reflect.DeepEqual(old.Spec, r.Spec) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
}
Expand Down
52 changes: 52 additions & 0 deletions api/v1alpha4/openstackcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,58 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
},
wantErr: false,
},
{
name: "OpenStackCluster.Spec.Bastion with mutable spec",
oldTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobar",
Image: "foobar",
Flavor: "minimal",
},
Enabled: false,
},
},
},
newTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobarbaz",
Image: "foobarbaz",
Flavor: "medium",
},
Enabled: true,
},
},
},
wantErr: false,
},
{
name: "empty OpenStackCluster.Spec.Bastion with mutable spec",
oldTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
},
},
newTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobar",
Image: "foobar",
Flavor: "medium",
},
Enabled: true,
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/openstackcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (r *OpenStackCluster) ValidateUpdate(oldRaw runtime.Object) error {
r.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{}
}

// Allow changes to the bastion spec.
r.Spec.Bastion = &Bastion{}
old.Spec.Bastion = &Bastion{}

if !reflect.DeepEqual(old.Spec, r.Spec) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
}
Expand Down
52 changes: 52 additions & 0 deletions api/v1beta1/openstackcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,58 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
},
wantErr: false,
},
{
name: "OpenStackCluster.Spec.Bastion with mutable spec",
oldTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobar",
Image: "foobar",
Flavor: "minimal",
},
Enabled: false,
},
},
},
newTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobarbaz",
Image: "foobarbaz",
Flavor: "medium",
},
Enabled: true,
},
},
},
wantErr: false,
},
{
name: "empty OpenStackCluster.Spec.Bastion with mutable spec",
oldTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
},
},
newTemplate: &OpenStackCluster{
Spec: OpenStackClusterSpec{
CloudName: "foobar",
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobar",
Image: "foobar",
Flavor: "medium",
},
Enabled: true,
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 5be9181

Please sign in to comment.