ClickHouseOperatorConfiguration watch.namespaces.include is overwritten by env WATCH_NAMESPACE in OLM installation

クローズ
#2,008 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go, kubernetes

調査の方向性

pkg/chop/config_manager.go から始めて Postprocess() を追跡し、次に pkg/apis/clickhouse.altinity.com/v1/type_configuration_chop.go の applyEnvVarParams() を調査します。WATCH_NAMESPACE と spec.watch.namespaces.include の意図された優先順位を特定し、最終的な設定で明示的に構成された CR の値が保持されるか、環境変数の優先順位が文書化されていることを確認します。

索引モデルが issue の本文から書いたものです。

説明

Description

When ClickHouse Operator is installed via OLM, the generated CSV contains the following environment variable:

- name: WATCH_NAMESPACE
  valueFrom:
    fieldRef:
      fieldPath: metadata.namespace

As a result, the operator pod starts with:

WATCH_NAMESPACE=openshift-operators

I created a ClickHouseOperatorConfiguration resource to enable watch-all mode:

apiVersion: clickhouse.altinity.com/v1
kind: ClickHouseOperatorConfiguration
metadata:
  name: watch-all-namespaces
  namespace: openshift-operators
spec:
  watch:
    namespaces:
      include:
        - ".*"

According to the default operator configuration template, [".*"] should force watch-all mode:

https://github.com/Altinity/clickhouse-operator/blob/master/deploy/builder/templates-config/config.yaml

Observed behavior

The operator successfully discovers and loads the ClickHouseOperatorConfiguration resource:

I0615 12:13:42.047018       1 config_manager.go:150] getAllCRBasedConfigs():Looking for ClickHouseOperatorConfigurations in namespace 'openshift-operators'.
I0615 12:13:43.086423       1 config_manager.go:183] getAllCRBasedConfigs():Append ClickHouseOperatorConfigurations 'openshift-operators/watch-all-namespaces'.

The CR-based configuration contains the expected value:

watch:
  namespaces:
    include:
      - .*

The merged configuration also contains the expected value:

Unified CHOP config - with secret data fetched (but not post-processed yet)
runtime:
    configFilePath: /etc/clickhouse-operator/config.yaml
    configFolderPath: /etc/clickhouse-operator
    configCRNamespace: openshift-operators
    configCRName: watch-all-namespaces
    configCRSources:
        - namespace: openshift-operators
          name: watch-all-namespaces
    namespace: ""
watch:
    namespaces:
        include:
            - .*

However, after post-processing, the final configuration changes to:

Final CHOP config
runtime:
    configFilePath: /etc/clickhouse-operator/config.yaml
    configFolderPath: /etc/clickhouse-operator
    configCRNamespace: openshift-operators
    configCRName: watch-all-namespaces
    configCRSources:
        - namespace: openshift-operators
          name: watch-all-namespaces
    namespace: openshift-operators

watch:
    namespaces:
        include:
            - openshift-operators

As a result, ClickHouseInstallation resources created in other namespaces are not reconciled.

Investigation

The operator calls Postprocess() between the "Unified CHOP config" and "Final CHOP config" stages:

https://github.com/Altinity/clickhouse-operator/blob/release-0.27.1/pkg/chop/config_manager.go#L129

log.V(1).Info("Unified CHOP config - with secret data fetched (but not post-processed yet):")
log.V(1).Info("\n" + cm.config.String(true))

cm.Postprocess()

log.V(1).Info("Final CHOP config:")
log.V(1).Info("\n" + cm.config.String(true))

Postprocess() invokes applyEnvVarParams():

https://github.com/Altinity/clickhouse-operator/blob/release-0.27.1/pkg/apis/clickhouse.altinity.com/v1/type_configuration_chop.go#L1486

func (c *OperatorConfig) applyEnvVarParams() {
	if ns := os.Getenv(deployment.WATCH_NAMESPACE); len(ns) > 0 {
		// We have WATCH_NAMESPACE explicitly specified
		c.Watch.Namespaces.Include = types.NewStrings([]string{ns})
	}

	if nss := os.Getenv(deployment.WATCH_NAMESPACES); len(nss) > 0 {
		// We have WATCH_NAMESPACES explicitly specified
		if namespaces := c.splitNamespaces(nss); len(namespaces) > 0 {
			c.Watch.Namespaces.Include = types.NewStrings(namespaces)
		}
	}

	if nss := os.Getenv(deployment.WATCH_NAMESPACES_EXCLUDE); len(nss) > 0 {
		// We have WATCH_NAMESPACES_EXCLUDE explicitly specified
		if namespaces := c.splitNamespaces(nss); len(namespaces) > 0 {
			c.Watch.Namespaces.Exclude = types.NewStrings(namespaces)
		}
	}
}

This appears to overwrite the value previously loaded from ClickHouseOperatorConfiguration.

Expected behavior

If spec.watch.namespaces.include is explicitly configured in ClickHouseOperatorConfiguration, it should remain unchanged during post-processing.

Alternatively, if WATCH_NAMESPACE is expected to have higher priority in OLM deployments, this behavior should be documented explicitly.

Question

Is this expected behavior for OLM installations, or is this a configuration precedence issue?

Environment
  • RedHat OpenShift cluster version 4.20.19
  • Operator installed from OLM Community Operators
  • Altinity® Kubernetes Operator for ClickHouse version 0.27.1
主要言語
Go
スター
2.6k
フォーク
584
平均マージ
4日 5時間
マージ済み PR(30日)
16

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Altinity/clickhouse-operator のほかの issue

Altinity/clickhouse-operator の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。