Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Prevent the bastion to be removed before it's been disabled #1866

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

EmilienM
Copy link
Contributor

@EmilienM EmilienM commented Feb 6, 2024

What this PR does / why we need it:

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.

Also, we added some code to prevent that we don't have a nil pointer if
the Spec.Bastion or Status.Bastion are unset.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1855

TODOs:

  • squashed commits
  • if necessary:
    • includes documentation
    • adds unit tests

Copy link

netlify bot commented Feb 6, 2024

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit 20f2a3c
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/65c3b960d880180009440531
😎 Deploy Preview https://deploy-preview-1866--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 6, 2024
@k8s-ci-robot k8s-ci-robot requested review from dulek and mdbooth February 6, 2024 23:18
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 6, 2024
@EmilienM
Copy link
Contributor Author

EmilienM commented Feb 6, 2024

I manually tested it and it worked:

# openstackclusters.infrastructure.cluster.x-k8s.io "development-29561-rxprv" was not valid:
# * spec.bastion: Forbidden: cannot be removed before disabling it

@@ -116,6 +116,13 @@ func (r *OpenStackCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warn
r.Spec.APIServerPort = 0
}

// Allow to remove the bastion spec only if it was disabled before.
if r.Spec.Bastion == nil {
if old.Spec.Bastion != nil && old.Spec.Bastion.Enabled {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that I didn't add a guard to compare the old instance with the new one because there are complicated objects with filters. If we want to go down that path, let me know although I'm not sure it's desired.

Otherwise let me know if the doc content is enough.

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.

Also, we added some code to prevent that we don't have a nil pointer if
the Spec.Bastion or Status.Bastion are unset.
@EmilienM EmilienM changed the title 🐛 bastion: document and guard how bastion is removed or updated 🐛 Prevent the bastion to be removed before it's been disabled Feb 7, 2024
@huxcrux
Copy link
Contributor

huxcrux commented Feb 9, 2024

Looks good, the more detailed documentation looks to be easy to follow 👍

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 9, 2024
Copy link
Contributor

@mdbooth mdbooth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you fancy writing an e2e test for this? We keep breaking it.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: EmilienM, mdbooth

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 14, 2024
@EmilienM
Copy link
Contributor Author

How do you fancy writing an e2e test for this? We keep breaking it.

On my list: #1822
My only problem is the limited amount of hours that we have per day.

@k8s-ci-robot k8s-ci-robot merged commit 8ca470a into kubernetes-sigs:main Feb 14, 2024
9 checks passed
@EmilienM EmilienM deleted the issue_1855 branch February 14, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing Bastion instance spec doesn't work
5 participants