You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Defining a custom namespace for ClusterClass object
442
+
443
+
As a user, I may need to create a `Cluster` from a `ClusterClass` object that exists only in a different namespace. To uniquely identify the `ClusterClass`, a `NamespaceName` ref is constructed from combination of:
444
+
* `cluster.spec.topology.classNamespace` - namespace of the `ClusterClass` object.
445
+
* `cluster.spec.topology.class` - name of the `ClusterClass` object.
446
+
447
+
Example of the `Cluster` object with the `name/namespace` reference:
448
+
449
+
```yaml
450
+
apiVersion: cluster.x-k8s.io/v1beta1
451
+
kind: Cluster
452
+
metadata:
453
+
name: my-docker-cluster
454
+
namespace: default
455
+
spec:
456
+
topology:
457
+
class: docker-clusterclass-v0.1.0
458
+
classNamespace: default
459
+
version: v1.22.4
460
+
controlPlane:
461
+
replicas: 3
462
+
workers:
463
+
machineDeployments:
464
+
- class: default-worker
465
+
name: md-0
466
+
replicas: 4
467
+
failureDomain: region
468
+
```
469
+
470
+
#### Securing cross-namespace reference to the ClusterClass
471
+
472
+
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.
473
+
474
+
An example of such policy may be:
475
+
476
+
```yaml
477
+
apiVersion: admissionregistration.k8s.io/v1
478
+
kind: ValidatingAdmissionPolicy
479
+
metadata:
480
+
name: "cluster-class-ref.cluster.x-k8s.io"
481
+
spec:
482
+
failurePolicy: Fail
483
+
paramKind:
484
+
apiVersion: v1
485
+
kind: Secret
486
+
matchConstraints:
487
+
resourceRules:
488
+
- apiGroups: ["cluster.x-k8s.io"]
489
+
apiVersions: ["v1beta1"]
490
+
operations: ["CREATE", "UPDATE"]
491
+
resources: ["clusters"]
492
+
validations:
493
+
- expression: "!has(object.spec.topology.classNamespace) || object.spec.topology.classNamespace in params.data"
0 commit comments