Skip to content

Allow ECK-Operator to easily watch deployed namespace#8830

Open
developer67890 wants to merge 3 commits intoelastic:mainfrom
developer67890:single-namespace-mode
Open

Allow ECK-Operator to easily watch deployed namespace#8830
developer67890 wants to merge 3 commits intoelastic:mainfrom
developer67890:single-namespace-mode

Conversation

@developer67890
Copy link

This change adds a Helm Chart value singleNamespaceMode which configures to the operator to watch its deployed namespace if true.

While this could have been achieved by including the deployed namespace in the managedNamespaces list, it requires a user to specify a second time this namespace.

helm install elastic-operator ./eck-operator -n my-namespace --create-namespace \
  --set=managedNamespaces='{my-namespace}' \
...

This model is fragile and prone to mistyping or omissions. Other products have accomplished a similar feature by including something like clusterWide=false, which will result in the same behavior this PR achieves.

Changes:

  • add singleNamespaceMode value to values.yaml, including short comment explanation
  • if singleNamespaceMode = true, only include .Release.Namespace in the namespaces field of the Configmap.
  • update documentation for "Install the operator restricted to a single namespace"

Resolves #8828

@cla-checker-service
Copy link

cla-checker-service bot commented Sep 29, 2025

❌ Author of the following commits did not sign a Contributor Agreement:
646dc1e, 56ee0ca, 13220a3

Please, read and sign the above mentioned agreement if you want to contribute to this project

@prodsecmachine
Copy link
Collaborator

prodsecmachine commented Sep 29, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@botelastic botelastic bot added the triage label Sep 29, 2025
@barkbay barkbay self-requested a review January 15, 2026 09:22
webhook-port: {{ .Values.webhook.port }}
{{- end }}
{{- with .Values.managedNamespaces }}
{{- if .Values.singleNamespaceMode }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we validate that managedNamespaces is not set if singleNamespaceMode is true?
Something along the lines of:

Suggested change
{{- if .Values.singleNamespaceMode }}
{{- if and .Values.singleNamespaceMode .Values.managedNamespaces }}
{{- fail "managedNamespaces should not be set when singleNamespaceMode is enabled" }}
{{- end }}
{{- if .Values.singleNamespaceMode }}

Copy link
Contributor

@barkbay barkbay left a comment

Choose a reason for hiding this comment

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

Let's also create some unit tests in deploy/eck-operator/templates/tests/configmap_test.yaml:

# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: test configmap
templates:
  - configmap.yaml
tests:
  - it: should render configmap with default values
    asserts:
      - isKind:
          of: ConfigMap
      - equal:
          path: metadata.name
          value: elastic-operator

  - it: should set namespaces to release namespace when singleNamespaceMode is enabled
    set:
      singleNamespaceMode: true
    release:
      namespace: my-namespace
    asserts:
      - isKind:
          of: ConfigMap
      - matchRegex:
          path: data.eck\.yaml
          pattern: "namespaces: \\[my-namespace\\]"

  - it: should set namespaces from managedNamespaces when singleNamespaceMode is disabled
    set:
      singleNamespaceMode: false
      managedNamespaces:
        - ns1
        - ns2
        - ns3
    asserts:
      - isKind:
          of: ConfigMap
      - matchRegex:
          path: data.eck\.yaml
          pattern: "namespaces: \\[ns1,ns2,ns3\\]"

  - it: should fail when both singleNamespaceMode and managedNamespaces are set
    set:
      singleNamespaceMode: true
      managedNamespaces:
        - ns1
    asserts:
      - failedTemplate:
          errorMessage: "managedNamespaces should not be set when singleNamespaceMode is enabled"

  - it: should not set namespaces when neither singleNamespaceMode nor managedNamespaces are set
    set:
      singleNamespaceMode: false
      managedNamespaces: []
    asserts:
      - isKind:
          of: ConfigMap
      - notMatchRegex:
          path: data.eck\.yaml
          pattern: "namespaces:"

  - it: should set metrics port correctly
    set:
      config:
        metrics:
          port: 9090
          secureMode:
            enabled: false
    asserts:
      - isKind:
          of: ConfigMap
      - matchRegex:
          path: data.eck\.yaml
          pattern: "metrics-port: 9090"

  - it: should fail when metrics secureMode is enabled but port is 0
    set:
      config:
        metrics:
          port: 0
          secureMode:
            enabled: true
    asserts:
      - failedTemplate:
          errorMessage: "config.metrics.port must be greater than 0 when config.metrics.secureMode.enabled is true"

  - it: should set container registry correctly
    set:
      config:
        containerRegistry: my-registry.example.com
    asserts:
      - isKind:
          of: ConfigMap
      - matchRegex:
          path: data.eck\.yaml
          pattern: "container-registry: my-registry.example.com"

  - it: should set setDefaultSecurityContext correctly
    set:
      config:
        setDefaultSecurityContext: "true"
    asserts:
      - isKind:
          of: ConfigMap
      - matchRegex:
          path: data.eck\.yaml
          pattern: "set-default-security-context: true"

Copy link
Contributor

@barkbay barkbay left a comment

Choose a reason for hiding this comment

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

@developer67890 sorry for the very late review, I think I'm 👍 with your proposal. I let a comment about adding a validation and some unit tests. Let me know what you think.

@barkbay barkbay added the >enhancement Enhancement of existing functionality label Jan 15, 2026
@botelastic botelastic bot removed the triage label Jan 15, 2026
@botelastic botelastic bot removed the triage label Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement Enhancement of existing functionality :helm-charts v3.4.0 (next next)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ease Namespace Configuration

3 participants