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

Allow using a ClusterClass across namespaces #5673

Open
fabriziopandini opened this issue Nov 16, 2021 · 40 comments · May be fixed by #11395
Open

Allow using a ClusterClass across namespaces #5673

fabriziopandini opened this issue Nov 16, 2021 · 40 comments · May be fixed by #11395
Assignees
Labels
area/clusterclass Issues or PRs related to clusterclass help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@fabriziopandini
Copy link
Member

User Story

As a user/operator I would like to define ClusterClass once and reuse it across many namespaces
As a user/operator I would like to define the namespaces my ClusterClass can be used from

Detailed Description

As of today ClusterClass is a namespaced object, and the Cluster.spec.topology.class is a simple name

This works well under some many circumstances, but this approach does not works well in use cases when clusters are deployed in several namespaces/managed by different tenants, but the organisation providing ClusterCluster class is only one.

This issue is about discussing how to allow users a simple an straightforward experience in the use case above.

A possible approach requires two changes:

  • make Cluster.spec.topology.class a namespaced name; if the namespace part is missing it defaults to current namespace
  • add to ClusterClass allowedNamespace, like in

Whenever a Cluster is created, we are going to check if allowedNamespaces are defined; if yes, the ClusterNamespace should be in that list, otherwise the operation is denied; most probably we should make a similar check at reconcile time.

Other things that should be considered, are e.g validation check when modifying a ClusterClass; in this case, if allowedNamespaces are defined, we should check for corresponding Cluster in a list of namespaces; similarly, the change of allowedNamespaces field itself should account for those Clusters to exist before allowing the operation.

Anything else you would like to add:

Prior art for this approach:

/kind feature

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 16, 2021
@fabriziopandini
Copy link
Member Author

/area topology
/milestone v1.1

@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Nov 16, 2021
@fabriziopandini
Copy link
Member Author

NOTE: I'm assuming a ClusterClass and its referenced templates should be in a single namespace as of today; the Cluster only can be in a different namespace

@sbueringer
Copy link
Member

clusterctl move currently moves an entire namespace. Because up until now Clusters and their ClusterClasses had to be in the same namespace we could just move all Clusters and ClusterClasses of the respective namespaces (but of course in the right order).

The feature that ClusterClasses can be in another namespace changes our assumptions, so we have to think about how clusterctl move should behave in those cases.

@killianmuldoon
Copy link
Contributor

Would it be more user friendly to change class to a struct with name and namespace(defaulting to cluster namespace if unset? This would mirror what we're doing elsewhere at least and avoids adding new patterns which might be confusing - I think making it a namespaced name could be tough for new users to understand
.

@sbueringer
Copy link
Member

sbueringer commented Nov 18, 2021

I think you both mean the same thing: types.NamespacedName:

type NamespacedName struct {
	Namespace string
	Name      string
}

https://github.com/kubernetes/apimachinery/blob/master/pkg/types/namespacedname.go#L27-L30

@killianmuldoon
Copy link
Contributor

I think you both mean the same thing: types.NamespacedName:

That looks right - I was thinking class: "namespace/classname" was on the table as an option.

@ykakarap
Copy link
Contributor

/assign

@vincepri
Copy link
Member

class: "namespace/classname" this could make sense as it's not a breaking change

@killianmuldoon
Copy link
Contributor

note: #5717 adds some namespacing to webhook validation for clusterClass that will have to be addressed as part of this work.

@ykakarap
Copy link
Contributor

ykakarap commented Dec 2, 2021

note: #5717 adds some namespacing to webhook validation for clusterClass that will have to be addressed as part of this work.

Thanks for the heads up @killianmuldoon! :)

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 4, 2022
@fabriziopandini
Copy link
Member Author

/remove-lifecycle stale
/priority-important-soon
I think we should reconsider this given that ClusterClass adoption is growing...

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 8, 2022
@fabriziopandini fabriziopandini added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label May 8, 2022
@fabriziopandini
Copy link
Member Author

I'm considering moving on with the suggested approach; adding some more considerations

  • I would prefer to have consistency across CAP*, so I suggest adding allowed namespace to a ClusterClass, similar to what we have in CAPA
  • If allowedNamespace is empty, the ClusterClass can be used only within the same namespace, otherwise only in the namespaces specified (TBD if the same namespace is always included)
  • when modifying a CC, if there is a change to allowedNamespace, we should ensure that we are not "orphaning" Clusters actually using the CC
  • when deleting a CC, we should make sure that it is not used in other namespaces
  • whenever we are reading a CC for a given Cluster, we should make sure that the cluster is in one of the allowed namespaces

Note, in the first iteration, I think we should not consider changing clusterctl move to move CC outsides the namespace being moved, this requires a dedicated deep dive

@sbueringer
Copy link
Member

Sounds good, one comment:

  • we might want to not add NamespaceList if we're fine to say that a label selector against the kubernetes.io/metadata.name label is only safe / works (?) with Kubernetes >= 1.21

@CecileRobertMichon
Copy link
Contributor

+1

Another use case for this: in provider e2e tests, we provide one namespace per test cluster but want to reuse the same clusterclass and install it in BeforeSuite https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/2235/files#r865122163

@CecileRobertMichon
Copy link
Contributor

I would prefer to have consistency across CAP*, so I suggest adding allowed namespace to a ClusterClass, similar to what we have in CAPA
If allowedNamespace is empty, the ClusterClass can be used only within the same namespace, otherwise only in the namespaces specified (TBD if the same namespace is always included)

Not sure what CAPA does but in CAPZ if allowedNamespaces is empty it allows all namespaces (as opposed to only the current one) https://capz.sigs.k8s.io/topics/multitenancy.html#allowednamespaces

Would be beneficial for testing to be able to specify all namespaces since cluster name/namespace is randomly generated for each spec so it won't be known ahead of time in BeforeSuite

@sbueringer
Copy link
Member

sbueringer commented May 12, 2022

Another use case for this: in provider e2e tests, we provide one namespace per test cluster but want to reuse the same clusterclass and install it in BeforeSuite https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/2235/files#r865122163

I'm not sure if that is an issue. clusterctl generate automatically includes the ClusterClass when generating the Cluster (here).

In core CAPI today we use the same ClusterClass in multiple tests and it gets automatically applied in different namespaces because clusterctl generate includes it automatically. So if the requirement is only to reuse the same ClusterClass across multiple tests you don't have to explicitly install it via BeforeSuite. (we didn't implement any explicit ClusterClass deployment at all in core CAPI e2e tests)

EDIT: While it's possible to reuse the same ClusterClass in e2e tests by deploying it multiple times (and it's automatically included in the output of clusterctl generate cluster) it of course might be desirable to intentionally re-use one single deployed ClusterClass in multiple tests in different namespaces.

@fabriziopandini
Copy link
Member Author

Not sure what CAPA does but in CAPZ if allowedNamespaces is empty it allows all namespaces (as opposed to only the current one) https://capz.sigs.k8s.io/topics/multitenancy.html#allowednamespaces

I'm not opposed at this behavior as well, however, I'm worried if this is "unsecure", given that if the user forgets to specify allowedNamespaces in a ClasterClass it is accessible from everywhere (instead of defaulting to the more restrictive behavior).

@killianmuldoon
Copy link
Contributor

/unassign

Not work on this ATM

@salasberryfin
Copy link
Contributor

/assign

Would like to take a look at this. Perhaps we can add a topic to this week's meeting agenda to define an action plan on how this feature could be implemented.

@Danil-Grigorev
Copy link
Member

Should this issue be separated into two? It seems to me that for a general scenario, just adding a namespace/name will be enough to reference a cluster class (although a classNamespace field is preferable IMO). And the policy access considerations in the multi-tenant scenario can have a separate issue. WDYT?

@simonostendorf
Copy link

It seems to me that for a general scenario, just adding a #5673 (comment) will be enough to reference a cluster class (although a classNamespace field is preferable IMO).

I also think that the first solution could be the namespace/name reference for a ClusterClass. This would be enough for me.

@Danil-Grigorev
Copy link
Member

Service Gateway API moved their referential approach into KEP, and it was merged - https://github.com/kubernetes/enhancements/tree/master/keps/sig-auth/3766-referencegrant

They propose using ReferenceGrant resource as a policy for both side cross-namespace references. This allows to use any sort of namespace/name or

ref:
  name: <name>
  namespace: <namespace>

openly, with a future expectation that a reference grant resource can be checked before processing the reference and executing the logic behind it.

I think this is a clean approach, allowing to rely on expectation that in the future the regular namespace/name or ref can be secured, and does not require changes in the ClusterClass CRD to manage this policy (can be used as-is).
Until the ReferenceGrant support is fully added, a cross-namespace ClusterClass reference inside the cluster can trigger a warning in the webhook output, if the specified namespace is different from the one in the cluster.

What do you think, will this help moving this issue to a solution?

@k8s-triage-robot
Copy link

This issue is labeled with priority/important-soon but has not been updated in over 90 days, and should be re-triaged.
Important-soon issues must be staffed and worked on either currently, or very soon, ideally in time for the next release.

You can:

  • Confirm that this issue is still relevant with /triage accepted (org members only)
  • Deprioritize it with /priority important-longterm or /priority backlog
  • Close this issue with /close

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. and removed triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Jul 15, 2024
@sbueringer
Copy link
Member

/priority important-longterm

@k8s-ci-robot k8s-ci-robot added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. label Jul 15, 2024
@fabriziopandini
Copy link
Member Author

/triage accepted
Still something to figure out about the API, but overall there is consensus

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 31, 2024
@k8s-triage-robot
Copy link

This issue is labeled with priority/important-soon but has not been updated in over 90 days, and should be re-triaged.
Important-soon issues must be staffed and worked on either currently, or very soon, ideally in time for the next release.

You can:

  • Confirm that this issue is still relevant with /triage accepted (org members only)
  • Deprioritize it with /priority important-longterm or /priority backlog
  • Close this issue with /close

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. and removed triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Oct 29, 2024
@salasberryfin
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clusterclass Issues or PRs related to clusterclass help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.