Skip to content

Commit 22f2b77

Browse files
clement0010ekampf
andauthored
feat: Allow scoping Operator installation on specific namespaces (#738)
## Related Tickets & Documents - Issue: #719, #717 ## Changes - Allow scoping Operator installation on specific namespaces ## Notes Currently, Operator will apply `twingate.com/kopf-managed` and `twingate.com/last-handled-configuration` annotations to all Kubernetes services & Twigate CRD across all namespaces. In some cases, we are not supposed to modify the k8s Service. Issue #717 is an example where we are not allowed to edit the `kube-system` namespace of the GKE autopilot cluster. --------- Co-authored-by: Eran Kampf <eran@ekampf.com> Co-authored-by: Eran Kampf <205185+ekampf@users.noreply.github.com>
1 parent 012c52d commit 22f2b77

5 files changed

Lines changed: 52 additions & 3 deletions

File tree

deploy/twingate-operator/templates/deployment.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ spec:
4545
- kopf
4646
- run
4747
- ./main.py
48-
- "-A"
48+
{{- with .Values.twingateOperator.namespaces }}
49+
{{- range . }}
50+
- "--namespace={{ . }}"
51+
{{- end }}
52+
{{- else }}
53+
- "--all-namespaces"
54+
{{- end }}
4955
- "--standalone"
5056
- "--liveness=http://0.0.0.0:8080/healthz"
5157
- "--log-format={{ $logFormat }}"

deploy/twingate-operator/tests/__snapshot__/default_values_test.yaml.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ should render:
111111
- kopf
112112
- run
113113
- ./main.py
114-
- -A
114+
- --all-namespaces
115115
- --standalone
116116
- --liveness=http://0.0.0.0:8080/healthz
117117
- --log-format=full

deploy/twingate-operator/tests/deployment_optional_values_test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ tests:
3737
content:
3838
name: TWINGATE_DEFAULT_RESOURCE_TAGS
3939
value: '{"cluster":"test-cluster","owner":"eran"}'
40+
- it: should use `namespaces`
41+
set:
42+
twingateOperator:
43+
namespaces:
44+
- foo
45+
- bar
46+
asserts:
47+
- equal:
48+
path: spec.template.spec.containers[0].command
49+
value:
50+
- kopf
51+
- run
52+
- ./main.py
53+
- --namespace=foo
54+
- --namespace=bar
55+
- --standalone
56+
- --liveness=http://0.0.0.0:8080/healthz
57+
- --log-format=full
4058
- it: should use `imagePullSecrets`
4159
set:
4260
imagePullSecrets:

deploy/twingate-operator/values.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@
155155
"additionalProperties": {
156156
"type": "string"
157157
}
158+
},
159+
"namespaces": {
160+
"type": "array",
161+
"description": "Array of namespaces to monitor by the operator",
162+
"items": { "type": "string" },
163+
"default": []
158164
}
159165
},
160166
"examples": [{

deploy/twingate-operator/values.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,26 @@
22
# This is a YAML-formatted file.
33
# Declare variables to be passed into your templates.
44

5-
# Required: you have to specify `network` and
5+
# Twingate operator configurations
6+
#
7+
# **Required**: you have to specify `network` and
68
# - either `apiKey` or `existingAPIKeySecret`
79
# - either `remoteNetworkId`, `remoteNetworkName` or `existingRemoteNetworkIdSecret`
10+
#
11+
# **Restricting Operator to Specific Namespaces**
12+
# Use the `namespaces` property to restrict operator to monitor resources only in specific namespaces.
13+
# You can either:
14+
# 1. Specify a list of namespaces: ["foo-dev", "foo-stg"]
15+
# 2. Use globs to match multiple namespaces: ["*-dev", "*-stg"]
16+
# 3. Use negation to include all namespaces except those excluded: ["!kube-*"]
17+
# 4. Use multiple globs in one pattern: ["foo-*,!*-test"]
18+
#
19+
# Default value is an empty list (`[]`) which means operator will monitor or all namespaces.
20+
#
21+
# *Note:* Defining glob patterns as a separate array elements is different from defining
22+
# comma-separated patterns within a single element.
23+
# For example, `namespaces: ["foo-*", "!*-test"]` is not the same as `namespaces: ["foo-*,!*-test"]`
24+
# `namespaces: ["foo-*", "!*-test"]` will evaluate each glob pattern independently and combine the results.
825
twingateOperator: {}
926
# apiKey: "<api key>"
1027
# existingAPIKeySecret:
@@ -16,12 +33,14 @@ twingateOperator: {}
1633
# name: my-secret
1734
# key: TWINGATE_REMOTE_NETWORK_ID
1835
# remoteNetworkName: "<remote network name>"
36+
# namespaces: []
1937
# logFormat: "plain|full|json"
2038
# logVerbosity: "quiet|verbose|debug"
2139
# defaultResourceTags:
2240
# tag1: value_for_tag1
2341
# tag2: value_for_tag2
2442

43+
2544
# Twingate Kubernetes Access is currently in beta. Sign up for early access at https://www.twingate.com/product/kubernetes-access.
2645
kubernetes-access-gateway:
2746
enabled: false

0 commit comments

Comments
 (0)