Skip to content

Commit

Permalink
re-implement WATCH_NAMESPACE
Browse files Browse the repository at this point in the history
  • Loading branch information
tstenner committed Jul 5, 2023
1 parent 3ec3f6a commit 722b2cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions charts/ext-postgres-operator/templates/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ spec:
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
command:
- postgres-operator
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- secretRef:
Expand All @@ -47,6 +45,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if .Values.prefix }}
- name: POSTGRES_OBJECT_PREFIX
value: {{ .Values.prefix }}
{{- end }}
- name: OPERATOR_NAME
value: {{ include "chart.fullname" . }}
{{- range $key, $value := .Values.env }}
Expand Down
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

Expand Down Expand Up @@ -66,13 +67,20 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

cacheOpts := cache.Options{}
namespace, found := os.LookupEnv("WATCH_NAMESPACE")
if found {
cacheOpts.Namespaces = []string{namespace}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "c5655ffe.db.movetokube.com",
Cache: cacheOpts,
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
Expand Down
2 changes: 1 addition & 1 deletion internal/postgres/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
CREATE_SCHEMA = `CREATE SCHEMA IF NOT EXISTS "%s" AUTHORIZATION "%s"`
CREATE_EXTENSION = `CREATE EXTENSION IF NOT EXISTS "%s"`
ALTER_DB_OWNER = `ALTER DATABASE "%s" OWNER TO "%s"`
DROP_DATABASE = `DROP DATABASE "%s"`
DROP_DATABASE = `DROP DATABASE IF EXISTS "%s" WITH (FORCE)`
GRANT_USAGE_SCHEMA = `GRANT USAGE ON SCHEMA "%s" TO "%s"`
GRANT_ALL_TABLES = `GRANT %s ON ALL TABLES IN SCHEMA "%s" TO "%s"`
DEFAULT_PRIVS_SCHEMA = `ALTER DEFAULT PRIVILEGES FOR ROLE "%s" IN SCHEMA "%s" GRANT %s ON TABLES TO "%s"`
Expand Down

0 comments on commit 722b2cf

Please sign in to comment.