Skip to content

Commit

Permalink
chore: set resource for kb init container and addon job (#5977)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldming authored Dec 2, 2023
1 parent a2380c1 commit 4051671
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 41 deletions.
85 changes: 44 additions & 41 deletions controllers/extensions/addon_controller_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func setInitContainer(addon *extensionsv1alpha1.Addon, helmJobPodSpec *corev1.Po
if fromPath == "" {
fromPath = localChartsPath
}
helmJobPodSpec.InitContainers = append(helmJobPodSpec.InitContainers, corev1.Container{
copyChartsContainer := corev1.Container{
Name: "copy-charts",
Image: addon.Spec.Helm.ChartsImage,
Command: []string{"sh", "-c", fmt.Sprintf("cp %s/* /mnt/charts", fromPath)},
Expand All @@ -467,7 +467,9 @@ func setInitContainer(addon *extensionsv1alpha1.Addon, helmJobPodSpec *corev1.Po
MountPath: "/mnt/charts",
},
},
})
}
intctrlutil.InjectZeroResourcesLimitsIfEmpty(&copyChartsContainer)
helmJobPodSpec.InitContainers = append(helmJobPodSpec.InitContainers, copyChartsContainer)
}

func (r *helmTypeInstallStage) Handle(ctx context.Context) {
Expand Down Expand Up @@ -854,6 +856,41 @@ func createHelmJobProto(addon *extensionsv1alpha1.Addon) (*batchv1.Job, error) {
}
ttlSec := int32(ttl.Seconds())
backoffLimit := int32(3)
container := corev1.Container{
Name: getJobMainContainerName(addon),
Image: viper.GetString(constant.KBToolsImage),
ImagePullPolicy: corev1.PullPolicy(viper.GetString(constant.CfgAddonJobImgPullPolicy)),
// TODO: need have image that is capable of following settings, current settings
// may expose potential security risk, as this pod is using cluster-admin clusterrole.
// SecurityContext: &corev1.SecurityContext{
// RunAsNonRoot: &[]bool{true}[0],
// RunAsUser: &[]int64{1001}[0],
// AllowPrivilegeEscalation: &[]bool{false}[0],
// Capabilities: &corev1.Capabilities{
// Drop: []corev1.Capability{
// "ALL",
// },
// },
// },
Command: []string{"helm"},
Env: []corev1.EnvVar{
{
Name: "RELEASE_NAME",
Value: getHelmReleaseName(addon),
},
{
Name: "RELEASE_NS",
Value: viper.GetString(constant.CfgKeyCtrlrMgrNS),
},
{
Name: "CHART",
Value: addon.Spec.Helm.ChartLocationURL,
},
},
VolumeMounts: []corev1.VolumeMount{},
}
intctrlutil.InjectZeroResourcesLimitsIfEmpty(&container)

helmProtoJob := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
Expand All @@ -874,45 +911,11 @@ func createHelmJobProto(addon *extensionsv1alpha1.Addon) (*batchv1.Job, error) {
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: viper.GetString("KUBEBLOCKS_ADDON_SA_NAME"),
Containers: []corev1.Container{
{
Name: getJobMainContainerName(addon),
Image: viper.GetString(constant.KBToolsImage),
ImagePullPolicy: corev1.PullPolicy(viper.GetString(constant.CfgAddonJobImgPullPolicy)),
// TODO: need have image that is capable of following settings, current settings
// may expose potential security risk, as this pod is using cluster-admin clusterrole.
// SecurityContext: &corev1.SecurityContext{
// RunAsNonRoot: &[]bool{true}[0],
// RunAsUser: &[]int64{1001}[0],
// AllowPrivilegeEscalation: &[]bool{false}[0],
// Capabilities: &corev1.Capabilities{
// Drop: []corev1.Capability{
// "ALL",
// },
// },
// },
Command: []string{"helm"},
Env: []corev1.EnvVar{
{
Name: "RELEASE_NAME",
Value: getHelmReleaseName(addon),
},
{
Name: "RELEASE_NS",
Value: viper.GetString(constant.CfgKeyCtrlrMgrNS),
},
{
Name: "CHART",
Value: addon.Spec.Helm.ChartLocationURL,
},
},
VolumeMounts: []corev1.VolumeMount{},
},
},
Volumes: []corev1.Volume{},
Tolerations: []corev1.Toleration{},
Affinity: &corev1.Affinity{},
NodeSelector: map[string]string{},
Containers: []corev1.Container{container},
Volumes: []corev1.Volume{},
Tolerations: []corev1.Toleration{},
Affinity: &corev1.Affinity{},
NodeSelector: map[string]string{},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/templates/dataprotection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- name: tools
image: "{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.tools.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
command:
- /bin/true
containers:
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ spec:
- name: tools
image: "{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.tools.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
command:
- /bin/true
- name: datascript
image: "{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.datascript.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
command:
- /bin/true
containers:
Expand Down

0 comments on commit 4051671

Please sign in to comment.