Skip to content

Commit

Permalink
chore: use deployment's namespace pass down to pod as operator namesp…
Browse files Browse the repository at this point in the history
…ace (#1139)

- fallback to use /var/run file if not get value

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw authored Jul 24, 2024
1 parent 7034768 commit a08c94a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,10 @@ spec:
env:
- name: DISABLE_DSC_CONFIG
value: "true"
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: REPLACE_IMAGE:latest
imagePullPolicy: Always
livenessProbe:
Expand Down
4 changes: 4 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ spec:
env:
- name: DISABLE_DSC_CONFIG
value: 'true'
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
args:
- --operator-name=opendatahub
image: controller:latest
Expand Down
4 changes: 4 additions & 0 deletions pkg/cluster/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func GetDomain(ctx context.Context, c client.Client) (string, error) {
}

func GetOperatorNamespace() (string, error) {
operatorNS, exist := os.LookupEnv("OPERATOR_NAMESPACE")
if exist && operatorNS != "" {
return operatorNS, nil
}
data, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
return string(data), err
}
Expand Down

0 comments on commit a08c94a

Please sign in to comment.