From 39f08fa45a32f246227b57b4514bd557e0a55fc7 Mon Sep 17 00:00:00 2001 From: zhangtao <111836083+sophon-zt@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:25:27 +0800 Subject: [PATCH] feat: config-manager support custom tools image (#6957) --- apis/apps/v1beta1/configconstraint_types.go | 54 +++++++++++++- apis/apps/v1beta1/meta.go | 6 ++ apis/apps/v1beta1/zz_generated.deepcopy.go | 5 ++ .../apps.kubeblocks.io_configconstraints.yaml | 42 +++++++++-- .../apps.kubeblocks.io_configconstraints.yaml | 42 +++++++++-- docs/developer_docs/api-reference/cluster.md | 52 ++++++++++++++ .../config_manager/handler_util.go | 3 + pkg/constant/config.go | 22 ++++++ pkg/controller/configuration/config_utils.go | 4 +- .../configuration/tool_image_builder.go | 71 ++++++++++++++----- .../configuration/tool_image_builder_test.go | 5 +- pkg/controller/factory/builder.go | 11 ++- pkg/controller/factory/builder_test.go | 4 +- 13 files changed, 284 insertions(+), 37 deletions(-) create mode 100644 pkg/constant/config.go diff --git a/apis/apps/v1beta1/configconstraint_types.go b/apis/apps/v1beta1/configconstraint_types.go index 31a6ad42be8..4a09b1983ec 100644 --- a/apis/apps/v1beta1/configconstraint_types.go +++ b/apis/apps/v1beta1/configconstraint_types.go @@ -289,6 +289,56 @@ type ToolConfig struct { // +kubebuilder:validation:Pattern:=`^[a-z]([a-z0-9\-]*[a-z0-9])?$` Name string `json:"name,omitempty"` + // Indicates whether the tool image should be used as the container image for a sidecar. + // This is useful for large tool images, such as those for C++ tools, which may depend on + // numerous libraries (e.g., *.so files). + // + // If enabled, the tool image is deployed as a sidecar container image. + // + // Examples: + // ```yaml + // reloadToolsImage: + // mountPoint: /kb_tools + // toolConfigs: + // - name: kb-tools + // asContainerImage: true + // image: apecloud/oceanbase:4.2.0.0-100010032023083021 + // ``` + // + // generated containers: + // ```yaml + // initContainers: + // - name: install-config-manager-tool + // image: apecloud/kubeblocks-tools:${version} + // command: + // - cp + // - /bin/config_render + // - /opt/tools + // volumemounts: + // - name: kb-tools + // mountpath: /opt/tools + // + // containers: + // - name: config-manager + // image: apecloud/oceanbase:4.2.0.0-100010032023083021 + // imagePullPolicy: IfNotPresent + // command: + // - /opt/tools/reloader + // - --log-level + // - info + // - --operator-update-enable + // - --tcp + // - "9901" + // - --config + // - /opt/config-manager/config-manager.yaml + // volumemounts: + // - name: kb-tools + // mountpath: /opt/tools + // ``` + // + // +optional + AsContainerImage *bool `json:"asContainerImage,omitempty"` + // Specifies the tool container image. // // +optional @@ -296,8 +346,8 @@ type ToolConfig struct { // Specifies the command to be executed by the init container. // - // +kubebuilder:validation:Required - Command []string `json:"command"` + // +optional + Command []string `json:"command,omitempty"` } // DownwardAction defines an action that triggers specific commands in response to changes in Pod labels. diff --git a/apis/apps/v1beta1/meta.go b/apis/apps/v1beta1/meta.go index 98a27b1dd7e..ea697164bee 100644 --- a/apis/apps/v1beta1/meta.go +++ b/apis/apps/v1beta1/meta.go @@ -43,3 +43,9 @@ func (in *ConfigConstraintSpec) BatchReload() bool { func (cs *ConfigConstraintStatus) ConfigConstraintTerminalPhases() bool { return cs.Phase == CCAvailablePhase } + +func (tc *ToolConfig) AsSidecarContainerImage() bool { + return tc != nil && + tc.AsContainerImage != nil && + *tc.AsContainerImage +} diff --git a/apis/apps/v1beta1/zz_generated.deepcopy.go b/apis/apps/v1beta1/zz_generated.deepcopy.go index 95e1235802b..ea1400a1236 100644 --- a/apis/apps/v1beta1/zz_generated.deepcopy.go +++ b/apis/apps/v1beta1/zz_generated.deepcopy.go @@ -419,6 +419,11 @@ func (in *TPLScriptTrigger) DeepCopy() *TPLScriptTrigger { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ToolConfig) DeepCopyInto(out *ToolConfig) { *out = *in + if in.AsContainerImage != nil { + in, out := &in.AsContainerImage, &out.AsContainerImage + *out = new(bool) + **out = **in + } if in.Command != nil { in, out := &in.Command, &out.Command *out = make([]string, len(*in)) diff --git a/config/crd/bases/apps.kubeblocks.io_configconstraints.yaml b/config/crd/bases/apps.kubeblocks.io_configconstraints.yaml index 85ec6fd443d..e622ac8c04d 100644 --- a/config/crd/bases/apps.kubeblocks.io_configconstraints.yaml +++ b/config/crd/bases/apps.kubeblocks.io_configconstraints.yaml @@ -533,6 +533,25 @@ spec: description: ToolConfig specifies the settings of an init container that prepare tools for dynamic reload. properties: + asContainerImage: + description: "Indicates whether the tool image should be + used as the container image for a sidecar. This is useful + for large tool images, such as those for C++ tools, which + may depend on numerous libraries (e.g., *.so files). \n + If enabled, the tool image is deployed as a sidecar container + image. \n Examples: ```yaml reloadToolsImage: mountPoint: + /kb_tools toolConfigs: - name: kb-tools asContainerImage: + true image: apecloud/oceanbase:4.2.0.0-100010032023083021 + ``` \n generated containers: ```yaml initContainers: - + name: install-config-manager-tool image: apecloud/kubeblocks-tools:${version} + command: - cp - /bin/config_render - /opt/tools volumemounts: + - name: kb-tools mountpath: /opt/tools \n containers: + - name: config-manager image: apecloud/oceanbase:4.2.0.0-100010032023083021 + imagePullPolicy: IfNotPresent command: - /opt/tools/reloader + - --log-level - info - --operator-update-enable - --tcp + - \"9901\" - --config - /opt/config-manager/config-manager.yaml + volumemounts: - name: kb-tools mountpath: /opt/tools ```" + type: boolean command: description: Specifies the command to be executed by the init container. @@ -547,8 +566,6 @@ spec: maxLength: 63 pattern: ^[a-z]([a-z0-9\-]*[a-z0-9])?$ type: string - required: - - command type: object type: array required: @@ -1063,6 +1080,25 @@ spec: description: ToolConfig specifies the settings of an init container that prepare tools for dynamic reload. properties: + asContainerImage: + description: "Indicates whether the tool image should be + used as the container image for a sidecar. This is useful + for large tool images, such as those for C++ tools, which + may depend on numerous libraries (e.g., *.so files). \n + If enabled, the tool image is deployed as a sidecar container + image. \n Examples: ```yaml reloadToolsImage: mountPoint: + /kb_tools toolConfigs: - name: kb-tools asContainerImage: + true image: apecloud/oceanbase:4.2.0.0-100010032023083021 + ``` \n generated containers: ```yaml initContainers: - + name: install-config-manager-tool image: apecloud/kubeblocks-tools:${version} + command: - cp - /bin/config_render - /opt/tools volumemounts: + - name: kb-tools mountpath: /opt/tools \n containers: + - name: config-manager image: apecloud/oceanbase:4.2.0.0-100010032023083021 + imagePullPolicy: IfNotPresent command: - /opt/tools/reloader + - --log-level - info - --operator-update-enable - --tcp + - \"9901\" - --config - /opt/config-manager/config-manager.yaml + volumemounts: - name: kb-tools mountpath: /opt/tools ```" + type: boolean command: description: Specifies the command to be executed by the init container. @@ -1077,8 +1113,6 @@ spec: maxLength: 63 pattern: ^[a-z]([a-z0-9\-]*[a-z0-9])?$ type: string - required: - - command type: object type: array required: diff --git a/deploy/helm/crds/apps.kubeblocks.io_configconstraints.yaml b/deploy/helm/crds/apps.kubeblocks.io_configconstraints.yaml index 85ec6fd443d..e622ac8c04d 100644 --- a/deploy/helm/crds/apps.kubeblocks.io_configconstraints.yaml +++ b/deploy/helm/crds/apps.kubeblocks.io_configconstraints.yaml @@ -533,6 +533,25 @@ spec: description: ToolConfig specifies the settings of an init container that prepare tools for dynamic reload. properties: + asContainerImage: + description: "Indicates whether the tool image should be + used as the container image for a sidecar. This is useful + for large tool images, such as those for C++ tools, which + may depend on numerous libraries (e.g., *.so files). \n + If enabled, the tool image is deployed as a sidecar container + image. \n Examples: ```yaml reloadToolsImage: mountPoint: + /kb_tools toolConfigs: - name: kb-tools asContainerImage: + true image: apecloud/oceanbase:4.2.0.0-100010032023083021 + ``` \n generated containers: ```yaml initContainers: - + name: install-config-manager-tool image: apecloud/kubeblocks-tools:${version} + command: - cp - /bin/config_render - /opt/tools volumemounts: + - name: kb-tools mountpath: /opt/tools \n containers: + - name: config-manager image: apecloud/oceanbase:4.2.0.0-100010032023083021 + imagePullPolicy: IfNotPresent command: - /opt/tools/reloader + - --log-level - info - --operator-update-enable - --tcp + - \"9901\" - --config - /opt/config-manager/config-manager.yaml + volumemounts: - name: kb-tools mountpath: /opt/tools ```" + type: boolean command: description: Specifies the command to be executed by the init container. @@ -547,8 +566,6 @@ spec: maxLength: 63 pattern: ^[a-z]([a-z0-9\-]*[a-z0-9])?$ type: string - required: - - command type: object type: array required: @@ -1063,6 +1080,25 @@ spec: description: ToolConfig specifies the settings of an init container that prepare tools for dynamic reload. properties: + asContainerImage: + description: "Indicates whether the tool image should be + used as the container image for a sidecar. This is useful + for large tool images, such as those for C++ tools, which + may depend on numerous libraries (e.g., *.so files). \n + If enabled, the tool image is deployed as a sidecar container + image. \n Examples: ```yaml reloadToolsImage: mountPoint: + /kb_tools toolConfigs: - name: kb-tools asContainerImage: + true image: apecloud/oceanbase:4.2.0.0-100010032023083021 + ``` \n generated containers: ```yaml initContainers: - + name: install-config-manager-tool image: apecloud/kubeblocks-tools:${version} + command: - cp - /bin/config_render - /opt/tools volumemounts: + - name: kb-tools mountpath: /opt/tools \n containers: + - name: config-manager image: apecloud/oceanbase:4.2.0.0-100010032023083021 + imagePullPolicy: IfNotPresent command: - /opt/tools/reloader + - --log-level - info - --operator-update-enable - --tcp + - \"9901\" - --config - /opt/config-manager/config-manager.yaml + volumemounts: - name: kb-tools mountpath: /opt/tools ```" + type: boolean command: description: Specifies the command to be executed by the init container. @@ -1077,8 +1113,6 @@ spec: maxLength: 63 pattern: ^[a-z]([a-z0-9\-]*[a-z0-9])?$ type: string - required: - - command type: object type: array required: diff --git a/docs/developer_docs/api-reference/cluster.md b/docs/developer_docs/api-reference/cluster.md index 115baab0b31..ca01d866bfb 100644 --- a/docs/developer_docs/api-reference/cluster.md +++ b/docs/developer_docs/api-reference/cluster.md @@ -22138,6 +22138,57 @@ string
asContainerImage
Indicates whether the tool image should be used as the container image for a sidecar. +This is useful for large tool images, such as those for C++ tools, which may depend on +numerous libraries (e.g., *.so files).
+If enabled, the tool image is deployed as a sidecar container image.
+Examples:
+ reloadToolsImage:
+ mountPoint: /kb_tools
+ toolConfigs:
+ - name: kb-tools
+ asContainerImage: true
+ image: apecloud/oceanbase:4.2.0.0-100010032023083021
+
+generated containers:
+initContainers:
+ - name: install-config-manager-tool
+ image: apecloud/kubeblocks-tools:${version}
+ command:
+ - cp
+ - /bin/config_render
+ - /opt/tools
+ volumemounts:
+ - name: kb-tools
+ mountpath: /opt/tools
+containers:
+ - name: config-manager
+ image: apecloud/oceanbase:4.2.0.0-100010032023083021
+ imagePullPolicy: IfNotPresent
+ command:
+ - /opt/tools/reloader
+ - --log-level
+ - info
+ - --operator-update-enable
+ - --tcp
+ - "9901"
+ - --config
+ - /opt/config-manager/config-manager.yaml
+ volumemounts:
+ - name: kb-tools
+ mountpath: /opt/tools
+
+image
Specifies the command to be executed by the init container.