-
Notifications
You must be signed in to change notification settings - Fork 35
Added logic to watch all namespaces #38
base: main
Are you sure you want to change the base?
Changes from all commits
c12998b
c8d3b55
7207a9b
a7f76de
8d20a4a
d6ed764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,3 +96,53 @@ $ kubectl delete crd workspaces.app.terraform.io | |
| ``` | ||
|
|
||
| If the CRD is not updated correctly, you will not be able to create a Workspace Custom Resource. | ||
|
|
||
|
|
||
|
|
||
| ### Helm Chart | ||
|
|
||
| The Helm chart consists of several components. The Kubernetes configurations associated with the Helm chart are located under `crds/` and `templates/`. | ||
|
|
||
| #### Custom Resource Definition | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would skip this paragraph completely. |
||
|
|
||
| Helm starts by deploying the Custom Resource Definition for the Workspace. Custom Resource Definitions extend the Kubernetes API. It looks for definitions in the `crds/` of the chart. | ||
|
|
||
| The Custom Resource Definition under `crds/app.terraform.io_workspaces_crd.yaml` defines that the Workspace Custom Resource schema. | ||
|
|
||
| #### Role-Based Access Control | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would skip this paragraph completely. |
||
|
|
||
| In order to scope the operator to a namespace, Helm assigns a role and service account to the namespace. The role has access to Pods, Secrets, Services, and ConfigMaps. This configuration is located in `templates/`. | ||
|
|
||
| #### Namespace Scope | ||
|
|
||
| To ensure the operator does not have access to secrets or resource beyond the namespace, the Helm chart scopes the operator's deployment to a namespace. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line wrapping should be on 80 characters. |
||
|
|
||
| ```yaml | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: terraform-k8s | ||
| spec: | ||
| # some sections omitted for clarity | ||
| template: | ||
| metadata: | ||
| labels: | ||
| name: terraform-k8s | ||
| spec: | ||
| serviceAccountName: terraform-k8s | ||
| containers: | ||
| - name: terraform-k8s | ||
| command: | ||
| - /bin/terraform-k8s | ||
| - "--k8s-watch-namespace=$(POD_NAMESPACE)" | ||
| env: | ||
| - name: POD_NAMESPACE | ||
| valueFrom: | ||
| fieldRef: | ||
| fieldPath: metadata.namespace | ||
| ``` | ||
|
|
||
| When deploying, if you want to explicitly watch all namespaces, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line wrapping should be on 80 characters. |
||
| then you'll need to set `watchAllNamespaces: true`. Otherwise, | ||
| the default behaviour will be to watch the Release namespace or | ||
| the namespace provided in the `k8WatchNamespace` value. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,3 +59,14 @@ Inject extra environment vars in the format key:value, if populated | |
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
|
|
||
| {{/* | ||
| Define the kind of Role to use | ||
| */}} | ||
| {{- define "terraform.getRole" -}} | ||
| {{- if .Values.syncWorkspace.watchAllNamespaces -}} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change this to this: {{/*
Define the kind of Role to use
*/}}
{{- define "terraform.getRole" -}}
{{- if or .Values.syncWorkspace.watchAllNamespaces (or (empty .Values.syncWorkspace.k8WatchNamespace) (eq (.Values.syncWorkspace.k8WatchNamespace | toString) .Release.Namespace)) }}
{{- "ClusterRole" }}
{{- else }}
{{- "Role" }}
{{- end }}
{{- end -}} |
||
| {{- "ClusterRole" -}} | ||
| {{- else -}} | ||
| {{- (ternary "Role" "ClusterRole" (or (empty .Values.syncWorkspace.k8WatchNamespace) (eq (.Values.syncWorkspace.k8WatchNamespace | toString) .Release.Namespace))) -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
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 would skip this paragraph completely.