Skip to content

Commit cb430ee

Browse files
committed
feat(deploy): support single namespace
Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com>
1 parent 01b870d commit cb430ee

File tree

10 files changed

+65
-12
lines changed

10 files changed

+65
-12
lines changed

.github/workflows/deploy.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ jobs:
3232

3333
- [EMQX, emqx, "config/samples/emqx/v2beta1/emqx-slim.yaml"]
3434
- [EMQX, emqx, "config/samples/emqx/v2beta1/emqx-full.yaml"]
35+
single_namespace:
36+
- false
37+
- true
38+
exclude:
39+
- install: static
40+
single_namespace: true
3541

3642
steps:
3743
- run: minikube start
@@ -63,11 +69,15 @@ jobs:
6369
helm install emqx-operator deploy/charts/emqx-operator \
6470
--set image.tag=${{ github.sha }} \
6571
--set development=true \
66-
--namespace emqx-operator-system \
72+
--set singleNamespace=${{ matrix.single_namespace }} \
73+
--namespace ${{ matrix.single_namespace && 'default' || 'emqx-operator-system' }} \
6774
--create-namespace
6875
- name: Check operator
6976
timeout-minutes: 5
70-
run: kubectl wait --for=condition=Ready pods -l "control-plane=controller-manager" -n emqx-operator-system
77+
run: |
78+
kubectl wait --for=condition=Ready pods \
79+
-l "control-plane=controller-manager" \
80+
-n ${{ matrix.single_namespace && 'default' || 'emqx-operator-system' }}
7181
- name: Deployment emqx
7282
timeout-minutes: 5
7383
uses: ./.github/actions/deploy-emqx

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22 as builder
2+
FROM golang:1.22 AS builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

RELEASE.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release Note 🍻
22

3-
EMQX Operator 2.2.25 has been released.
3+
EMQX Operator 2.2.26-rc.1 has been released.
44

55
## Supported version
66
+ apps.emqx.io/v2beta1
@@ -15,9 +15,7 @@ EMQX Operator 2.2.25 has been released.
1515

1616
## Enhancements 🚀
1717

18-
+ `apps.emqx.io/v2beta1 EMQX`.
19-
20-
+ Fix sometimes got `EOF` error when request EMQX API
18+
+ EMQX operator can now be deployed in a single namespace scope, where it will only manage resources within that namespace. Just set `singleNamespace: true` in the `values.yaml` file of Helm chart, and then the operator will only manage resources in the namespace where it is deployed.
2119

2220
## How to install/upgrade EMQX Operator 💡
2321

@@ -29,7 +27,7 @@ helm repo update
2927
helm upgrade --install emqx-operator emqx/emqx-operator \
3028
--namespace emqx-operator-system \
3129
--create-namespace \
32-
--version 2.2.25
30+
--version 2.2.26-rc.1
3331
kubectl wait --for=condition=Ready pods -l "control-plane=controller-manager" -n emqx-operator-system
3432
```
3533

deploy/charts/emqx-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 2.2.26
18+
version: 2.2.26-rc.1
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
23-
appVersion: 2.2.26
23+
appVersion: 2.2.26-rc.1
2424

2525
sources:
2626
- https://github.com/emqx/emqx-operator/tree/main/deploy/charts/emqx-operator

deploy/charts/emqx-operator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following table lists the configurable parameters of the cert-manager chart
3434
| Parameter | Description | Default |
3535
| --------- | ----------- | ------- |
3636
| `skipCRDs` | If `true`, skips installing CRDs | `false` |
37+
| `singleNamespace` | If true, the operator will watch only the namespace where it is deployed. If false, the operator will watch all namespaces. | `false` |
3738
| `development` | Development configures the logger to use a Zap development config (stacktraces on warnings, no sampling), otherwise a Zap production config will be used (stacktraces on errors, sampling). | `false` |
3839
| `image.repository` | Image repository | `emqx/emqx-operator-controller` |
3940
| `image.tag` | Image tag | `{{RELEASE_VERSION}}` |

deploy/charts/emqx-operator/templates/controller-manager-rbac.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,40 @@ imagePullSecrets:
1616
{{- end }}
1717
---
1818
apiVersion: rbac.authorization.k8s.io/v1
19+
{{ if .Values.singleNamespace }}
20+
kind: RoleBinding
21+
metadata:
22+
name: {{ include "emqx-operator.fullname" . }}-manager-rolebinding
23+
namespace: {{ .Release.Namespace }}
24+
{{- else }}
1925
kind: ClusterRoleBinding
2026
metadata:
2127
name: {{ include "emqx-operator.fullname" . }}-manager-rolebinding
28+
{{- end }}
2229
roleRef:
2330
apiGroup: rbac.authorization.k8s.io
31+
{{- if .Values.singleNamespace }}
32+
kind: Role
33+
{{- else }}
2434
kind: ClusterRole
35+
{{- end }}
2536
name: {{ include "emqx-operator.fullname" . }}-manager-role
2637
subjects:
2738
- kind: ServiceAccount
2839
name: {{ include "emqx-operator.serviceAccountName" . }}
2940
namespace: {{ .Release.Namespace }}
3041
---
3142
apiVersion: rbac.authorization.k8s.io/v1
43+
{{ if .Values.singleNamespace }}
44+
kind: Role
45+
metadata:
46+
name: {{ include "emqx-operator.fullname" . }}-manager-role
47+
namespace: {{ .Release.Namespace }}
48+
{{- else }}
3249
kind: ClusterRole
3350
metadata:
34-
creationTimestamp: null
3551
name: {{ include "emqx-operator.fullname" . }}-manager-role
52+
{{- end }}
3653
rules:
3754
- apiGroups:
3855
- ""

deploy/charts/emqx-operator/templates/controller-manager.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ spec:
5151
- containerPort: 9443
5252
name: webhook-server
5353
protocol: TCP
54+
{{- if .Values.singleNamespace }}
55+
env:
56+
- name: WATCH_NAMESPACE
57+
valueFrom:
58+
fieldRef:
59+
fieldPath: metadata.namespace
60+
{{- end }}
5461
readinessProbe:
5562
httpGet:
5663
path: /readyz

deploy/charts/emqx-operator/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
skipCRDs: false
66

7+
## If true, the operator will watch only the namespace where it is deployed. If false, the operator will watch all namespaces.
8+
singleNamespace: false
9+
710
# Development configures the logger to use a Zap development config
811
# (stacktraces on warnings, no sampling), otherwise a Zap production
912
# config will be used (stacktraces on errors, sampling).

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3535
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3636
ctrl "sigs.k8s.io/controller-runtime"
37+
"sigs.k8s.io/controller-runtime/pkg/cache"
3738
"sigs.k8s.io/controller-runtime/pkg/healthz"
3839
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3940

@@ -102,6 +103,9 @@ func main() {
102103
LeaderElectionID: "19fd6fcc.emqx.io",
103104
LeaseDuration: ptr.To(time.Second * 30),
104105
RenewDeadline: ptr.To(time.Second * 20),
106+
Cache: cache.Options{
107+
DefaultNamespaces: getWatchNamespace(),
108+
},
105109
})
106110
if err != nil {
107111
setupLog.Error(err, "unable to start manager")
@@ -173,3 +177,16 @@ func main() {
173177
os.Exit(1)
174178
}
175179
}
180+
181+
// getWatchNamespace returns the Namespace the operator should be watching for changes
182+
func getWatchNamespace() map[string]cache.Config {
183+
var watchNamespaceEnvVar = "WATCH_NAMESPACE"
184+
185+
ns, found := os.LookupEnv(watchNamespaceEnvVar)
186+
if found {
187+
return map[string]cache.Config{
188+
ns: {},
189+
}
190+
}
191+
return nil
192+
}

sidecar/reloader/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.18.3 as builder
2+
FROM golang:1.18.3 AS builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

0 commit comments

Comments
 (0)