Skip to content

Commit

Permalink
Link and naming fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Jan 9, 2025
1 parent f1456bd commit eb540d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
11 changes: 7 additions & 4 deletions api/v1beta1/index/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ByClusterClassName(ctx context.Context, mgr ctrl.Manager) error {
func ByClusterClassNamespace(ctx context.Context, mgr ctrl.Manager) error {
if err := mgr.GetCache().IndexField(ctx, &clusterv1.Cluster{},
ClusterClassNamespaceField,
ClusterByClusterClassClassNamespace,
ClusterByClusterClassNamespace,
); err != nil {
return errors.Wrap(err, "error setting index field")
}
Expand All @@ -70,11 +70,14 @@ func ClusterByClusterClassClassName(o client.Object) []string {
return nil
}

// ClusterByClusterClassClassNamespace contains the logic to index Clusters by ClusterClass namespace.
func ClusterByClusterClassClassNamespace(o client.Object) []string {
// ClusterByClusterClassNamespace contains the logic to index Clusters by ClusterClass namespace.
func ClusterByClusterClassNamespace(o client.Object) []string {
cluster, ok := o.(*clusterv1.Cluster)
if !ok {
panic(fmt.Sprintf("Expected Cluster but got a %T", o))
}
return []string{cluster.GetClassKey().Namespace}
if cluster.Spec.Topology != nil {
return []string{cluster.GetClassKey().Namespace}
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ Changing `classNamespace` is not supported in rebase procedure, while changing `

#### Securing cross-namespace reference to the ClusterClass

It is often desirable to restrict free cross-namespace `ClusterClass` access for the `Cluster` object. This can be implemented by defining a [`ValidatingAdmissionPolicy`](https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/) on the `Cluster` object.
It is often desirable to restrict free cross-namespace `ClusterClass` access for the `Cluster` object. This can be implemented by defining a [ValidatingAdmissionPolicy](https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/#what-is-validating-admission-policy) on the `Cluster` object.

An example of such policy may be:

Expand Down
8 changes: 4 additions & 4 deletions internal/webhooks/clusterclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestClusterClassDefaultNamespaces(t *testing.T) {
fakeClient := fake.NewClientBuilder().
WithScheme(fakeScheme).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNameField, index.ClusterByClusterClassClassName).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassClassNamespace).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassNamespace).
Build()

// Create the webhook and add the fakeClient as its client.
Expand Down Expand Up @@ -1867,7 +1867,7 @@ func TestClusterClassValidation(t *testing.T) {
fakeClient := fake.NewClientBuilder().
WithScheme(fakeScheme).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNameField, index.ClusterByClusterClassClassName).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassClassNamespace).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassNamespace).
Build()

// Pin the compatibility version used in variable CEL validation to 1.29, so we don't have to continuously refactor
Expand Down Expand Up @@ -2515,7 +2515,7 @@ func TestClusterClassValidationWithClusterAwareChecks(t *testing.T) {
WithScheme(fakeScheme).
WithObjects(tt.clusters...).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNameField, index.ClusterByClusterClassClassName).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassClassNamespace).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassNamespace).
Build()

// Create the webhook and add the fakeClient as its client.
Expand Down Expand Up @@ -2569,7 +2569,7 @@ func TestGetClustersUsingClusterClass(t *testing.T) {
WithScheme(fakeScheme).
WithObjects(tt.clusters...).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNameField, index.ClusterByClusterClassClassName).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassClassNamespace).
WithIndex(&clusterv1.Cluster{}, index.ClusterClassNamespaceField, index.ClusterByClusterClassNamespace).
Build()

// Create the webhook and add the fakeClient as its client.
Expand Down

0 comments on commit eb540d6

Please sign in to comment.