From b7c6a38e0f549b62288c4497e4af08029a72c831 Mon Sep 17 00:00:00 2001 From: yandongxiao Date: Tue, 19 Nov 2024 23:29:19 +0800 Subject: [PATCH] review code Signed-off-by: yandongxiao --- ...cks-when-readOnlyRootFilesystem-is-true.md | 174 +++++++++--------- .../charts/starrocks/values.yaml | 23 ++- helm-charts/charts/kube-starrocks/values.yaml | 18 ++ pkg/common/common.go | 62 +------ pkg/k8sutils/templates/pod/spec.go | 69 ++++++- pkg/k8sutils/templates/pod/spec_test.go | 38 ++++ pkg/subcontrollers/be/be_controller.go | 3 +- pkg/subcontrollers/be/be_pod.go | 14 +- pkg/subcontrollers/cn/cn_controller.go | 3 +- pkg/subcontrollers/cn/cn_pod.go | 10 +- pkg/subcontrollers/fe/fe_controller.go | 3 +- pkg/subcontrollers/fe/fe_pod.go | 14 +- 12 files changed, 258 insertions(+), 173 deletions(-) diff --git a/doc/setup-starrocks-when-readOnlyRootFilesystem-is-true.md b/doc/setup-starrocks-when-readOnlyRootFilesystem-is-true.md index d40eae6f..e614f905 100644 --- a/doc/setup-starrocks-when-readOnlyRootFilesystem-is-true.md +++ b/doc/setup-starrocks-when-readOnlyRootFilesystem-is-true.md @@ -65,55 +65,63 @@ metadata: namespace: starrocks spec: starRocksFeSpec: - command: [ "bash", "-c" ] - args: - - cp -r /opt/starrocks/* /opt/starrocks-artifacts && export STARROCKS_ROOT=/opt/starrocks-artifacts && exec /opt/starrocks-artifacts/fe_entrypoint.sh $FE_SERVICE_NAME readOnlyRootFilesystem: true + runAsNonRoot: true configMapInfo: configMapName: kube-starrocks-fe-cm resolveKey: fe.conf + storageVolumes: + - mountPath: /opt/starrocks-artifacts + name: fe-artifacts + storageClassName: emptyDir + storageSize: 20Gi + - mountPath: /opt/starrocks-meta + name: fe-meta + storageSize: 10Gi + - mountPath: /opt/starrocks-log + name: fe-log + storageSize: 10Gi + command: ["bash", "-c"] + args: + - cp -r /opt/starrocks/* /opt/starrocks-artifacts && exec /opt/starrocks-artifacts/fe_entrypoint.sh $FE_SERVICE_NAME + feEnvVars: + - name: STARROCKS_ROOT + value: /opt/starrocks-artifacts image: starrocks/fe-ubuntu:3.2.2 imagePullPolicy: IfNotPresent replicas: 1 requests: cpu: 1m memory: 22Mi - storageVolumes: - - mountPath: /opt/starrocks-artifacts - name: fe-artifacts - storageClassName: emptyDir - storageSize: 20Gi - - mountPath: /opt/starrocks-meta - name: fe-meta - storageSize: 10Gi - - mountPath: /opt/starrocks-log - name: fe-log - storageSize: 10Gi starRocksBeSpec: - command: [ "bash", "-c" ] - args: - - cp -r /opt/starrocks/* /opt/starrocks-artifacts && export STARROCKS_ROOT=/opt/starrocks-artifacts && exec /opt/starrocks-artifacts/be_entrypoint.sh $FE_SERVICE_NAME readOnlyRootFilesystem: true + runAsNonRoot: true configMapInfo: configMapName: kube-starrocks-be-cm resolveKey: be.conf + storageVolumes: + - mountPath: /opt/starrocks-artifacts + name: be-artifacts + storageClassName: emptyDir + storageSize: 20Gi + - mountPath: /opt/starrocks-storage + name: be-storage # the name must be this + storageSize: 10Gi + - mountPath: /opt/starrocks-log + name: be-log # the name must be this + storageSize: 10Gi + command: ["bash", "-c"] + args: + - cp -r /opt/starrocks/* /opt/starrocks-artifacts && exec /opt/starrocks-artifacts/be_entrypoint.sh $FE_SERVICE_NAME + beEnvVars: + - name: STARROCKS_ROOT + value: /opt/starrocks-artifacts image: starrocks/be-ubuntu:3.2.2 imagePullPolicy: IfNotPresent - replicas: 1 + replicas: 2 requests: cpu: 1m memory: 10Mi - storageVolumes: - - mountPath: /opt/starrocks-artifacts - name: be-artifacts - storageClassName: emptyDir - storageSize: 20Gi - - mountPath: /opt/starrocks-storage - name: be-storage # the name must be this - storageSize: 10Gi - - mountPath: /opt/starrocks-log - name: be-log # the name must be this - storageSize: 10Gi --- @@ -129,7 +137,7 @@ data: edit_log_port = 9010 mysql_service_nio_enabled = true sys_log_level = INFO - + # config for meta and log meta_dir = /opt/starrocks-meta dump_log_dir = /opt/starrocks-log @@ -171,7 +179,7 @@ If you are using the `kube-starrocks` Helm chart, add the following snippets to operator: starrocksOperator: image: - repository: operator + repository: starrocks/operator tag: v1.9.9-rc1 imagePullPolicy: IfNotPresent resources: @@ -179,59 +187,26 @@ operator: cpu: 1m memory: 20Mi starrocks: - initPassword: - enabled: false - password: "123456" - starrocksBeSpec: + starrocksFESpec: readOnlyRootFilesystem: true - entrypoint: - script: | - #! /bin/bash - echo "do something before start BE" - cp -r /opt/starrocks/* /opt/starrocks-artifacts - export STARROCKS_ROOT=/opt/starrocks-artifacts - exec /opt/starrocks-artifacts/be_entrypoint.sh $FE_SERVICE_NAME - image: - repository: starrocks/be-ubuntu - tag: 3.2.2 - replicas: 1 - resources: - limits: - cpu: 8 - memory: 8Gi - requests: - cpu: 1m - memory: 10Mi + runAsNonRoot: true storageSpec: - name: be + name: fe storageSize: 10Gi - storageMountPath: /opt/starrocks-storage + storageMountPath: /opt/starrocks-meta logStorageSize: 10Gi logMountPath: /opt/starrocks-log - spillStorageSize: 10Gi - spillMountPath: /opt/starrocks-spill emptyDirs: - - name: be-artifacts - mountPath: /opt/starrocks-artifacts - config: | - be_port = 9060 - webserver_port = 8040 - heartbeat_service_port = 9050 - brpc_port = 8060 - sys_log_level = INFO - default_rowset_type = beta - # config for storage and log - storage_root_path = /opt/starrocks-storage - sys_log_dir = /opt/starrocks-log - spill_local_storage_dir = /opt/starrocks-spill - starrocksFESpec: - readOnlyRootFilesystem: true + - name: fe-artifacts + mountPath: /opt/starrocks-artifacts entrypoint: script: | #! /bin/bash cp -r /opt/starrocks/* /opt/starrocks-artifacts - export STARROCKS_ROOT=/opt/starrocks-artifacts exec /opt/starrocks/fe_entrypoint.sh $FE_SERVICE_NAME + feEnvVars: + - name: STARROCKS_ROOT + value: /opt/starrocks-artifacts image: repository: starrocks/fe-ubuntu tag: 3.2.2 @@ -242,15 +217,6 @@ starrocks: requests: cpu: 1m memory: 20Mi - storageSpec: - name: fe - storageSize: 10Gi - storageMountPath: /opt/starrocks-meta - logStorageSize: 10Gi - logMountPath: /opt/starrocks-log - emptyDirs: - - name: fe-artifacts - mountPath: /opt/starrocks-artifacts config: | LOG_DIR = ${STARROCKS_HOME}/log DATE = "$(date +%Y%m%d-%H%M%S)" @@ -266,4 +232,48 @@ starrocks: dump_log_dir = /opt/starrocks-log sys_log_dir = /opt/starrocks-log audit_log_dir = /opt/starrocks-log + starrocksBeSpec: + readOnlyRootFilesystem: true + runAsNonRoot: true + storageSpec: + name: be + storageSize: 10Gi + storageMountPath: /opt/starrocks-storage + logStorageSize: 10Gi + logMountPath: /opt/starrocks-log + spillStorageSize: 10Gi + spillMountPath: /opt/starrocks-spill + emptyDirs: + - name: be-artifacts + mountPath: /opt/starrocks-artifacts + entrypoint: + script: | + #! /bin/bash + cp -r /opt/starrocks/* /opt/starrocks-artifacts + exec /opt/starrocks-artifacts/be_entrypoint.sh $FE_SERVICE_NAME + beEnvVars: + - name: STARROCKS_ROOT + value: /opt/starrocks-artifacts + image: + repository: starrocks/be-ubuntu + tag: 3.2.2 + replicas: 1 + resources: + limits: + cpu: 8 + memory: 8Gi + requests: + cpu: 1m + memory: 10Mi + config: | + be_port = 9060 + webserver_port = 8040 + heartbeat_service_port = 9050 + brpc_port = 8060 + sys_log_level = INFO + default_rowset_type = beta + # config for storage and log + storage_root_path = /opt/starrocks-storage + sys_log_dir = /opt/starrocks-log + spill_local_storage_dir = /opt/starrocks-spill ``` \ No newline at end of file diff --git a/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml b/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml index 80639c74..ff44dc03 100644 --- a/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml +++ b/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml @@ -286,10 +286,15 @@ starrocksFESpec: storageSize: 10Gi # If storageMountPath is empty, the storageMountPath will be set to /opt/starrocks/fe/meta. storageMountPath: "" - logMountPath: "" # Setting this parameter can persist log storage, and the mount path is /opt/starrocks/fe/log. # If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted. logStorageSize: 5Gi + # If logMountPath is empty, the logMountPath will be set to /opt/starrocks/fe/log. + # If logMountPath is not /opt/starrocks/fe/log, you must add in config the following configuration: + # dump_log_dir = xxx + # sys_log_dir = xxx + # audit_log_dir = xxx + logMountPath: "" # mount emptyDir volumes if necessary. # Note: please use storageSpec field for persistent metadata and log. emptyDirs: [] @@ -588,15 +593,19 @@ starrocksCnSpec: storageCount: 1 # see the comment of storageCount for the usage of storageMountPath. storageMountPath: "" - logMountPath: "" - spillMountPath: "" # the storage size of persistent volume for log, and the mount path is /opt/starrocks/cn/log. # If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted. logStorageSize: 20Gi + # If logMountPath is empty, the logMountPath will be set to /opt/starrocks/cn/log. + # If logMountPath is not /opt/starrocks/cn/log, you must add in config the following configuration: sys_log_dir = xxx. + logMountPath: "" # Setting this parameter can persist spill storage, and the mount path is /opt/starrocks/cn/spill. # If you set it to 0Gi, the related PVC will not be created, and the spill will not be persisted. # You need to add in be.conf spill_local_storage_dir=/opt/starrocks/cn/spill. spillStorageSize: 0Gi + # If spillMountPath is empty, the spillMountPath will be set to /opt/starrocks/cn/spill. + # If spillMountPath is not /opt/starrocks/cn/spill, you must add in config the following configuration: spill_local_storage_dir = xxx. + spillMountPath: "" # mount emptyDir volumes if necessary. # Note: please use storageSpec field for persistent storage data and log. emptyDirs: [] @@ -868,15 +877,19 @@ starrocksBeSpec: storageCount: 1 # see the comment of storageCount for the usage of storageMountPath. storageMountPath: "" - logMountPath: "" - spillMountPath: "" # Setting this parameter can persist log storage, and the mount path is /opt/starrocks/be/log. # If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted. logStorageSize: 20Gi + # If logMountPath is empty, the logMountPath will be set to /opt/starrocks/be/log. + # If logMountPath is not /opt/starrocks/be/log, you must add in config the following configuration: sys_log_dir = xxx. + logMountPath: "" # Setting this parameter can persist spill storage, and the mount path is /opt/starrocks/be/spill. # If you set it to 0Gi, the related PVC will not be created, and the spill will not be persisted. # You need to add in be.conf spill_local_storage_dir=/opt/starrocks/be/spill. spillStorageSize: 0Gi + # If spillMountPath is empty, the spillMountPath will be set to /opt/starrocks/be/spill. + # If spillMountPath is not /opt/starrocks/be/spill, you must add in config the following configuration: spill_local_storage_dir = xxx. + spillMountPath: "" # mount emptyDir volumes if necessary. # Note: please use storageSpec field for persistent storage data and log. emptyDirs: [] diff --git a/helm-charts/charts/kube-starrocks/values.yaml b/helm-charts/charts/kube-starrocks/values.yaml index fcd6a542..2cc7be95 100644 --- a/helm-charts/charts/kube-starrocks/values.yaml +++ b/helm-charts/charts/kube-starrocks/values.yaml @@ -397,6 +397,12 @@ starrocks: # Setting this parameter can persist log storage, and the mount path is /opt/starrocks/fe/log. # If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted. logStorageSize: 5Gi + # If logMountPath is empty, the logMountPath will be set to /opt/starrocks/fe/log. + # If logMountPath is not /opt/starrocks/fe/log, you must add in config the following configuration: + # dump_log_dir = xxx + # sys_log_dir = xxx + # audit_log_dir = xxx + logMountPath: "" # mount emptyDir volumes if necessary. # Note: please use storageSpec field for persistent metadata and log. emptyDirs: [] @@ -698,10 +704,16 @@ starrocks: # the storage size of persistent volume for log, and the mount path is /opt/starrocks/cn/log. # If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted. logStorageSize: 20Gi + # If logMountPath is empty, the logMountPath will be set to /opt/starrocks/cn/log. + # If logMountPath is not /opt/starrocks/cn/log, you must add in config the following configuration: sys_log_dir = xxx. + logMountPath: "" # Setting this parameter can persist spill storage, and the mount path is /opt/starrocks/cn/spill. # If you set it to 0Gi, the related PVC will not be created, and the spill will not be persisted. # You need to add in be.conf spill_local_storage_dir=/opt/starrocks/cn/spill. spillStorageSize: 0Gi + # If spillMountPath is empty, the spillMountPath will be set to /opt/starrocks/cn/spill. + # If spillMountPath is not /opt/starrocks/cn/spill, you must add in config the following configuration: spill_local_storage_dir = xxx. + spillMountPath: "" # mount emptyDir volumes if necessary. # Note: please use storageSpec field for persistent storage data and log. emptyDirs: [] @@ -976,10 +988,16 @@ starrocks: # Setting this parameter can persist log storage, and the mount path is /opt/starrocks/be/log. # If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted. logStorageSize: 20Gi + # If logMountPath is empty, the logMountPath will be set to /opt/starrocks/be/log. + # If logMountPath is not /opt/starrocks/be/log, you must add in config the following configuration: sys_log_dir = xxx. + logMountPath: "" # Setting this parameter can persist spill storage, and the mount path is /opt/starrocks/be/spill. # If you set it to 0Gi, the related PVC will not be created, and the spill will not be persisted. # You need to add in be.conf spill_local_storage_dir=/opt/starrocks/be/spill. spillStorageSize: 0Gi + # If spillMountPath is empty, the spillMountPath will be set to /opt/starrocks/be/spill. + # If spillMountPath is not /opt/starrocks/be/spill, you must add in config the following configuration: spill_local_storage_dir = xxx. + spillMountPath: "" # mount emptyDir volumes if necessary. # Note: please use storageSpec field for persistent storage data and log. emptyDirs: [] diff --git a/pkg/common/common.go b/pkg/common/common.go index 531f5c24..a02ebd99 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -1,69 +1,9 @@ package common -import ( - "fmt" - "strings" - - corev1 "k8s.io/api/core/v1" -) +import "strings" func EqualsIgnoreCase(a, b string) bool { a = strings.ToLower(a) b = strings.ToLower(b) return a == b } - -func GetStarRocksRootPath(envVars []corev1.EnvVar) string { - if envVars != nil { - for _, env := range envVars { - if EqualsIgnoreCase(env.Name, "STARROCKS_ROOT") { - return env.Value - } - } - } - return "/opt/starrocks" -} - -func GetFEPreStopScriptPath(feEnvVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/fe_prestop.sh", GetStarRocksRootPath(feEnvVars)) -} - -func GetBEPreStopScriptPath(beEnvVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/be_prestop.sh", GetStarRocksRootPath(beEnvVars)) -} - -func GetCNPreStopScriptPath(cnEnvVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/cn_prestop.sh", GetStarRocksRootPath(cnEnvVars)) -} - -func GetFEConfigDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/fe/conf", GetStarRocksRootPath(envVars)) -} - -func GetBEConfigDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/be/conf", GetStarRocksRootPath(envVars)) -} - -func GetCNConfigDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/cn/conf", GetStarRocksRootPath(envVars)) -} - -func GetFELogDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/fe/log", GetStarRocksRootPath(envVars)) -} - -func GetBELogDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/be/log", GetStarRocksRootPath(envVars)) -} - -func GetCNLogDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/cn/log", GetStarRocksRootPath(envVars)) -} - -func GetFEMetaDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/fe/meta", GetStarRocksRootPath(envVars)) -} - -func GetBEStorageDir(envVars []corev1.EnvVar) string { - return fmt.Sprintf("%s/be/storage", GetStarRocksRootPath(envVars)) -} diff --git a/pkg/k8sutils/templates/pod/spec.go b/pkg/k8sutils/templates/pod/spec.go index 7c595475..090a84da 100644 --- a/pkg/k8sutils/templates/pod/spec.go +++ b/pkg/k8sutils/templates/pod/spec.go @@ -322,15 +322,78 @@ func ContainerSecurityContext(spec v1.SpecInterface) *corev1.SecurityContext { func getDefaultEntrypointScript(spec v1.SpecInterface) string { switch v := spec.(type) { case *v1.StarRocksFeSpec: - return fmt.Sprintf("%s/fe_entrypoint.sh", common.GetStarRocksRootPath(v.FeEnvVars)) + return fmt.Sprintf("%s/fe_entrypoint.sh", GetStarRocksRootPath(v.FeEnvVars)) case *v1.StarRocksBeSpec: - return fmt.Sprintf("%s/be_entrypoint.sh", common.GetStarRocksRootPath(v.BeEnvVars)) + return fmt.Sprintf("%s/be_entrypoint.sh", GetStarRocksRootPath(v.BeEnvVars)) case *v1.StarRocksCnSpec: - return fmt.Sprintf("%s/cn_entrypoint.sh", common.GetStarRocksRootPath(v.CnEnvVars)) + return fmt.Sprintf("%s/cn_entrypoint.sh", GetStarRocksRootPath(v.CnEnvVars)) } return "" } +func GetStorageDir(spec v1.SpecInterface) string { + switch v := spec.(type) { + case *v1.StarRocksFeSpec: + return fmt.Sprintf("%s/fe/meta", GetStarRocksRootPath(v.FeEnvVars)) + case *v1.StarRocksBeSpec: + return fmt.Sprintf("%s/be/storage", GetStarRocksRootPath(v.BeEnvVars)) + case *v1.StarRocksCnSpec: + return fmt.Sprintf("%s/cn/storage", GetStarRocksRootPath(v.CnEnvVars)) + } + return "" +} + +func GetLogDir(spec v1.SpecInterface) string { + switch v := spec.(type) { + case *v1.StarRocksFeSpec: + return fmt.Sprintf("%s/fe/log", GetStarRocksRootPath(v.FeEnvVars)) + case *v1.StarRocksBeSpec: + return fmt.Sprintf("%s/be/log", GetStarRocksRootPath(v.BeEnvVars)) + case *v1.StarRocksCnSpec: + return fmt.Sprintf("%s/cn/log", GetStarRocksRootPath(v.CnEnvVars)) + } + return "" +} + +func GetConfigDir(spec v1.SpecInterface) string { + switch v := spec.(type) { + case *v1.StarRocksFeSpec: + return fmt.Sprintf("%s/fe/conf", GetStarRocksRootPath(v.FeEnvVars)) + case *v1.StarRocksBeSpec: + return fmt.Sprintf("%s/be/conf", GetStarRocksRootPath(v.BeEnvVars)) + case *v1.StarRocksCnSpec: + return fmt.Sprintf("%s/cn/conf", GetStarRocksRootPath(v.CnEnvVars)) + } + return "" +} + +func GetPreStopScriptPath(spec v1.SpecInterface) string { + switch v := spec.(type) { + case *v1.StarRocksFeSpec: + return fmt.Sprintf("%s/fe_prestop.sh", GetStarRocksRootPath(v.FeEnvVars)) + case *v1.StarRocksBeSpec: + return fmt.Sprintf("%s/be_prestop.sh", GetStarRocksRootPath(v.BeEnvVars)) + case *v1.StarRocksCnSpec: + return fmt.Sprintf("%s/cn_prestop.sh", GetStarRocksRootPath(v.CnEnvVars)) + } + return "" +} + +func GetStarRocksDefaultRootPath() string { + return "/opt/starrocks" +} + +func GetStarRocksRootPath(envVars []corev1.EnvVar) string { + if envVars != nil { + for _, env := range envVars { + if common.EqualsIgnoreCase(env.Name, "STARROCKS_ROOT") { + return env.Value + } + } + } + return "/opt/starrocks" +} + func ContainerCommand(spec v1.SpecInterface) []string { if spec.GetCommand() != nil { return spec.GetCommand() diff --git a/pkg/k8sutils/templates/pod/spec_test.go b/pkg/k8sutils/templates/pod/spec_test.go index 9917d463..bbf16d19 100644 --- a/pkg/k8sutils/templates/pod/spec_test.go +++ b/pkg/k8sutils/templates/pod/spec_test.go @@ -591,3 +591,41 @@ func TestK8sYamlMarshal(t *testing.T) { }) } } + +func TestGetStarRocksRootPath(t *testing.T) { + type args struct { + envVars []corev1.EnvVar + } + tests := []struct { + name string + args args + want string + }{ + { + name: "test get starrocks root path - 1", + args: args{ + envVars: nil, + }, + want: "/opt/starrocks", + }, + { + name: "test get starrocks root path - 2", + args: args{ + envVars: []corev1.EnvVar{ + { + Name: "STARROCKS_ROOT", + Value: "xxx", + }, + }, + }, + want: "xxx", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetStarRocksRootPath(tt.args.envVars); got != tt.want { + t.Errorf("GetStarRocksRootPath() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/subcontrollers/be/be_controller.go b/pkg/subcontrollers/be/be_controller.go index af6a58a8..329f5e1c 100644 --- a/pkg/subcontrollers/be/be_controller.go +++ b/pkg/subcontrollers/be/be_controller.go @@ -30,7 +30,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1" - "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/log" rutils "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/resource_utils" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils" @@ -212,7 +211,7 @@ func (be *BeController) generateInternalService(ctx context.Context, func (be *BeController) GetBeConfig(ctx context.Context, beSpec *srapi.StarRocksBeSpec, namespace string) (map[string]interface{}, error) { return k8sutils.GetConfig(ctx, be.Client, beSpec.ConfigMapInfo, - beSpec.ConfigMaps, common.GetBEConfigDir(beSpec.BeEnvVars), "be.conf", namespace) + beSpec.ConfigMaps, pod.GetConfigDir(beSpec), "be.conf", namespace) } func (be *BeController) ClearResources(ctx context.Context, src *srapi.StarRocksCluster) error { diff --git a/pkg/subcontrollers/be/be_pod.go b/pkg/subcontrollers/be/be_pod.go index a7512a77..5c1d6dfd 100644 --- a/pkg/subcontrollers/be/be_pod.go +++ b/pkg/subcontrollers/be/be_pod.go @@ -21,7 +21,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1" - "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common" rutils "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/resource_utils" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils/templates/pod" @@ -44,14 +43,14 @@ func (be *BeController) buildPodTemplate(src *srapi.StarRocksCluster, config map vols, volumeMounts := pod.MountStorageVolumes(beSpec) if !k8sutils.HasVolume(vols, _storageName) && !k8sutils.HasVolume(vols, _storageName2) && - !k8sutils.HasMountPath(volumeMounts, common.GetBEStorageDir(beSpec.BeEnvVars)) { + !k8sutils.HasMountPath(volumeMounts, pod.GetStorageDir(beSpec)) { // Changing the volume name to _storageName2 is fine, it will only affect users who did not persist data. // The reason why we need to change the volume name is that the helm chart uses the format _storageName2 // Keeping the same suffix will make user easy to use feature, like init-containers and sidecars. - vols, volumeMounts = pod.MountEmptyDirVolume(vols, volumeMounts, _storageName2, common.GetBEStorageDir(beSpec.BeEnvVars), "") + vols, volumeMounts = pod.MountEmptyDirVolume(vols, volumeMounts, _storageName2, pod.GetStorageDir(beSpec), "") } - if !k8sutils.HasVolume(vols, _logName) && !k8sutils.HasMountPath(volumeMounts, common.GetBELogDir(beSpec.BeEnvVars)) { - vols, volumeMounts = pod.MountEmptyDirVolume(vols, volumeMounts, _logName, common.GetBELogDir(beSpec.BeEnvVars), "") + if !k8sutils.HasVolume(vols, _logName) && !k8sutils.HasMountPath(volumeMounts, pod.GetLogDir(beSpec)) { + vols, volumeMounts = pod.MountEmptyDirVolume(vols, volumeMounts, _logName, pod.GetLogDir(beSpec), "") } // mount configmap, secrets to pod if needed @@ -78,9 +77,12 @@ func (be *BeController) buildPodTemplate(src *srapi.StarRocksCluster, config map StartupProbe: pod.StartupProbe(beSpec.GetStartupProbeFailureSeconds(), webServerPort, pod.HEALTH_API_PATH), LivenessProbe: pod.LivenessProbe(beSpec.GetLivenessProbeFailureSeconds(), webServerPort, pod.HEALTH_API_PATH), ReadinessProbe: pod.ReadinessProbe(beSpec.GetReadinessProbeFailureSeconds(), webServerPort, pod.HEALTH_API_PATH), - Lifecycle: pod.LifeCycle(beSpec.GetLifecycle(), common.GetBEPreStopScriptPath(beSpec.BeEnvVars)), + Lifecycle: pod.LifeCycle(beSpec.GetLifecycle(), pod.GetPreStopScriptPath(beSpec)), SecurityContext: pod.ContainerSecurityContext(beSpec), } + if pod.GetStarRocksRootPath(beSpec.BeEnvVars) != pod.GetStarRocksDefaultRootPath() { + beContainer.WorkingDir = pod.GetStarRocksRootPath(beSpec.BeEnvVars) + } if beSpec.ConfigMapInfo.ConfigMapName != "" && beSpec.ConfigMapInfo.ResolveKey != "" { beContainer.Env = append(beContainer.Env, corev1.EnvVar{ Name: _envBeConfigPath, diff --git a/pkg/subcontrollers/cn/cn_controller.go b/pkg/subcontrollers/cn/cn_controller.go index b6a20929..b36937ad 100644 --- a/pkg/subcontrollers/cn/cn_controller.go +++ b/pkg/subcontrollers/cn/cn_controller.go @@ -33,7 +33,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1" - "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/hash" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/log" rutils "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/resource_utils" @@ -429,7 +428,7 @@ func (cc *CnController) ClearResources(ctx context.Context, src *srapi.StarRocks func (cc *CnController) GetCnConfig(ctx context.Context, cnSpec *srapi.StarRocksCnSpec, namespace string) (map[string]interface{}, error) { return k8sutils.GetConfig(ctx, cc.k8sClient, cnSpec.ConfigMapInfo, - cnSpec.ConfigMaps, common.GetCNConfigDir(cnSpec.CnEnvVars), "cn.conf", + cnSpec.ConfigMaps, pod.GetConfigDir(cnSpec), "cn.conf", namespace) } diff --git a/pkg/subcontrollers/cn/cn_pod.go b/pkg/subcontrollers/cn/cn_pod.go index a11b3c0d..23c2be9b 100644 --- a/pkg/subcontrollers/cn/cn_pod.go +++ b/pkg/subcontrollers/cn/cn_pod.go @@ -29,7 +29,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1" - "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common" rutils "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/resource_utils" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils" srobject "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils/templates/object" @@ -48,8 +47,8 @@ func (cc *CnController) buildPodTemplate(ctx context.Context, object srobject.St cnSpec *srapi.StarRocksCnSpec, config map[string]interface{}) (*corev1.PodTemplateSpec, error) { vols, volumeMounts := pod.MountStorageVolumes(cnSpec) - if !k8sutils.HasVolume(vols, _logName) && !k8sutils.HasMountPath(volumeMounts, common.GetCNLogDir(cnSpec.CnEnvVars)) { - vols, volumeMounts = pod.MountEmptyDirVolume(vols, volumeMounts, _logName, common.GetCNLogDir(cnSpec.CnEnvVars), "") + if !k8sutils.HasVolume(vols, _logName) && !k8sutils.HasMountPath(volumeMounts, pod.GetLogDir(cnSpec)) { + vols, volumeMounts = pod.MountEmptyDirVolume(vols, volumeMounts, _logName, pod.GetLogDir(cnSpec), "") } // mount configmap, secrets to pod if needed @@ -89,9 +88,12 @@ func (cc *CnController) buildPodTemplate(ctx context.Context, object srobject.St StartupProbe: pod.StartupProbe(cnSpec.GetStartupProbeFailureSeconds(), webServerPort, pod.HEALTH_API_PATH), LivenessProbe: pod.LivenessProbe(cnSpec.GetLivenessProbeFailureSeconds(), webServerPort, pod.HEALTH_API_PATH), ReadinessProbe: pod.ReadinessProbe(cnSpec.GetReadinessProbeFailureSeconds(), webServerPort, pod.HEALTH_API_PATH), - Lifecycle: pod.LifeCycle(cnSpec.GetLifecycle(), common.GetCNPreStopScriptPath(cnSpec.CnEnvVars)), + Lifecycle: pod.LifeCycle(cnSpec.GetLifecycle(), pod.GetPreStopScriptPath(cnSpec)), SecurityContext: pod.ContainerSecurityContext(cnSpec), } + if pod.GetStarRocksRootPath(cnSpec.CnEnvVars) != pod.GetStarRocksDefaultRootPath() { + cnContainer.WorkingDir = pod.GetStarRocksRootPath(cnSpec.CnEnvVars) + } if cnSpec.ConfigMapInfo.ConfigMapName != "" && cnSpec.ConfigMapInfo.ResolveKey != "" { cnContainer.Env = append(cnContainer.Env, corev1.EnvVar{ diff --git a/pkg/subcontrollers/fe/fe_controller.go b/pkg/subcontrollers/fe/fe_controller.go index 779fbabc..f581485c 100644 --- a/pkg/subcontrollers/fe/fe_controller.go +++ b/pkg/subcontrollers/fe/fe_controller.go @@ -29,7 +29,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1" - "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/log" rutils "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/resource_utils" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils" @@ -225,7 +224,7 @@ func (fc *FeController) Validating(feSpec *srapi.StarRocksFeSpec) error { func GetFEConfig(ctx context.Context, client client.Client, feSpec *srapi.StarRocksFeSpec, namespace string) (map[string]interface{}, error) { return k8sutils.GetConfig(ctx, client, feSpec.ConfigMapInfo, - feSpec.ConfigMaps, common.GetFEConfigDir(feSpec.FeEnvVars), "fe.conf", + feSpec.ConfigMaps, pod.GetConfigDir(feSpec), "fe.conf", namespace) } diff --git a/pkg/subcontrollers/fe/fe_pod.go b/pkg/subcontrollers/fe/fe_pod.go index 1c88481a..abb6c96c 100644 --- a/pkg/subcontrollers/fe/fe_pod.go +++ b/pkg/subcontrollers/fe/fe_pod.go @@ -21,7 +21,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1" - "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common" rutils "github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/resource_utils" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils" "github.com/StarRocks/starrocks-kubernetes-operator/pkg/k8sutils/templates/pod" @@ -42,11 +41,11 @@ func (fc *FeController) buildPodTemplate(src *srapi.StarRocksCluster, config map vols, volMounts := pod.MountStorageVolumes(feSpec) // add default volume about log, meta if not configure. - if !k8sutils.HasVolume(vols, _metaName) && !k8sutils.HasMountPath(volMounts, common.GetFEMetaDir(feSpec.FeEnvVars)) { - vols, volMounts = pod.MountEmptyDirVolume(vols, volMounts, _metaName, common.GetFEMetaDir(feSpec.FeEnvVars), "") + if !k8sutils.HasVolume(vols, _metaName) && !k8sutils.HasMountPath(volMounts, pod.GetStorageDir(feSpec)) { + vols, volMounts = pod.MountEmptyDirVolume(vols, volMounts, _metaName, pod.GetStorageDir(feSpec), "") } - if !k8sutils.HasVolume(vols, _logName) && !k8sutils.HasMountPath(volMounts, common.GetFELogDir(feSpec.FeEnvVars)) { - vols, volMounts = pod.MountEmptyDirVolume(vols, volMounts, _logName, common.GetFELogDir(feSpec.FeEnvVars), "") + if !k8sutils.HasVolume(vols, _logName) && !k8sutils.HasMountPath(volMounts, pod.GetLogDir(feSpec)) { + vols, volMounts = pod.MountEmptyDirVolume(vols, volMounts, _logName, pod.GetLogDir(feSpec), "") } // mount configmap, secrets to pod if needed @@ -73,9 +72,12 @@ func (fc *FeController) buildPodTemplate(src *srapi.StarRocksCluster, config map StartupProbe: pod.StartupProbe(feSpec.GetStartupProbeFailureSeconds(), httpPort, pod.HEALTH_API_PATH), LivenessProbe: pod.LivenessProbe(feSpec.GetLivenessProbeFailureSeconds(), httpPort, pod.HEALTH_API_PATH), ReadinessProbe: pod.ReadinessProbe(feSpec.GetReadinessProbeFailureSeconds(), httpPort, pod.HEALTH_API_PATH), - Lifecycle: pod.LifeCycle(feSpec.GetLifecycle(), common.GetFEPreStopScriptPath(feSpec.FeEnvVars)), + Lifecycle: pod.LifeCycle(feSpec.GetLifecycle(), pod.GetPreStopScriptPath(feSpec)), SecurityContext: pod.ContainerSecurityContext(feSpec), } + if pod.GetStarRocksRootPath(feSpec.FeEnvVars) != pod.GetStarRocksDefaultRootPath() { + feContainer.WorkingDir = pod.GetStarRocksRootPath(feSpec.FeEnvVars) + } if feSpec.ConfigMapInfo.ConfigMapName != "" && feSpec.ConfigMapInfo.ResolveKey != "" { feContainer.Env = append(feContainer.Env, corev1.EnvVar{