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

✨ Add inactive annotation to logicalcluster #3152

Merged
merged 2 commits into from
Aug 26, 2024

Conversation

RedbackThomson
Copy link
Contributor

@RedbackThomson RedbackThomson commented Aug 16, 2024

Summary

In order to do maintenance on a workspace, without controllers reconciling the resources inside the window during the maintenance period, I need a mechanism by which to disable access to the workspace. This feature adds a new optional annotation to LogicalCluster which disables API access through to the resource while present:

internal.kcp.io/inactive: "true"

All requests to the logical cluster while the annotation is set are denied with a 400 error, except for requests to CRUD the logical cluster itself or the OpenAPI spec (so that you can reasonably disable the annotation).

Related issue(s)

None

Release Notes

Add support for `internal.kcp.io/inactive` annotation on logical clusters to forbid any access beyond logical clusters.

@kcp-ci-bot kcp-ci-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: no Indicates the PR's author has not signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 16, 2024
@kcp-ci-bot
Copy link
Contributor

Hi @RedbackThomson. Thanks for your PR.

I'm waiting for a kcp-dev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@kcp-ci-bot kcp-ci-bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 16, 2024
@kcp-ci-bot kcp-ci-bot added dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels Aug 16, 2024
@@ -445,6 +445,7 @@ func NewConfig(opts kcpserveroptions.CompletedOptions) (*Config, error) {
apiHandler = filters.WithWarningRecorder(apiHandler)

apiHandler = kcpfilters.WithAuditEventClusterAnnotation(apiHandler)
apiHandler = kcpfilters.WithBlockInactiveLogicalClusters(apiHandler, c.KcpSharedInformerFactory.Core().V1alpha1().LogicalClusters())
Copy link
Member

Choose a reason for hiding this comment

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

Wondering, what speaks against putting it just before auth, i.e. line 411 or 426 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I honestly had no intuition as to where it should go. Let me know :)

if err == nil {
if ann, ok := logicalCluster.ObjectMeta.Annotations[inactiveAnnotation]; ok && ann == "true" {
responsewriters.ErrorNegotiated(
apierrors.NewBadRequest("logical cluster is marked inactive"),
Copy link
Member

Choose a reason for hiding this comment

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

400 is explicitly a client error. Looking through the list

403 Forbidden
423 Locked
503 Service Unavailable

What do we return when accessing a logical cluster without the LogicalCluster object? 403 I assume? Maybe that would be the right response here too.

@sttts
Copy link
Member

sttts commented Aug 17, 2024

Wondering, a small e2e test would be good.

@sttts
Copy link
Member

sttts commented Aug 17, 2024

/ok-to-test

@kcp-ci-bot kcp-ci-bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 17, 2024
@sttts
Copy link
Member

sttts commented Aug 17, 2024

What about discovery? Should we allow that?

Why do you need OpenAPI (am just curious) ?

@embik
Copy link
Member

embik commented Aug 17, 2024

What kind of maintenance would this feature allow? If everything except the LogicalCluster is blocked, what can you reasonably do during a maintenance window?

@RedbackThomson
Copy link
Contributor Author

What about discovery? Should we allow that?

Why do you need OpenAPI (am just curious) ?

Without the OpenAPI endpoint, kubectl edit logicalcluster was failing. I imagine this is because it does CRD discovery first, which was being blocked. I figured that it didn't hurt to have this endpoint open except for the case where a client may use OpenAPI discovery as a health check to see if the cluster is accessible.

@RedbackThomson
Copy link
Contributor Author

What kind of maintenance would this feature allow? If everything except the LogicalCluster is blocked, what can you reasonably do during a maintenance window?

My use case is that I'm rebuilding the cluster by restoring from an etcd snapshot and in that time I don't want controllers to access resources before they're fully reapplied.

@kcp-ci-bot kcp-ci-bot added dco-signoff: no Indicates the PR's author has not signed the DCO. and removed dco-signoff: yes Indicates the PR's author has signed the DCO. labels Aug 22, 2024
Signed-off-by: Nicholas Thomson <[email protected]>
@kcp-ci-bot kcp-ci-bot added dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels Aug 22, 2024
@RedbackThomson
Copy link
Contributor Author

/retest-required

@sttts
Copy link
Member

sttts commented Aug 26, 2024

/lgtm
/approve

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 26, 2024
@kcp-ci-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 17f26e8c7f809b8d8a7fc1bf6e62df8cdffef172

@kcp-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

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

@kcp-ci-bot kcp-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 26, 2024
@kcp-ci-bot kcp-ci-bot merged commit d2ffee0 into kcp-dev:main Aug 26, 2024
16 checks passed
@embik
Copy link
Member

embik commented Aug 27, 2024

/kind feature

@kcp-ci-bot kcp-ci-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 27, 2024
@RedbackThomson RedbackThomson deleted the inactive_workspaces branch August 27, 2024 15:37
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. dco-signoff: yes Indicates the PR's author has signed the DCO. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

4 participants