Skip to content

Commit d87cb46

Browse files
committed
feat: secret copying
1 parent b59b408 commit d87cb46

4 files changed

Lines changed: 47 additions & 9 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Choose how the controller should access the API token:
2929
--wait
3030
```
3131

32-
Swap `--set-file` for `--set credentials.secret.value=$TOKEN` if you prefer piping the token directly from an environment variable or secret store.
32+
Swap `--set-file` for `--set credentials.secret.value=$TOKEN` if you prefer piping the token directly from an environment variable or secret store. Add tenant copies with `--set-json credentials.secret.additionalNamespaces='["edge","storefront"]'`.
3333

3434
- **Bring-your-own secret** – pre-create it and point the chart at it:
3535

@@ -46,7 +46,7 @@ Choose how the controller should access the API token:
4646
--wait
4747
```
4848

49-
The chart-generated secret defaults to `betterstack-operator-credentials`. Whichever path you choose, the secret must exist in every namespace where you define `BetterStackMonitor` objects.
49+
The chart-generated secret defaults to `betterstack-operator-credentials` in the release namespace. Use `credentials.secret.namespace` to move the primary secret and `credentials.secret.additionalNamespaces` to duplicate it; whichever path you choose, ensure the secret exists in every namespace where you create `BetterStackMonitor` objects.
5050

5151
### 2. Create monitors
5252

@@ -67,12 +67,13 @@ kubectl describe betterstackmonitor demo-monitor
6767

6868
Deleting a `BetterStackMonitor` automatically deletes the remote Better Stack monitor thanks to controller finalizers.
6969

70-
### Configuration highlights
70+
### Configuration
7171

7272
See `helm/betterstack-operator/values.yaml` for the full list. Frequently tuned values include:
7373

7474
- `credentials.existingSecret` – reference a pre-created secret instead of letting the chart manage one.
7575
- `credentials.secret.*` – control chart-managed secret creation (name override, key, annotations, inline value).
76+
Use `credentials.secret.namespace` to move the primary secret and `credentials.secret.additionalNamespaces` to fan it out to tenant namespaces.
7677
- `imagePullSecrets` – add registry credentials when pulling the operator image.
7778
- `podAnnotations`, `podLabels`, `podSecurityContext`, `containerSecurityContext` – attach metadata or adjust pod/container security posture.
7879
- `nodeSelector`, `tolerations`, `affinity` – steer the operator onto matching nodes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{- if .Values.monitors }}
2+
{{- range $index, $monitor := .Values.monitors }}
3+
{{- $name := required (printf "monitors[%d].name is required" $index) $monitor.name }}
4+
{{- $spec := required (printf "monitors[%d].spec is required" $index) $monitor.spec }}
5+
---
6+
apiVersion: monitoring.betterstack.io/v1alpha1
7+
kind: BetterStackMonitor
8+
metadata:
9+
name: {{ $name }}
10+
namespace: {{ default $.Release.Namespace $monitor.namespace }}
11+
{{- with $monitor.labels }}
12+
labels:
13+
{{ toYaml . | indent 4 }}
14+
{{- end }}
15+
{{- with $monitor.annotations }}
16+
annotations:
17+
{{ toYaml . | indent 4 }}
18+
{{- end }}
19+
spec:
20+
{{ toYaml $spec | indent 2 }}
21+
{{- end }}
22+
{{- end }}
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
{{- $existing := .Values.credentials.existingSecret -}}
22
{{- if and (not $existing) .Values.credentials.secret.create }}
3-
{{- $name := default (printf "%s-credentials" (include "betterstack-operator.fullname" .)) .Values.credentials.secret.name -}}
3+
{{- $root := . -}}
4+
{{- $name := default (printf "%s-credentials" (include "betterstack-operator.fullname" $root)) .Values.credentials.secret.name -}}
45
{{- $key := default "api-key" .Values.credentials.secret.key -}}
56
{{- $value := required "credentials.secret.value must be set when credentials.secret.create is true" .Values.credentials.secret.value -}}
7+
{{- $primaryNamespace := default (include "betterstack-operator.namespace" $root) .Values.credentials.secret.namespace -}}
8+
{{- $namespaces := list $primaryNamespace -}}
9+
{{- range $ns := .Values.credentials.secret.additionalNamespaces }}
10+
{{- if $ns }}
11+
{{- $namespaces = append $namespaces $ns }}
12+
{{- end }}
13+
{{- end }}
14+
{{- range $i, $ns := $namespaces }}
15+
{{- if $ns }}
16+
---
617
apiVersion: v1
718
kind: Secret
819
metadata:
920
name: {{ $name }}
10-
namespace: {{ include "betterstack-operator.namespace" . }}
21+
namespace: {{ $ns }}
1122
labels:
12-
app.kubernetes.io/name: {{ include "betterstack-operator.name" . }}
13-
app.kubernetes.io/instance: {{ .Release.Name }}
14-
app.kubernetes.io/managed-by: {{ .Release.Service }}
15-
{{- with .Values.credentials.secret.annotations }}
23+
app.kubernetes.io/name: {{ include "betterstack-operator.name" $root }}
24+
app.kubernetes.io/instance: {{ $root.Release.Name }}
25+
app.kubernetes.io/managed-by: {{ $root.Release.Service }}
26+
{{- with $root.Values.credentials.secret.annotations }}
1627
annotations:
1728
{{ toYaml . | nindent 4 }}
1829
{{- end }}
1930
type: Opaque
2031
stringData:
2132
{{ $key }}: {{ $value | quote }}
2233
{{- end }}
34+
{{- end }}
35+
{{- end }}

helm/betterstack-operator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ credentials:
6161
key: api-key
6262
value: ""
6363
annotations: {}
64+
namespace: ""
65+
additionalNamespaces: []

0 commit comments

Comments
 (0)