Skip to content

Commit 2ffe6fd

Browse files
committed
Document applied resources
1 parent 43c3643 commit 2ffe6fd

File tree

4 files changed

+337
-60
lines changed

4 files changed

+337
-60
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
- name: unit tests
2222
run: make test-unit
2323

24+
- name: manifest validation
25+
run: make lint
26+
2427
- name: setup kind
2528
uses: engineerd/[email protected]
2629
with:

README.md

+149-21
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,68 @@
77

88
## Introduction
99

10-
The Plex Sandbox Operator is an operator for [Kubernetes](https://kubernetes.io/) that enables authenticated users to a cluster to create their own isolated environments leveraging namespaces.
10+
The Plex Sandbox Operator is an operator for [Kubernetes](https://kubernetes.io/) that enables authenticated users to a cluster to create their own isolated environments.
1111

1212
## Installation
1313

14-
The [deploy](deploy) folder contains the necessary Kubernetes manifests to install the operator.
14+
### Kustomize
15+
16+
This repository contains a [deploy](deploy) folder which contains all of the manifests required to deploy the operator, as well as a `kustomization.yaml` file.
17+
18+
If you would like to apply your own customizations, reference the `deploy` folder and the version in your `kustomization.yaml`.
19+
20+
```yaml
21+
resources:
22+
- git::https://github.com/plexsystems/sandbox-operator.git//deploy?ref=v0.3.0
23+
```
24+
25+
Additionally, the [example](example) folder shows one example of how to customize the operator.
26+
27+
### Bundle
28+
29+
Alternatively, a [bundle.yaml](bundle.yaml) is provided in the root of the repository which can then be applied via `kubectl apply`.
30+
31+
### Created ClusterRole and ClusterRoleBinding
32+
33+
After installing the operator, a `ClusterRole` and `ClusterRoleBinding` will be created for all _authenticated_ users in your cluster.
34+
35+
### ClusterRole (sandbox-users)
36+
37+
|Verbs|API Groups|Resources|
38+
|---|---|---|
39+
|create, list, get|operators.plex.dev|sandboxes|
40+
41+
### ClusterRoleBinding (sandbox-user)
42+
43+
|API Group|Name|Subjects|
44+
|---|---|---|
45+
|rbac.authorization.k8s.io|sandbox-users|system:authenticated|
46+
47+
### Created Sandbox CRD
48+
49+
After installing the operator, a `CustomResourceDefinition` named `Sandbox` will be created.
50+
51+
An example manifest for the Sandbox CRD is as follows:
52+
53+
```yaml
54+
apiVersion: operators.plex.dev/v1alpha1
55+
kind: Sandbox
56+
metadata:
57+
name: test
58+
spec:
59+
owners:
60+
61+
```
1562

1663
## Configuration
1764

1865
The sandbox operator can leverage different clients, depending upon how authenitcation is configured for your cluster.
1966

2067
### Azure
2168

22-
If Azure credentials are provided to the deployment, the operator will perform a lookup of the user in the owners field to fetch that users ObjectID inside of Azure.
69+
If Azure credentials are provided to the operators environment, it will perform a lookup of each user in the owners field and fetch that users `ObjectID` inside of Azure using [Microsoft Graph](https://docs.microsoft.com/en-us/graph/api/resources/azure-ad-overview?view=graph-rest-1.0).
2370

24-
This enables users of the operator to provide a user friendly name, such as their email address, and have the operator itself handle the creation of the bindings within Kubernetes.
71+
This enables users to create Sandboxes with friendly names, such as their email address, and have the operator itself handle the mapping when creating the Kubernetes resources.
2572

2673
To use the Azure client, include the following environment variables:
2774

@@ -31,53 +78,134 @@ To use the Azure client, include the following environment variables:
3178

3279
### Default
3380

34-
If no credentials are provided, the operator will create the bindings using the values listed in the owners field.
81+
If no credentials are provided, the operator will create the `Role` and `ClusterRole` bindings using the values listed in the owners field.
82+
83+
## Creating a Sandbox
3584

36-
## Usage
85+
To create a Sandbox, create and apply a Sandbox CRD to the target cluster.
3786

38-
To use the operator, create and apply a Sandbox CRD to the target cluster.
87+
The following will create a Sandbox called `foo` (the resulting namespace being `sandbox-foo`), and assign the RBAC policies to user `[email protected]`.
3988

40-
The following manifest will create a sandbox called `test` (the resulting namespace being `sandbox-test`), and assign the RBAC roles to user `foo@bar.com`
89+
### sandbox-foo.yaml
4190

4291
```yaml
4392
apiVersion: operators.plex.dev/v1alpha1
4493
kind: Sandbox
4594
metadata:
46-
name: test
95+
name: foo
96+
spec:
97+
owners:
98+
99+
```
100+
101+
```console
102+
$ kubectl apply -f sandbox-foo.yaml
103+
sandboxes.operators.plex.dev "foo" created
104+
```
105+
106+
## Created Resources
107+
108+
Assuming the name of the created Sandbox is named `foo`, the following resources will be created per Sandbox:
109+
110+
### Namespace (sandbox-foo)
111+
112+
### ClusterRole (sandbox-foo-deleter)
113+
114+
|Verbs|API Groups|Resources|ResourceNames|
115+
|---|---|---|---|
116+
|delete|operators.plex.dev|sandboxes|sandbox-foo|
117+
118+
This is created so that only users defined in the `owners` field can delete their Sandboxes.
119+
120+
### ClusterRoleBinding (sandbox-foo-deleters)
121+
122+
One `ClusterRoleBinding` per name in the `owners` field
123+
124+
### Role (sandbox-foo-owner)
125+
126+
|Verbs|API Groups|Resources|
127+
|---|---|---|
128+
|*|core|pods, pods/log, services, services/finalizers, endpoints, persistentvolumeclaims, events, configmaps, replicationcontrollers|
129+
|*|apps|deployments, daemonsets, replicasets, statefulsets|
130+
|*|autoscaling|horizontalpodautoscalers|
131+
|*|batch|jobs, cronjobs|
132+
|create, list, get|rbac.authorization.k8s.io|roles, rolebindings|
133+
134+
### RoleBinding (sandbox-foo-owners)
135+
136+
One `RoleBinding` per name in the `owners` field
137+
138+
### ResourceQuota (sandbox-foo-resourcequota)
139+
140+
|Resource Name|Quantity|
141+
|---|---|
142+
|ResourceRequestsMemory|1Gi|
143+
144+
## Managing Owners of a Sandbox
145+
146+
After the Sandbox has been created, you can add or remove owners that are associated to it.
147+
148+
For example, to add `[email protected]` as an owner, add their name to the list of owners and apply the changes:
149+
150+
```yaml
151+
apiVersion: operators.plex.dev/v1alpha1
152+
kind: Sandbox
153+
metadata:
154+
name: foo
47155
spec:
48156
owners:
49157
158+
159+
```
160+
161+
```console
162+
$ kubectl apply -f sandbox-foo.yaml
163+
sandboxes.operators.plex.dev "foo" configured
50164
```
51165

52-
### Created Resources
166+
This will cause the operator to add `ClusterRoleBinding` and `RoleBinding` resources to match the owners list.
167+
168+
## Deleting a Sandbox
53169

54-
For each sandbox that is created the following resources will be created:
170+
To delete a Sandbox, delete the Sandbox resource from the cluster:
55171

56-
- `Namespace`: Name of the sandbox, prefixed with `sandbox-`.
172+
```console
173+
$ kubectl delete sandbox foo
174+
sandboxes.operators.plex.dev "foo" deleted
175+
```
57176

58-
- `ClusterRole`: Only the permission to delete and view the created sandbox.
177+
Deleting a Sandbox will delete the `Namespace` as well as the `ClusterRole` and `ClusterRoleBinding` resources
59178

60-
- `ClusterRoleBinding`: Given to each user listed in the `owners` field of the Sandbox CRD.
179+
## Metrics
61180

62-
- `Role`: Permissions to manage the contents of the sandbox, but no permission to view secrets.
181+
The operator exposes two metric ports for the `/metrics` end point:
63182

64-
- `RoleBinding`: Given to each user listed in the `owners` field of the Sandbox CRD.
183+
- Port `8383` exposes metrics for the operator itself
184+
- Port `8686` exposes metrics for the `Sandbox` CRD
65185

66-
- `ResourceQuota`: Defined quotas for the Sandbox.
186+
Additionally, if [prometheus-operator](https://github.com/coreos/prometheus-operator) is installed into the cluster, a `ServiceMonitor` is created for the operator
67187

68188
## Development
69189

70-
### Testing
190+
No external tooling is required to develop and build the operator. However, some tooling is required to run the integration tests and validate the manifests:
191+
192+
- [Kind](https://github.com/kubernetes-sigs/kind)
193+
- [Kustomize](https://github.com/kubernetes-sigs/kustomize)
194+
- [Kubeval](https://github.com/instrumenta/kubeval/)
195+
196+
## Testing
197+
198+
The provided `Makefile` contains commands that assist with running the tests for the operator.
71199

72200
### Unit tests
73201

74-
Run the `make test-unit` command. This will use an in-memory kubernetes client to validate and test your changes.
202+
`make test-unit` will use an in-memory kubernetes client to validate and test your changes without the need for an external Kubernetes cluster.
75203

76204
### Integration tests
77205

78-
Run the `make test-integration` command. This will create a Kubernetes cluster for you, using [Kind](https://github.com/kubernetes-sigs/kind), and deploy the operator to it. Afterwards, the integration tests will be ran against the newly created cluster and operator.
206+
`make test-integration` will create a Kubernetes cluster for you, using Kind, and deploy the operator to it. The integration tests will then be ran against the newly created cluster.
79207

80-
**NOTE:** To test the operator with different versions of Kubernetes, you can use the `KUBERNETES_VERSION` variable to when calling `make`. For example, to test on Kubernetes v1.16.3, run the following command:
208+
**NOTE:** To test the operator with different versions of Kubernetes, you can use the `KUBERNETES_VERSION` variable when calling `make`. For example, to test on Kubernetes v1.16.3, run the following command:
81209

82210
`make test-integration KUBERNETES_VERSION=v1.16.3`
83211

0 commit comments

Comments
 (0)