Skip to content

Commit cd79565

Browse files
ldmingapecloud-bot
authored andcommitted
chore: addon controller use kb sa (#9572)
(cherry picked from commit 13d89eb)
1 parent 7025c57 commit cd79565

7 files changed

Lines changed: 5 additions & 64 deletions

File tree

controllers/extensions/addon_controller_stages.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const (
6262
)
6363

6464
func init() {
65-
viper.SetDefault(addonSANameKey, "kubeblocks-addon-installer")
65+
viper.SetDefault(constant.KBServiceAccountName, "kubeblocks")
6666
viper.SetDefault(addonHelmInstallOptKey, []string{
6767
"--atomic",
6868
"--cleanup-on-fail",
@@ -598,7 +598,6 @@ func (r *helmTypeInstallStage) Handle(ctx context.Context) {
598598
chartsPath,
599599
"--namespace",
600600
"$(RELEASE_NS)",
601-
"--create-namespace",
602601
}, viper.GetStringSlice(addonHelmInstallOptKey)...)
603602

604603
installValues := addon.Spec.Helm.BuildMergedValues(addon.Spec.InstallSpec)
@@ -916,19 +915,7 @@ func createHelmJobProto(addon *extensionsv1alpha1.Addon) (*batchv1.Job, error) {
916915
Name: getJobMainContainerName(addon),
917916
Image: viper.GetString(constant.KBToolsImage),
918917
ImagePullPolicy: corev1.PullPolicy(viper.GetString(constant.CfgAddonJobImgPullPolicy)),
919-
// TODO: need have image that is capable of following settings, current settings
920-
// may expose potential security risk, as this pod is using cluster-admin clusterrole.
921-
// SecurityContext: &corev1.SecurityContext{
922-
// RunAsNonRoot: &[]bool{true}[0],
923-
// RunAsUser: &[]int64{1001}[0],
924-
// AllowPrivilegeEscalation: &[]bool{false}[0],
925-
// Capabilities: &corev1.Capabilities{
926-
// Drop: []corev1.Capability{
927-
// "ALL",
928-
// },
929-
// },
930-
// },
931-
Command: []string{"helm"},
918+
Command: []string{"helm"},
932919
Env: []corev1.EnvVar{
933920
{
934921
Name: "RELEASE_NAME",
@@ -966,7 +953,7 @@ func createHelmJobProto(addon *extensionsv1alpha1.Addon) (*batchv1.Job, error) {
966953
},
967954
Spec: corev1.PodSpec{
968955
RestartPolicy: corev1.RestartPolicyNever,
969-
ServiceAccountName: viper.GetString("KUBEBLOCKS_ADDON_SA_NAME"),
956+
ServiceAccountName: viper.GetString(constant.KBServiceAccountName),
970957
Containers: []corev1.Container{container},
971958
Volumes: []corev1.Volume{},
972959
Tolerations: []corev1.Toleration{},

controllers/extensions/const.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ const (
5454

5555
// config keys used in viper
5656
maxConcurrentReconcilesKey = "MAXCONCURRENTRECONCILES_ADDON"
57-
addonSANameKey = "KUBEBLOCKS_ADDON_SA_NAME"
5857
addonHelmInstallOptKey = "KUBEBLOCKS_ADDON_HELM_INSTALL_OPTIONS"
5958
addonHelmUninstallOptKey = "KUBEBLOCKS_ADDON_HELM_UNINSTALL_OPTIONS"
6059
)

deploy/helm/templates/_helpers.tpl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ Create the name of the service account to use
6161
{{- end }}
6262
{{- end }}
6363

64-
{{/*
65-
Create the addon installer name of the service account to use
66-
*/}}
67-
{{- define "kubeblocks.addonSAName" -}}
68-
{{- printf "%s-%s" (include "kubeblocks.serviceAccountName" .) "addon-installer" }}
69-
{{- end }}
70-
7164
{{/*
7265
Create the name of the webhook service.
7366
*/}}

deploy/helm/templates/deployment.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ spec:
146146
- name: ADDON_JOB_IMAGE_PULL_POLICY
147147
value: {{ .jobImagePullPolicy | default "IfNotPresent" }}
148148
{{- end }}
149-
- name: KUBEBLOCKS_ADDON_SA_NAME
150-
value: {{ include "kubeblocks.addonSAName" . }}
151149
- name: KUBEBLOCKS_ADDON_HELM_INSTALL_OPTIONS
152150
value: {{ join " " .Values.addonHelmInstallOptions }}
153151
- name: KUBEBLOCKS_ADDON_CHARTS_IMAGE_PULL_POLICY

deploy/helm/templates/rbac/clusterrole_binding.yaml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,4 @@ roleRef:
1111
subjects:
1212
- kind: ServiceAccount
1313
name: {{ include "kubeblocks.serviceAccountName" . }}
14-
namespace: {{ .Release.Namespace }}
15-
16-
{{- if ( include "kubeblocks.addonControllerEnabled" . ) | deepEqual "true" }}
17-
---
18-
apiVersion: rbac.authorization.k8s.io/v1
19-
kind: ClusterRoleBinding
20-
metadata:
21-
name: {{ include "kubeblocks.fullname" . }}-cluster-admin-rolebinding
22-
labels:
23-
{{- include "kubeblocks.labels" . | nindent 4 }}
24-
roleRef:
25-
apiGroup: rbac.authorization.k8s.io
26-
kind: ClusterRole
27-
name: cluster-admin
28-
subjects:
29-
- kind: ServiceAccount
30-
name: {{ include "kubeblocks.addonSAName" . }}
31-
namespace: {{ .Release.Namespace }}
32-
{{- end }}
14+
namespace: {{ .Release.Namespace }}

deploy/helm/templates/serviceaccount.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,6 @@ imagePullSecrets:
1414
{{- toYaml . | nindent 2 }}
1515
{{- end }}
1616

17-
{{- if ( include "kubeblocks.addonControllerEnabled" . ) | deepEqual "true" }}
18-
---
19-
apiVersion: v1
20-
kind: ServiceAccount
21-
metadata:
22-
name: {{ include "kubeblocks.addonSAName" . }}
23-
labels:
24-
{{- include "kubeblocks.labels" . | nindent 4 }}
25-
{{- with .Values.serviceAccount.annotations }}
26-
annotations:
27-
{{- toYaml . | nindent 4 }}
28-
{{- end }}
29-
{{- with .Values.addonChartsImage.pullSecrets }}
30-
imagePullSecrets:
31-
{{- toYaml . | nindent 2 }}
32-
{{- end }}
33-
{{- end }}
34-
3517
{{- if and .Values.dataProtection.enabled }}
3618
---
3719
apiVersion: v1

deploy/helm/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ backupRepo:
453453
accessKeyId: ""
454454
secretAccessKey: ""
455455

456-
## Addon controller settings, this will require cluster-admin clusterrole.
456+
## Addon controller settings
457457
##
458458
## @param addonController.enabled
459459
## @param addonController.jobTTL - is addon job time-to-live period, this value is time.Duration-parseable string.

0 commit comments

Comments
 (0)