Commit d20844a7 authored by Edmund Ochieng's avatar Edmund Ochieng

change operator scope to namespaced

parent f9317f86
......@@ -67,7 +67,7 @@ generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
docker-build: #test # Pending https://github.com/kubernetes-sigs/kubebuilder/pull/1626
docker-build: test # Pending https://github.com/kubernetes-sigs/kubebuilder/pull/1626
podman build . -t ${IMG}
# Push the docker image
......
......@@ -34,6 +34,11 @@ spec:
- /manager
image: quay.io/eochieng/gitlab-operator:latest
name: manager
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.name
resources:
limits:
cpu: 200m
......
......@@ -36,5 +36,10 @@ spec:
requests:
cpu: 200m
memory: 20Mi
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.name
terminationGracePeriodSeconds: 10
serviceAccountName: gitlab-operator
......@@ -17,6 +17,7 @@ limitations under the License.
package main
import (
"errors"
"flag"
"os"
......@@ -71,12 +72,18 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
watchedNamespace, err := getWatchedNamespace()
if err != nil {
setupLog.Error(err, "unable to get watched namespace, the manager will watch all namespaces")
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "852d23b0.gitlab.com",
Namespace: watchedNamespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
......@@ -115,3 +122,12 @@ func main() {
os.Exit(1)
}
}
func getWatchedNamespace() (string, error) {
ns, ok := os.LookupEnv("WATCH_NAMESPACE")
if !ok {
return "", errors.New("WATCH_NAMESPACE env required")
}
return ns, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment