Skip to content

HIVE-30210: Introduce configurable namespace scoping for K8s operator - #6983

Open
tanishq-chugh wants to merge 6 commits into
apache:masterfrom
tanishq-chugh:HIVE-30210
Open

tanishq-chugh wants to merge 6 commits into
apache:masterfrom
tanishq-chugh:HIVE-30210

Conversation

@tanishq-chugh

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Introduces a configuration to allow specifying the K8s namespaces to be monitored by the Hive K8s operator

Why are the changes needed?

To enable the Hive K8s Operator to manage Hive clusters across different namespaces, rather than only namespace where operator is deployed.

Does this PR introduce any user-facing change?

Yes, the end-user can now configure the namespaces which the K8s hive operator will watch for HiveCluster resources.

How was this patch tested?

Manual Testing

@tanishq-chugh

Copy link
Copy Markdown
Contributor Author

Hi @ayushtkn
Can you please help with a review on this PR?
Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Approval is blocked by a critical Helm template rendering error that produces invalid YAML and a moderate deployment configuration gap that prevents documented raw-manifest users from configuring cross-namespace watching.

2 open issues
What changed in this PR

Adds configurable namespace scoping for the Hive Kubernetes operator, allowing it to watch the release namespace, selected namespaces, or all namespaces through Helm configuration and environment variables.

Changes:

  • Added namespace configuration parsing and operator watch-scope setup.
  • Added the operator.watchNamespaces Helm value and deployment wiring.
  • Documented the supported namespace configuration formats.
File Description
packaging/​src/​kubernetes/​src/​java/​org/​apache/​hive/​kubernetes/​operator/​HiveOperatorMain.java Parses namespace configuration and applies the corresponding operator watch scope.
packaging/​src/​kubernetes/​README.md Documents the new Helm namespace configuration option.
packaging/​src/​kubernetes/​helm/​hive-operator/​values.yaml Defines the default and supported operator.watchNamespaces formats.
packaging/​src/​kubernetes/​helm/​hive-operator/​templates/​deployment.yaml Passes the configured namespace list to the operator through an environment variable.

Review effort: Lite

Comment on lines +40 to +44
{{- with .Values.operator.watchNamespaces }}
env:
- name: HIVE_OPERATOR_WATCH_NAMESPACES
value: {{ join "," . | quote }}
{{- end }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid. This would have occurred in case - trimming had been used even with the ending delimiter {{.
With the current patch, it is rendered correctly:

tanishqchugh@D7JR63VVY6 hive % helm template test packaging/src/kubernetes/helm/hive-operator \
  --set 'operator.watchNamespaces={ns1,ns2}' \
  -s templates/deployment.yaml
---
# Source: hive-operator/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-hive-operator
  namespace: default
  labels:
    app.kubernetes.io/name: hive-kubernetes-operator
    app.kubernetes.io/instance: test
    app.kubernetes.io/version: "4.3.0-SNAPSHOT"
    app.kubernetes.io/managed-by: Helm
    helm.sh/chart: hive-operator-4.3.0-SNAPSHOT
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: hive-kubernetes-operator
      app.kubernetes.io/instance: test
  template:
    metadata:
      labels:
        app.kubernetes.io/name: hive-kubernetes-operator
        app.kubernetes.io/instance: test
    spec:
      serviceAccountName: test-hive-operator
      containers:
        - name: operator
          image: "apache/hive:operator-4.3.0-SNAPSHOT"
          imagePullPolicy: IfNotPresent
          env:
            - name: HIVE_OPERATOR_WATCH_NAMESPACES
              value: "ns1,ns2"
          resources:
            limits:
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 256Mi
tanishqchugh@D7JR63VVY6 hive % 

Comment on lines +61 to +62
String watchNamespaces = System.getenv(WATCH_NAMESPACES_ENV_KEY);
String watchNsValue = watchNamespaces == null ? "" : watchNamespaces.trim();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit: 8e4df22

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants