forked from GoogleCloudPlatform/metacontroller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for cluster scoped parent resources
This CL adds initial support for clustered parents the decorator controller. The composite controller will work as long as you're not using rolling updates. This CL changes the behavior of the client map which is sent as `attachments` or `children` in the DecoratorController and CompositeController, respectively. The new keys can be thought of as a relative path to the child. When both the parent and child are at the same scope - either both namespaced or both clustered - the key is just the child's name. When the parent is clustered and the child is namespaced the relative are relative - the children's keys will always be prefaced with the namespace - this is to disambiguate between two children with the same name in different namespaces. To test this change this CL also adds two examples. The first example is of a decorator controller that creates a "reader" ClusterRole, similar to the default roles and rolebindings for each CRD with the `enable-default-roles` annotation. The second is a decorator controller which creates role bindings in the default namespace that bind the default service account to clusterrolebindings. Closes GoogleCloudPlatform#2
- Loading branch information
Showing
17 changed files
with
441 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## ClusterRole service account binding | ||
|
||
This is an example DecoratorController that creates a namespaced resources from a | ||
cluster scoped parent resource. | ||
|
||
This controller will bind any ClusterRole with the "default-service-account-binding" | ||
annotation to the default service account in the default namespace. | ||
|
||
### Prerequisites | ||
|
||
* Install [Metacontroller](https://github.com/GoogleCloudPlatform/metacontroller) | ||
|
||
### Deploy the controller | ||
|
||
```sh | ||
kubectl create configmap cluster-parent-controller -n metacontroller --from-file=sync.py | ||
kubectl apply -f cluster-parent.yaml | ||
``` | ||
|
||
### Create a ClusterRole | ||
|
||
```sh | ||
kubectl apply -f my-clusterole.yaml | ||
``` | ||
|
||
A RoleBinding should be created for the ClusterRole: | ||
|
||
```console | ||
$ kubectl get rolebinding -n default my-clusterrole -o wide | ||
NAME AGE ROLE USERS GROUPS SERVICEACCOUNTS | ||
my-clusterrole 40s ClusterRole/my-clusterrole default/default | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
apiVersion: metacontroller.k8s.io/v1alpha1 | ||
kind: DecoratorController | ||
metadata: | ||
name: cluster-parent | ||
spec: | ||
resources: | ||
- apiVersion: rbac.authorization.k8s.io/v1 | ||
resource: clusterroles | ||
annotationSelector: | ||
matchExpressions: | ||
- {key: default-service-account-binding, operator: Exists} | ||
attachments: | ||
- apiVersion: rbac.authorization.k8s.io/v1 | ||
resource: rolebindings | ||
hooks: | ||
sync: | ||
webhook: | ||
url: http://cluster-parent-controller.metacontroller/sync | ||
--- | ||
apiVersion: apps/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: clusterparent-controller | ||
namespace: metacontroller | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: cluster-parent-controller | ||
template: | ||
metadata: | ||
labels: | ||
app: cluster-parent-controller | ||
spec: | ||
containers: | ||
- name: controller | ||
image: python:2.7 | ||
command: ["python", "/hooks/sync.py"] | ||
volumeMounts: | ||
- name: hooks | ||
mountPath: /hooks | ||
volumes: | ||
- name: hooks | ||
configMap: | ||
name: cluster-parent-controller | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: cluster-parent-controller | ||
namespace: metacontroller | ||
spec: | ||
selector: | ||
app: cluster-parent-controller | ||
ports: | ||
- port: 80 |
Oops, something went wrong.