Skip to content

Commit

Permalink
feat: config-manager support custom tools image (#6957)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt authored Apr 25, 2024
1 parent 67c6336 commit 39f08fa
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 37 deletions.
54 changes: 52 additions & 2 deletions apis/apps/v1beta1/configconstraint_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,65 @@ 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
Image string `json:"image,omitempty"`

// 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.
Expand Down
6 changes: 6 additions & 0 deletions apis/apps/v1beta1/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions apis/apps/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 38 additions & 4 deletions config/crd/bases/apps.kubeblocks.io_configconstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
42 changes: 38 additions & 4 deletions deploy/helm/crds/apps.kubeblocks.io_configconstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
52 changes: 52 additions & 0 deletions docs/developer_docs/api-reference/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -22138,6 +22138,57 @@ string
</tr>
<tr>
<td>
<code>asContainerImage</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>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).</p>
<p>If enabled, the tool image is deployed as a sidecar container image.</p>
<p>Examples:</p>
<pre><code class="language-yaml"> reloadToolsImage:
mountPoint: /kb_tools
toolConfigs:
- name: kb-tools
asContainerImage: true
image: apecloud/oceanbase:4.2.0.0-100010032023083021
</code></pre>
<p>generated containers:</p>
<pre><code class="language-yaml">initContainers:
- name: install-config-manager-tool
image: apecloud/kubeblocks-tools:$&#123;version&#125;
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
- &quot;9901&quot;
- --config
- /opt/config-manager/config-manager.yaml
volumemounts:
- name: kb-tools
mountpath: /opt/tools
</code></pre>
</td>
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
Expand All @@ -22156,6 +22207,7 @@ string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Specifies the command to be executed by the init container.</p>
</td>
</tr>
Expand Down
3 changes: 3 additions & 0 deletions pkg/configuration/config_manager/handler_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type CfgManagerBuildParams struct {
CMConfigVolumes []corev1.Volume
ConfigLazyRenderedVolumes map[string]corev1.VolumeMount

// support custom config manager sidecar
ConfigManagerReloadPath string `json:"configManagerReloadPath"`

// support host network
ContainerPort int32 `json:"containerPort"`
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/constant/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright (C) 2022-2024 ApeCloud Co., Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package constant

const (
TPLRenderToolPath = "/bin/config_render"
ConfigManagerToolPath = "/bin/reloader"
)
4 changes: 2 additions & 2 deletions pkg/controller/configuration/config_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func buildConfigManagerWithComponent(podSpec *corev1.PodSpec, configSpecs []apps
func checkAndUpdateSharProcessNamespace(podSpec *corev1.PodSpec, buildParams *cfgcm.CfgManagerBuildParams, configSpecMetas []cfgcm.ConfigSpecMeta) {
shared := cfgcm.NeedSharedProcessNamespace(configSpecMetas)
if shared {
podSpec.ShareProcessNamespace = func() *bool { b := true; return &b }()
podSpec.ShareProcessNamespace = cfgutil.ToPointer(true)
}
buildParams.ShareProcessNamespace = shared
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func buildConfigManagerParams(cli client.Client, ctx context.Context, cluster *a
if err := cfgcm.BuildConfigManagerContainerParams(cli, ctx, cfgManagerParams, volumeDirs); err != nil {
return nil, err
}
if err := buildConfigToolsContainer(cfgManagerParams, podSpec, comp); err != nil {
if err := buildReloadToolsContainer(cfgManagerParams, podSpec); err != nil {
return nil, err
}
return cfgManagerParams, nil
Expand Down
Loading

0 comments on commit 39f08fa

Please sign in to comment.