-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 classNamespace to topology #11352
base: main
Are you sure you want to change the base?
✨ Add classNamespace to topology #11352
Conversation
ae1cb19
to
43cb995
Compare
2bddeeb
to
352fd66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Danil-Grigorev! I added a small suggestion but I think this looks good.
docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md
Outdated
Show resolved
Hide resolved
352fd66
to
bd8a56f
Compare
Thanks @Danil-Grigorev /lgtm |
LGTM label has been added. Git tree hash: c4b418743a4683ae623b3264aae7636c41ad5675
|
/assign @chrischdi |
bd8a56f
to
4bbb218
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
4bbb218
to
d450768
Compare
LGTM label has been added. Git tree hash: f7b15d982fdfb8730cff97c2900ccbd9c661e3d9
|
docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md
Outdated
Show resolved
Hide resolved
docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md
Outdated
Show resolved
Hide resolved
@@ -371,7 +370,9 @@ func (r *Reconciler) clusterClassToCluster(ctx context.Context, o client.Object) | |||
// create a request for each of the clusters. | |||
requests := []ctrl.Request{} | |||
for i := range clusterList.Items { | |||
requests = append(requests, ctrl.Request{NamespacedName: util.ObjectKey(&clusterList.Items[i])}) | |||
if clusterList.Items[i].GetInfrastructureNamespace() == clusterClass.Namespace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a unit test ensuring that a change in a CC with a given name triggers reconcile only for clusters using it (and not for clusters using CC with the same name, but in another ns)
Possibly, this should cover both cluster with ClassNamespace set and not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for self: this seems still open no matter if it reports outdated
@@ -380,12 +380,19 @@ func (webhook *ClusterClass) getClustersUsingClusterClass(ctx context.Context, c | |||
clusters := &clusterv1.ClusterList{} | |||
err := webhook.Client.List(ctx, clusters, | |||
client.MatchingFields{index.ClusterClassNameField: clusterClass.Name}, | |||
client.InNamespace(clusterClass.Namespace), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should update the index, so it contains both namespace and name of the cluster class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking a little bit more about this, I think we change this index so performance in the webhook are optimized and also the resulting code will be more readable (both here and in clusterClassToCluster)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that in this method there is not enough information to know cluster namespace due to duality of the namespace reference.
If an index is added, there will be another Client.List
call for client.MatchingFields{index.ClusterClassNamespaceField: clusterClass.Namespace}
, and here I’m not sure how would an empty field be treated - matching an empty string or matching no selector at all?
If the first one the case, then the method will combine two list responses, and it will be more readable. If not, it will only increase the number of calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, seems it is not an issue, as the index can use GetClass()
method which resolves ambiguity. Should be added now.
internal/webhooks/clusterclass.go
Outdated
|
||
referencedClusters := []clusterv1.Cluster{} | ||
for _, cluster := range clusters.Items { | ||
if cluster.GetInfrastructureNamespace() == clusterClass.Namespace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in this case, possibly add unit test coverage (similar to clusterClassToCluster above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be added in other places now, and is tested indirectly by cleanup in integration tests which goes through ValidateDelete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be added in other places now, and is tested indirectly by cleanup in integration tests which goes through ValidateDelete.
Edit: added unit test on top
// The namespace of the ClusterClass object to create the topology. | ||
// | ||
// +optional | ||
ClassNamespace string `json:"classNamespace,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a minimum and maximum length to all raw string types, since this is a namespace, it follows DNS1123Subdomain and should also be validated as such (there's a regex for this). The maximum length is 253 and the minimum is 1.
Since you have omitempty
, you can safely add the MinLength
, it will prevent anyone using an unstructured client from persisting classNamespace: ""
which would then otherwise not round trip through a structured request
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
d6d8e33
to
bbbddcf
Compare
New changes are detected. LGTM label has been removed. |
Signed-off-by: Danil-Grigorev <[email protected]>
bbbddcf
to
b4b6131
Compare
api/v1beta1/cluster_types.go
Outdated
@@ -509,6 +509,14 @@ type Topology struct { | |||
// The name of the ClusterClass object to create the topology. | |||
Class string `json:"class"` | |||
|
|||
// The namespace of the ClusterClass object to create the topology. | |||
// Empty namespace assumes the namespace of the cluster object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should default to current namespace ...
Pros: it is explicit and consistent to what we do for other references
Cons: it add "noises" to the containing struct while we don't have a clean nesting yet
A compromise might be to keep it empty for now and start defaulting when we will introduce a nested struct
@JoelSpeed opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The namespace of the object can never change, so, defaulting this value to the current namespace would make sense, and make the API explicit. I can't foresee us ever, in the future, wanting to default this to a specific namespace, as we have no concept of a core namespace.
That said, I could see a use case where a cluster admin wants to default this field themselves. In the future they could leverage MutatingAdmissionPolicy to set the namespace always to a certain namespace where they keep their classes. Could defaulting this (since it would have to be a webhook, or MAP) then cause interference with any logic the cluster admin has there? They'd have to make sure that their defaulting went before ours 🤔
I think I would err on the side here, or not defaulting it and just explaining that the empty namespace means that the namespace of the cluster is leveraged, as it is now.
api/v1beta1/cluster_types.go
Outdated
return types.NamespacedName{Namespace: c.GetNamespace(), Name: c.Spec.Topology.Class} | ||
|
||
namespace := c.Spec.Topology.ClassNamespace | ||
if c.Spec.Topology == nil || c.Spec.Topology.ClassNamespace == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if c.Spec.Topology == nil || c.Spec.Topology.ClassNamespace == "" { | |
if namespace == "" { |
Above we are returning when c.Spec.Topology == nil
|
||
<h1>Cluster rebase across namespaces</h1> | ||
|
||
Changing `classNamespace` is not supported in rebase procedure, while chanding `class` reference to a different `ClusterClass` from the same namespace performs regular `Cluster` rebase procedure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be I'm wrong, but I did not found a place where we are enforcing "Changing classNamespace
is not supported".
Also, out of curiosity, why are we introducing this limitation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s mainly due to tests performed on that operation locally. It seems when changing classNamespace
, many referenced template components change namespace too, as they have to preserve ownership references, and instead of rebase
performing minimal modifications of the resource, it has to switch resources entirely. This seemed as a larger scope change.
I’ll add a validation on the field modifications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks clarification
It would be great if we can add the same note as a godoc explanation for check above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I composed a clarification message on the field. It seems there is no need for additional tests as TestLocalObjectTemplatesAreCompatible
is already covering template namespace changes.
@@ -380,12 +380,19 @@ func (webhook *ClusterClass) getClustersUsingClusterClass(ctx context.Context, c | |||
clusters := &clusterv1.ClusterList{} | |||
err := webhook.Client.List(ctx, clusters, | |||
client.MatchingFields{index.ClusterClassNameField: clusterClass.Name}, | |||
client.InNamespace(clusterClass.Namespace), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking a little bit more about this, I think we change this index so performance in the webhook are optimized and also the resulting code will be more readable (both here and in clusterClassToCluster)
@@ -371,7 +370,9 @@ func (r *Reconciler) clusterClassToCluster(ctx context.Context, o client.Object) | |||
// create a request for each of the clusters. | |||
requests := []ctrl.Request{} | |||
for i := range clusterList.Items { | |||
requests = append(requests, ctrl.Request{NamespacedName: util.ObjectKey(&clusterList.Items[i])}) | |||
if clusterList.Items[i].GetInfrastructureNamespace() == clusterClass.Namespace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for self: this seems still open no matter if it reports outdated
5fef5d3
to
703597f
Compare
Signed-off-by: Danil-Grigorev <[email protected]>
9103f4d
to
c581444
Compare
Signed-off-by: Danil-Grigorev <[email protected]>
c581444
to
3639364
Compare
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md
Outdated
Show resolved
Hide resolved
docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Christian Schlotter <[email protected]>
@chrischdi @fabriziopandini Can I get another review? All comments are addressed here. |
What this PR does / why we need it:
Adding
classNamespace
variable to the cluster topology, which allows to point to a ClusterClass in a different namespace. This field is dormant, and is used for differentiation only.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Related to #5673
/area clusterclass