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

HACK: Ensure the clusterName is managed consistently... #7

Conversation

davidfestal
Copy link
Member

We should not allow any operation that results in an object having an empty clusterName.

@davidfestal
Copy link
Member Author

This PR is a followup of PR #4, especially this comment especially this sentence:

that's a code smell because it's almost a certainty we'll have a bug in the long run where you do not want to risk an empty string

} else {
klog.Infof("NO SUB: %T %s", curObj, clusterName)
}
if clusterName == "" {
Copy link

Choose a reason for hiding this comment

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

You can't make this change because it would break normal usage of kubernetes starting kube-apiserver. That's what can't change in the serving chain. Inside kube-apiserver's lower layers you can't assume the cluster context is present. In other places (like client, or code that MUST have cluster name), you can error if it's not present.

Principle: our "added hacks" still have to not break the behavior of the k/k repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree on the principle of not to break the behavior of the k/k repo so I obviously missed some of the impacts here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean that I should only emit error logs but not fail at all the places where I check for valid cluster presence in the storage/etcd3 files such as the follownig places:

Copy link

Choose a reason for hiding this comment

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

Can we add some flag to reject requests without a cluster context? I agree we shouldn't break k/k but it's also useful in our usage to reject requests that don't make sense for us.

@davidfestal
Copy link
Member Author

@smarterclayton I changed the code to only emit error logs, but not fail, at all the places where I check for a valid cluster presence in the storage/etcd3 files.
Do you think the PR is OK for you now ?
It would be great if we could merge it and point KCP to the merged commit, since it also fixes a case when the clusterName was not correctly retrieved (here for example)

if headerCluster != "" {
req.Header.Add("X-Kubernetes-Cluster", headerCluster)
if headerCluster == "" {
return nil, fmt.Errorf("Cluster should not be empty for request '%s' on resource '%s' (%s)", requestInfo.Verb, requestInfo.Resource, requestInfo.Path)
Copy link

Choose a reason for hiding this comment

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

You can use %q instead of '%s' to get quoted strings using fmt.

We should not allow any operation that results in an object having an empty `clusterName`
For etcd3 storage functions, we only emit a warning, in order to avoid breaking normal usage of kubernetes starting kube-apiserver.

Signed-off-by: David Festal <dfestal@redhat.com>
@davidfestal davidfestal changed the title Ensure the clusterName is managed consistently... HACK: Ensure the clusterName is managed consistently... Jul 13, 2021
@davidfestal davidfestal merged commit 27a078d into kcp-dev:feature-logical-clusters Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants