Skip to content

Commit f84d7b1

Browse files
committed
bastion: document and guard how bastion is removed or updated
We now have a webhook that checks that a bastion has been disabled if a change has to be made (update or delete) in the bastion field. We also document it better.
1 parent 84e1f4e commit f84d7b1

File tree

7 files changed

+66
-6
lines changed

7 files changed

+66
-6
lines changed

api/v1alpha8/openstackcluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ type OpenStackClusterSpec struct {
155155
// Bastion is the OpenStack instance to login the nodes
156156
//
157157
// As a rolling update is not ideal during a bastion host session, we
158-
// prevent changes to a running bastion configuration. Set `enabled: false` to
159-
// make changes.
158+
// prevent changes to a running bastion configuration. To make changes, it's required
159+
// to first set `enabled: false` which will remove the bastion and then changes can be made.
160160
//+optional
161161
Bastion *Bastion `json:"bastion,omitempty"`
162162

api/v1alpha8/openstackcluster_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ func (r *OpenStackCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warn
116116
r.Spec.APIServerPort = 0
117117
}
118118

119+
// Allow to remove the bastion spec only if it was disabled before.
120+
if r.Spec.Bastion == nil {
121+
if old.Spec.Bastion != nil && old.Spec.Bastion.Enabled {
122+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "bastion"), "cannot be removed before disabling it"))
123+
}
124+
}
125+
119126
// Allow changes to the bastion spec.
120127
old.Spec.Bastion = &Bastion{}
121128
r.Spec.Bastion = &Bastion{}

api/v1alpha8/openstackcluster_webhook_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,42 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
358358
},
359359
wantErr: true,
360360
},
361+
{
362+
name: "Removing OpenStackCluster.Spec.Bastion when it is enabled is not allowed",
363+
oldTemplate: &OpenStackCluster{
364+
Spec: OpenStackClusterSpec{
365+
Bastion: &Bastion{
366+
Enabled: true,
367+
Instance: OpenStackMachineSpec{
368+
Flavor: "m1.small",
369+
Image: ImageFilter{Name: "ubuntu"},
370+
},
371+
},
372+
},
373+
},
374+
newTemplate: &OpenStackCluster{
375+
Spec: OpenStackClusterSpec{},
376+
},
377+
wantErr: true,
378+
},
379+
{
380+
name: "Removing OpenStackCluster.Spec.Bastion when it is disabled is allowed",
381+
oldTemplate: &OpenStackCluster{
382+
Spec: OpenStackClusterSpec{
383+
Bastion: &Bastion{
384+
Enabled: false,
385+
Instance: OpenStackMachineSpec{
386+
Flavor: "m1.small",
387+
Image: ImageFilter{Name: "ubuntu"},
388+
},
389+
},
390+
},
391+
},
392+
newTemplate: &OpenStackCluster{
393+
Spec: OpenStackClusterSpec{},
394+
},
395+
wantErr: false,
396+
},
361397
}
362398
for _, tt := range tests {
363399
t.Run(tt.name, func(t *testing.T) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4899,8 +4899,8 @@ spec:
48994899
49004900
49014901
As a rolling update is not ideal during a bastion host session, we
4902-
prevent changes to a running bastion configuration. Set `enabled: false` to
4903-
make changes.
4902+
prevent changes to a running bastion configuration. To make changes, it's required
4903+
to first set `enabled: false` which will remove the bastion and then changes can be made.
49044904
properties:
49054905
availabilityZone:
49064906
type: string

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,8 +2324,8 @@ spec:
23242324
23252325
23262326
As a rolling update is not ideal during a bastion host session, we
2327-
prevent changes to a running bastion configuration. Set `enabled: false` to
2328-
make changes.
2327+
prevent changes to a running bastion configuration. To make changes, it's required
2328+
to first set `enabled: false` which will remove the bastion and then changes can be made.
23292329
properties:
23302330
availabilityZone:
23312331
type: string

controllers/openstackcluster_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ func deleteBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackClust
263263
}
264264
}
265265

266+
// To remove the bastion, we need to get the instance spec. So when a user
267+
// wants to remove the OpenStackCluster.Spec.Bastion, they first need to set
268+
// the OpenStackCluster.Spec.Bastion.Enabled to false so here we can still get
269+
// the instance spec and delete the bastion. Then changes can be made to the
270+
// OpenStackCluster.Spec.Bastion.
266271
instanceSpec := bastionToInstanceSpec(openStackCluster, cluster.Name)
267272
if err = computeService.DeleteInstance(openStackCluster, openStackCluster, instanceStatus, instanceSpec); err != nil {
268273
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete bastion: %w", err))

docs/book/src/clusteropenstack/configuration.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
- [Custom pod network CIDR](#custom-pod-network-cidr)
3636
- [Accessing nodes through the bastion host via SSH](#accessing-nodes-through-the-bastion-host-via-ssh)
3737
- [Enabling the bastion host](#enabling-the-bastion-host)
38+
- [Making changes to the bastion host](#making-changes-to-the-bastion-host)
39+
- [Disabling the bastion](#disabling-the-bastion)
3840
- [Obtain floating IP address of the bastion node](#obtain-floating-ip-address-of-the-bastion-node)
3941

4042
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -654,6 +656,16 @@ spec:
654656

655657
If `managedSecurityGroups: true`, security group rule opening 22/tcp is added to security groups for bastion, controller, and worker nodes respectively. Otherwise, you have to add `securityGroups` to the `bastion` in `OpenStackCluster` spec and `OpenStackMachineTemplate` spec template respectively.
656658

659+
### Making changes to the bastion host
660+
661+
Changes can be made to the bastion instance, like for example changing the flavor.
662+
First, you have to disable the bastion host by setting `enabled: false` in the `OpenStackCluster.Spec.Bastion` field. Then, you can make changes to the instance spec and re-enable the bastion host by setting `enabled: true` and by modifying the `OpenStackCluster.Spec.Bastion.Instance` field.
663+
664+
### Disabling the bastion
665+
666+
To disable the bastion host, set `enabled: false` in the `OpenStackCluster.Spec.Bastion` field. The bastion host will be deleted.
667+
Then you can remove the `OpenStackCluster.Spec.Bastion` field from the `OpenStackCluster` spec.
668+
657669
### Obtain floating IP address of the bastion node
658670

659671
Once the workload cluster is up and running after being configured for an SSH bastion host, you can use the kubectl get openstackcluster command to look up the floating IP address of the bastion host (make sure the kubectl context is set to the management cluster). The output will look something like this:

0 commit comments

Comments
 (0)