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

🌱 WithClusterScope: should not assign a default cluster name #1871

Conversation

p0lyn0mial
Copy link
Contributor

Summary

clients should specify a cluster name before storing something in the db as that leads to more readable code.
the server should not assign a default cluster name.

at the moment requests without a cluster name are rejected by the storage layer.

Things to consider:
reject a request without a name in the filter
will this break some external clients?

Related issue(s)

Fixes #

@openshift-ci openshift-ci bot requested review from davidfestal and sttts August 31, 2022 15:25
@p0lyn0mial
Copy link
Contributor Author

/assign @stevekuznetsov @sttts

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

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

This is one of those super ancient decisions that I don't actually have any memory for why we did it. Hard to think through the implications.

@davidfestal thoughts?

@ncdc
Copy link
Member

ncdc commented Aug 31, 2022

IIRC it was to get "unaware" clients (e.g. kube internals) to succeed in their work (e.g. to create default RBAC resources) in some logical cluster.

I'm in favor of proceeding to remove the defaulting and trying to fix any remaining clients that were relying on this default.

@p0lyn0mial
Copy link
Contributor Author

/retest

@p0lyn0mial
Copy link
Contributor Author

IIRC it was to get "unaware" clients (e.g. kube internals) to succeed in their work (e.g. to create default RBAC resources) in some logical cluster.

I think it was achieved by providing multiClusterClientConfigRoundTripper.

@ncdc
Copy link
Member

ncdc commented Sep 1, 2022

E0901 06:16:38.200882   38061 errors.go:77] cluster name is empty in the request context - RequestInfo: &request.RequestInfo{IsResourceRequest:false, Path:"/livez", Verb:"get", APIPrefix:"", APIGroup:"", APIVersion:"", Namespace:"", Resource:"", Subresource:"", Name:"", Parts:[]string(nil)}

@stevekuznetsov
Copy link
Contributor

(and we've since learned that of course unaware clients doing "something" without being multi-cluster-aware just do nothing important whatsoever in the root logical cluster ... and no importance in supporting that)

@p0lyn0mial p0lyn0mial force-pushed the with-cluster-scope-no-default-value branch from f9f3c01 to 2f9b592 Compare September 2, 2022 13:37
@@ -272,7 +272,7 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque
logger := klog.FromContext(ctx)
lcluster, err := request.ValidClusterFrom(ctx)
if err != nil {
responsewriters.InternalError(rw, req, err)
h.apiHandler.ServeHTTP(rw, req)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it looks like the home-ws is first in the chain, capturing healthz/readyz as well.

@p0lyn0mial p0lyn0mial force-pushed the with-cluster-scope-no-default-value branch from 2f9b592 to 402f45f Compare September 5, 2022 09:04
@p0lyn0mial
Copy link
Contributor Author

I almost have it, a few unit tests require fixing.

@@ -584,6 +584,7 @@ func testWorkspacesVirtualWorkspaces(t *testing.T, standalone bool) {
// write kubeconfig to disk, next to kcp kubeconfig
kcpAdminConfig, _ := server.RawConfig()
var baseCluster = *kcpAdminConfig.Clusters["base"] // shallow copy
baseCluster.Server = fmt.Sprintf("%s/clusters/system:admin", baseCluster.Server)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

alternatively, we could add something to a handler but having a cluster name here is much cleaner.

@sttts
Copy link
Member

sttts commented Sep 9, 2022

How is this going? Any blocker?

@ncdc ncdc changed the title WithClusterScope: should not assign a default cluster name 🌱 WithClusterScope: should not assign a default cluster name Sep 9, 2022
@p0lyn0mial
Copy link
Contributor Author

How is this going? Any blocker?

I need to fix a few failing unit tests and this is ready to go.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 12, 2022
@p0lyn0mial p0lyn0mial force-pushed the with-cluster-scope-no-default-value branch from 402f45f to 637e428 Compare September 14, 2022 15:09
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 14, 2022
lcluster, err := request.ValidClusterFrom(ctx)
if err != nil {
responsewriters.InternalError(rw, req, err)
lcluster := request.ClusterFrom(req.Context())
Copy link
Contributor Author

@p0lyn0mial p0lyn0mial Sep 14, 2022

Choose a reason for hiding this comment

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

I'll follow up with a PR that removes the usage of ValidClusterFrom from the authorizers.

I think that we should also refactor our fork and use only ValidClusterFrom on the storage layer.

@p0lyn0mial
Copy link
Contributor Author

okay ci/prow/test is green, PTAL.

@@ -121,7 +120,7 @@ func WithClusterScope(apiHandler http.Handler) http.HandlerFunc {
// fallthrough
cluster.Name = logicalcluster.Wildcard
case clusterName.Empty():
cluster.Name = genericcontrolplane.LocalAdminCluster
Copy link
Member

Choose a reason for hiding this comment

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

if we get rid of cluster.Wildcard, i don't even think we need the logic in here. instead:

if clusterName != logicalcluster.Wildcard {
  // do regex check
}
cluster.Name = clusterName

Copy link
Member

Choose a reason for hiding this comment

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

can do in a follow-up if you want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know we were planning to get rid of cluster.Wildcard. I can do that in a follow-up.
Meanwhile, I removed the case when the clusterName was empty. We will make use of the default value.

Copy link
Member

Choose a reason for hiding this comment

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

It has no value any more, since you can compare against logicalcluster.Wildcard 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think the same arguments used to not have a .Wildcard for shard name apply here

@p0lyn0mial p0lyn0mial force-pushed the with-cluster-scope-no-default-value branch from 637e428 to 5f9bfa5 Compare September 15, 2022 08:23
clients should specify a cluster name before storing something in the db as that leads to more readable code.
the server should not assing a default cluster name.

at the moment requests without a cluster name are rejected by the storage layer.
@@ -121,7 +120,7 @@ func WithClusterScope(apiHandler http.Handler) http.HandlerFunc {
// fallthrough
cluster.Name = logicalcluster.Wildcard
case clusterName.Empty():
cluster.Name = genericcontrolplane.LocalAdminCluster
Copy link
Member

Choose a reason for hiding this comment

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

It has no value any more, since you can compare against logicalcluster.Wildcard 😄

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 15, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 15, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ncdc

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 15, 2022
@openshift-merge-robot openshift-merge-robot merged commit 8ccf2c4 into kcp-dev:main Sep 15, 2022
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants