apiVersion: starrocks.com/v1
kind: StarRocksCluster
metadata:
  name: {{ template "starrockscluster.name" . }}
  namespace: {{ template "starrockscluster.namespace" . }}
  labels:
    cluster: {{ template "starrockscluster.name" . }}
  {{- include "starrockscluster.labels" . | nindent 4 }}
  {{- if .Values.starrocksCluster.annotations }}
  annotations:
    {{- toYaml .Values.starrocksCluster.annotations | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.starrocksCluster.disasterRecovery }}
  disasterRecovery:
    {{- toYaml .Values.starrocksCluster.disasterRecovery | nindent 4 }}
  {{- end }}
  starRocksFeSpec:
    {{- if .Values.starrocksFESpec.initContainers }}
    initContainers:
      {{- toYaml .Values.starrocksFESpec.initContainers | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksFESpec.shareProcessNamespace }}
    shareProcessNamespace: {{ .Values.starrocksFESpec.shareProcessNamespace }}
    {{- end }}
    image: "{{ .Values.starrocksFESpec.image.repository }}:{{ include "starrockscluster.fe.image.tag" . }}"
    {{- if .Values.starrocksFESpec.entrypoint }}
    command: ["bash", "-c"]
    args:
      - {{template "starrockscluster.entrypoint.mount.path" .}}/{{template "starrockscluster.entrypoint.script.name" .}}
    {{- end }}
    replicas: {{ .Values.starrocksFESpec.replicas }}
    imagePullPolicy: {{ .Values.starrocksFESpec.imagePullPolicy }}
    {{- if .Values.starrocksFESpec.maxUnavailablePods }}
    updateStrategy:
      rollingUpdate:
        maxUnavailable: {{ .Values.starrocksFESpec.maxUnavailablePods }}
    {{- end }}
    {{- /*
    support both resources and resource for backward compatibility
    */}}
    {{- if .Values.starrocksFESpec.resources }}
    {{- include "starrockscluster.fe.resources" . | nindent 4 }}
    {{- else if .Values.starrocksFESpec.resource }}
    {{- toYaml .Values.starrocksFESpec.resource | nindent 4 }}
    {{- end }}
    {{- if .Values.starrocksFESpec.service.type }}
    service:
      type: {{ .Values.starrocksFESpec.service.type }}
      {{- if and (eq "LoadBalancer" .Values.starrocksFESpec.service.type) .Values.starrocksFESpec.service.loadbalancerIP }}
      loadBalancerIP: {{ .Values.starrocksFESpec.service.loadbalancerIP }}
      {{- end }}
      {{- if and (eq "LoadBalancer" .Values.starrocksFESpec.service.type) .Values.starrocksFESpec.service.loadBalancerSourceRanges}}
      loadBalancerSourceRanges:
        {{- toYaml .Values.starrocksFESpec.service.loadBalancerSourceRanges | nindent 8 }}
      {{- end }}
      {{- if .Values.starrocksFESpec.service.ports }}
      ports:
        {{- toYaml .Values.starrocksFESpec.service.ports | nindent 8 }}
      {{- end }}
      {{- if or .Values.starrocksFESpec.service.annotations .Values.datadog.metrics.enabled }}
      annotations:
        {{- if .Values.datadog.metrics.enabled }}
        prometheus.io/path: "/metrics"
        prometheus.io/port: "{{- default 8030 (include "starrockscluster.fe.http.port" .) }}"
        prometheus.io/scrape: "true"
        {{- end }}
        {{- if .Values.starrocksFESpec.service.annotations}}
        {{- toYaml .Values.starrocksFESpec.service.annotations | nindent 8 }}
        {{- end }}
      {{- end }}
      {{- if .Values.starrocksFESpec.service.labels}}
      labels:
        {{- toYaml .Values.starrocksFESpec.service.labels | nindent 8 }}
      {{- end }}
    {{- end }}
    annotations:
      app.starrocks.io/fe-config-hash: "{{template "starrockscluster.fe.config.hash" . }}"
      {{- if .Values.datadog.log.enabled }}
      {{- if eq (trimAll " {}" .Values.datadog.log.logConfig) "" }}
      ad.datadoghq.com/fe.logs: '[{"service":"starrocks","source":"fe"}]'
      {{- else }}
      ad.datadoghq.com/fe.logs: {{ printf "[%s]" (printf "{%s, \"source\": \"fe\", \"service\": \"starrocks\"}" (trimAll " {}" .Values.datadog.log.logConfig) | fromJson | toJson) | squote }}
      {{- end }}
      {{- end }}
      {{- if .Values.starrocksFESpec.entrypoint }}
      app.starrocks.io/fe-entrypoint-hash: "{{ template "starrockscluster.fe.entrypoint.script.hash" . }}"
      {{- end }}
      {{- if .Values.starrocksFESpec.annotations }}
      {{- toYaml .Values.starrocksFESpec.annotations | nindent 6 }}
      {{- end }}
    {{- if or .Values.starrocksFESpec.imagePullSecrets .Values.starrocksCluster.componentValues.imagePullSecrets }}
    imagePullSecrets:
      {{- include "starrockscluster.fe.imagePullSecrets" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.serviceAccount .Values.starrocksCluster.componentValues.serviceAccount }}
    serviceAccount: {{ include "starrockscluster.fe.serviceAccount" . }}
    {{- end }}
    runAsNonRoot: {{ include "starrockscluster.fe.runAsNonRoot" . }}
    {{- if .Values.starrocksFESpec.readOnlyRootFilesystem }}
    readOnlyRootFilesystem: {{ .Values.starrocksFESpec.readOnlyRootFilesystem }}
    {{- end }}
    {{- if .Values.starrocksFESpec.capabilities }}
    capabilities:
      {{- toYaml .Values.starrocksFESpec.capabilities | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksFESpec.sysctls }}
    sysctls:
      {{- toYaml .Values.starrocksFESpec.sysctls | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.nodeSelector .Values.starrocksCluster.componentValues.nodeSelector }}
    nodeSelector:
      {{- include "starrockscluster.fe.nodeSelector" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.podLabels .Values.starrocksCluster.componentValues.podLabels .Values.datadog.profiling.fe }}
    podLabels:
      {{- if or .Values.starrocksFESpec.podLabels .Values.starrocksCluster.componentValues.podLabels }}
      {{- include "starrockscluster.fe.podLabels" . | nindent 6 }}
      {{- end }}
      {{- if .Values.datadog.profiling.fe }}
      admission.datadoghq.com/config.mode: {{ .Values.datadog.profiling.configMode }}
      admission.datadoghq.com/enabled: "true"
      {{- end }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.hostAliases .Values.starrocksCluster.componentValues.hostAliases }}
    hostAliases:
      {{- include "starrockscluster.fe.hostAliases" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.schedulerName .Values.starrocksCluster.componentValues.schedulerName }}
    schedulerName: {{ include "starrockscluster.fe.schedulerName" . }}
    {{- end }}
    feEnvVars:
      - name: TZ
        value: {{ .Values.timeZone }}
      {{- if .Values.datadog.log.enabled }}
      - name: LOG_CONSOLE
        value: "1"
      {{- end }}
      {{- if and .Values.initPassword.enabled (.Values.starrocksFESpec.feEnvVars | toJson | contains "MYSQL_PWD" | not) }}
      - name: "MYSQL_PWD"
        valueFrom:
          secretKeyRef:
            name: {{ template "starrockscluster.initpassword.secret.name" . }}
            key: password
      {{- end }}
      {{- if .Values.datadog.profiling.fe }}
      - name: ENABLE_DATADOG_PROFILE
        value: "true"
      - name: DD_PROFILING_ENABLED
        value: "true"
      - name: DD_SERVICE
        value: starrocks-fe
      - name: DD_ENV
        value: "{{ .Values.datadog.profiling.env }}"
      - name: DD_VERSION
        value: "{{ include "starrockscluster.fe.image.tag" . }}"
      - name: DD_PROFILING_DDPROF_ALLOC_ENABLED
        value: "true"
      - name: DD_PROFILING_DDPROF_ENABLED
        value: "true"
      - name: DD_PROFILING_DDPROF_LIVEHEAP_ENABLED
        value: "true"
      - name: DD_PROFILING_DIRECTALLOCATION_ENABLED
        value: "true"
      {{- end }}
      {{- if .Values.starrocksFESpec.feEnvVars }}
      {{- /* if it is a map, we use range to iterate to merge environment variables */}}
      {{- if eq (kindOf .Values.starrocksFESpec.feEnvVars) "map" }}
      {{- range $key, $value := .Values.starrocksFESpec.feEnvVars }}
      - name: {{ $key }}
        {{- if eq (kindOf $value) "string" }}
        value: {{ $value | quote }}
        {{- else }}
        {{- toYaml $value | nindent 8 }}
        {{- end }}
      {{- end }}
      {{- else }}
      {{- /* the default kind is slice, we keep backward compatibility */}}
      {{- toYaml .Values.starrocksFESpec.feEnvVars | nindent 6 }}
      {{- end }}
      {{- end }}
    {{- if or .Values.starrocksFESpec.affinity .Values.starrocksCluster.componentValues.affinity }}
    affinity:
      {{- include "starrockscluster.fe.affinity" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.tolerations .Values.starrocksCluster.componentValues.tolerations }}
    tolerations:
      {{- include "starrockscluster.fe.tolerations" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.topologySpreadConstraints .Values.starrocksCluster.componentValues.topologySpreadConstraints }}
    topologySpreadConstraints:
      {{- include "starrockscluster.fe.topologySpreadConstraints" . | nindent 6 }}
    {{- end }}
    terminationGracePeriodSeconds: {{ .Values.starrocksFESpec.terminationGracePeriodSeconds }}
    {{- if .Values.starrocksFESpec.startupProbeFailureSeconds }}
    startupProbeFailureSeconds: {{ .Values.starrocksFESpec.startupProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksFESpec.livenessProbeFailureSeconds }}
    livenessProbeFailureSeconds: {{ .Values.starrocksFESpec.livenessProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksFESpec.readinessProbeFailureSeconds }}
    readinessProbeFailureSeconds: {{ .Values.starrocksFESpec.readinessProbeFailureSeconds }}
    {{- end }}
    minReadySeconds: {{ .Values.starrocksFESpec.minReadySeconds }}
    podManagementPolicy: {{ .Values.starrocksFESpec.podManagementPolicy }}
    {{- if .Values.starrocksFESpec.lifecycle }}
    lifecycle:
      {{- toYaml .Values.starrocksFESpec.lifecycle | nindent 6 }}
    {{- end }}
    {{- if and .Values.starrocksFESpec.sidecarsMap .Values.starrocksFESpec.sidecars }}
      {{ fail "starrocksFESpec.sidecarsMap and starrocksFESpec.sidecars cannot be set at the same time" }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.sidecarsMap .Values.starrocksFESpec.sidecars }}
    sidecars:
      {{- if .Values.starrocksFESpec.sidecarsMap }}
      {{- range $name, $spec := .Values.starrocksFESpec.sidecarsMap }}
      - name: {{ $name }}
        {{- toYaml $spec | nindent 8 }}
      {{- end }}
      {{- else if .Values.starrocksFESpec.sidecars }}
      {{- toYaml .Values.starrocksFESpec.sidecars | nindent 6 }}
      {{- end }}
    {{- end }}
    {{- if .Values.starrocksFESpec.secrets }}
    secrets:
    {{- range .Values.starrocksFESpec.secrets }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      subPath: {{ .subPath }}
    {{- end }}
    {{- end }}
    {{- if or .Values.starrocksFESpec.configMaps .Values.starrocksFESpec.entrypoint }}
    configMaps:
    {{- if .Values.starrocksFESpec.configMaps }}
    {{- range .Values.starrocksFESpec.configMaps }}
      - name: {{ .name }}
        mountPath: {{ .mountPath }}
        subPath: {{ .subPath }}
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksFESpec.entrypoint }}
      - name: {{template "starrockscluster.fe.entrypoint.script.configmap.name" .}}
        mountPath: {{template "starrockscluster.entrypoint.mount.path" .}}/{{ template "starrockscluster.entrypoint.script.name" .}}
        subPath: {{ template "starrockscluster.entrypoint.script.name" .}}
    {{- end }}
    {{- end }}
    configMapInfo:
      configMapName: {{ template  "starrockscluster.fe.configmap.name" . }}
      resolveKey: fe.conf
    {{- if or .Values.starrocksFESpec.storageSpec.name .Values.starrocksFESpec.emptyDirs .Values.starrocksFESpec.hostPaths }}
    storageVolumes:
    {{- if .Values.starrocksFESpec.storageSpec.name }}
    - name: {{ .Values.starrocksFESpec.storageSpec.name }}{{ template "starrockscluster.fe.meta.suffix" . }}
      storageClassName: {{ .Values.starrocksFESpec.storageSpec.storageClassName }}
      storageSize: "{{ .Values.starrocksFESpec.storageSpec.storageSize }}"
      mountPath: {{ template "starrockscluster.fe.meta.path" . }}
    - name: {{ .Values.starrocksFESpec.storageSpec.name }}{{ template "starrockscluster.fe.log.suffix" . }}
      {{- if .Values.starrocksFESpec.storageSpec.logStorageClassName }}
      storageClassName: {{ .Values.starrocksFESpec.storageSpec.logStorageClassName }}
      {{- else }}
      storageClassName: {{ .Values.starrocksFESpec.storageSpec.storageClassName }}
      {{- end }}
      storageSize: "{{ .Values.starrocksFESpec.storageSpec.logStorageSize }}"
      mountPath: {{ template "starrockscluster.fe.log.path" . }}
    {{- end }}
    {{- if .Values.starrocksFESpec.emptyDirs }}
    {{- range .Values.starrocksFESpec.emptyDirs }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      storageClassName: "emptyDir"
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksFESpec.hostPaths }}
    {{- range .Values.starrocksFESpec.hostPaths }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      storageClassName: "hostPath"
      hostPath:
        {{- toYaml .hostPath | nindent 8 }}
    {{- end }}
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksFESpec.persistentVolumeClaimRetentionPolicy }}
    persistentVolumeClaimRetentionPolicy:
      {{- toYaml .Values.starrocksFESpec.persistentVolumeClaimRetentionPolicy | nindent 6 }}
    {{- end }}
  {{- if .Values.starrocksCluster.enabledBe }}
  starRocksBeSpec:
    {{- if .Values.starrocksBeSpec.initContainers }}
    initContainers:
      {{- toYaml .Values.starrocksBeSpec.initContainers | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.shareProcessNamespace }}
    shareProcessNamespace: {{ .Values.starrocksBeSpec.shareProcessNamespace }}
    {{- end }}
    image: "{{ .Values.starrocksBeSpec.image.repository }}:{{ include "starrockscluster.be.image.tag" . }}"
    {{- if .Values.starrocksBeSpec.entrypoint }}
    command: ["bash", "-c"]
    args:
      - {{template "starrockscluster.entrypoint.mount.path" .}}/{{template "starrockscluster.entrypoint.script.name" .}}
    {{- end }}
    replicas: {{ .Values.starrocksBeSpec.replicas }}
    imagePullPolicy: {{ .Values.starrocksBeSpec.imagePullPolicy }}
    {{- if .Values.starrocksBeSpec.maxUnavailablePods }}
    updateStrategy:
      rollingUpdate:
        maxUnavailable: {{ .Values.starrocksBeSpec.maxUnavailablePods }}
    {{- end }}
    {{- /*
    support both resources and resource for backward compatibility
    */}}
    {{- if .Values.starrocksBeSpec.resources }}
    {{- include "starrockscluster.be.resources" . | nindent 4 }}
    {{- else if .Values.starrocksBeSpec.resource }}
    {{- toYaml .Values.starrocksBeSpec.resource | nindent 4 }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.service.type }}
    service:
      type: {{ .Values.starrocksBeSpec.service.type }}
      {{- if and (eq "LoadBalancer" .Values.starrocksBeSpec.service.type) .Values.starrocksBeSpec.service.loadbalancerIP }}
      loadBalancerIP: {{ .Values.starrocksBeSpec.service.loadbalancerIP }}
      {{- end }}
      {{- if and (eq "LoadBalancer" .Values.starrocksBeSpec.service.type) .Values.starrocksBeSpec.service.loadBalancerSourceRanges}}
      loadBalancerSourceRanges:
        {{- toYaml .Values.starrocksBeSpec.service.loadBalancerSourceRanges | nindent 8 }}
      {{- end }}
      {{- if .Values.starrocksBeSpec.service.ports }}
      ports:
        {{- toYaml .Values.starrocksBeSpec.service.ports | nindent 8 }}
      {{- end }}
      {{- if or .Values.starrocksBeSpec.service.annotations .Values.datadog.metrics.enabled }}
      annotations:
        {{- if .Values.datadog.metrics.enabled }}
        prometheus.io/path: "/metrics"
        prometheus.io/port: "{{- default 8040 (include "starrockscluster.be.webserver.port" .) }}"
        prometheus.io/scrape: "true"
        {{- end }}
        {{- if .Values.starrocksBeSpec.service.annotations }}
        {{- toYaml .Values.starrocksBeSpec.service.annotations | nindent 8 }}
        {{- end }}
      {{- end }}
      {{- if .Values.starrocksBeSpec.service.labels}}
      labels:
        {{- toYaml .Values.starrocksBeSpec.service.labels | nindent 8 }}
      {{- end }}
    {{- end }}
    annotations:
      app.starrocks.io/be-config-hash: "{{template "starrockscluster.be.config.hash" . }}"
      {{- if .Values.datadog.log.enabled }}
      {{- if eq (trimAll " {}" .Values.datadog.log.logConfig) "" }}
      ad.datadoghq.com/be.logs: '[{"service":"starrocks","source":"be"}]'
      {{- else }}
      ad.datadoghq.com/be.logs: {{ printf "[%s]" (printf "{%s, \"source\": \"be\", \"service\": \"starrocks\"}" (trimAll " {}" .Values.datadog.log.logConfig) | fromJson | toJson) | squote }}
      {{- end }}
      {{- end }}
      {{- if .Values.starrocksBeSpec.annotations }}
      {{- toYaml .Values.starrocksBeSpec.annotations | nindent 6 }}
      {{- end }}
      {{- if .Values.starrocksBeSpec.entrypoint }}
      app.starrocks.io/be-entrypoint-hash: "{{ template "starrockscluster.be.entrypoint.script.hash" . }}"
      {{- end }}
    {{- if or .Values.starrocksBeSpec.imagePullSecrets .Values.starrocksCluster.componentValues.imagePullSecrets }}
    imagePullSecrets:
      {{- include "starrockscluster.be.imagePullSecrets" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.serviceAccount .Values.starrocksCluster.componentValues.serviceAccount }}
    serviceAccount: {{ include "starrockscluster.be.serviceAccount" . }}
    {{- end }}
    runAsNonRoot: {{ include "starrockscluster.be.runAsNonRoot" . }}
    {{- if .Values.starrocksBeSpec.readOnlyRootFilesystem }}
    readOnlyRootFilesystem: {{ .Values.starrocksBeSpec.readOnlyRootFilesystem }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.capabilities .Values.datadog.profiling.be }}
    capabilities:
      {{- if or .Values.starrocksBeSpec.capabilities.add .Values.datadog.profiling.be }}
      add:
        {{- if .Values.starrocksBeSpec.capabilities.add }}
        {{- toYaml .Values.starrocksBeSpec.capabilities.add | nindent 8 }}
        {{- end }}
        {{- if .Values.datadog.profiling.be }}
        {{- if and .Values.starrocksBeSpec.capabilities.add (has "PERFMON" .Values.starrocksBeSpec.capabilities.add) | not }}
        - PERFMON
        {{- end }}
        {{- if and .Values.starrocksBeSpec.capabilities.add (has "SYS_PTRACE" .Values.starrocksBeSpec.capabilities.add) | not }}
        - SYS_PTRACE
        {{- end }}
        {{- end }}
      {{- end }}
      {{- if .Values.starrocksBeSpec.capabilities.drop }}
      drop:
        {{- toYaml .Values.starrocksBeSpec.capabilities.drop | nindent 8 }}
      {{- end }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.sysctls }}
    sysctls:
      {{- toYaml .Values.starrocksBeSpec.sysctls | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.podLabels .Values.starrocksCluster.componentValues.podLabels .Values.datadog.profiling.be }}
    podLabels:
      {{- if or .Values.starrocksBeSpec.podLabels .Values.starrocksCluster.componentValues.podLabels }}
      {{- include "starrockscluster.be.podLabels" . | nindent 6 }}
      {{- end }}
      {{- if .Values.datadog.profiling.be }}
      admission.datadoghq.com/config.mode: {{ .Values.datadog.profiling.configMode }}
      admission.datadoghq.com/enabled: "true"
      {{- end }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.hostAliases .Values.starrocksCluster.componentValues.hostAliases }}
    hostAliases:
      {{- include "starrockscluster.be.hostAliases" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.schedulerName .Values.starrocksCluster.componentValues.schedulerName }}
    schedulerName: {{ include "starrockscluster.be.schedulerName" . }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.nodeSelector .Values.starrocksCluster.componentValues.nodeSelector }}
    nodeSelector:
      {{- include "starrockscluster.be.nodeSelector" . | nindent 6 }}
    {{- end }}
    beEnvVars:
      - name: TZ
        value: {{ .Values.timeZone }}
      {{- if .Values.datadog.log.enabled }}
      - name: LOG_CONSOLE
        value: "1"
      {{- end }}
      {{- if and .Values.initPassword.enabled (.Values.starrocksBeSpec.beEnvVars | toJson | contains "MYSQL_PWD" | not) }}
      - name: "MYSQL_PWD"
        valueFrom:
          secretKeyRef:
            name: {{ template "starrockscluster.initpassword.secret.name" . }}
            key: password
      {{- end }}
      {{- if .Values.datadog.profiling.be }}
      - name: ENABLE_DATADOG_PROFILE
        value: "true"
      - name: DD_PROFILING_ENABLED
        value: "true"
      - name: DD_SERVICE
        value: starrocks-be
      - name: DD_ENV
        value: "{{ .Values.datadog.profiling.env }}"
      - name: DD_VERSION
        value: "{{ include "starrockscluster.be.image.tag" . }}"
      {{- end }}
      {{- if .Values.starrocksBeSpec.beEnvVars }}
      {{- /* if it is a map, we use range to iterate to merge environment variables */}}
      {{- if eq (kindOf .Values.starrocksBeSpec.beEnvVars) "map" }}
      {{- range $key, $value := .Values.starrocksBeSpec.beEnvVars }}
      - name: {{ $key }}
        {{- if eq (kindOf $value) "string" }}
        value: {{ $value | quote }}
        {{- else }}
        {{- toYaml $value | nindent 8 }}
        {{- end }}
      {{- end }}
      {{- else }}
      {{- /* the default kind is slice, we keep backward compatibility */}}
      {{- toYaml .Values.starrocksBeSpec.beEnvVars | nindent 6 }}
      {{- end }}
      {{- end }}
    {{- if or .Values.starrocksBeSpec.affinity .Values.starrocksCluster.componentValues.affinity }}
    affinity:
      {{- include "starrockscluster.be.affinity" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.tolerations .Values.starrocksCluster.componentValues.tolerations }}
    tolerations:
      {{- include "starrockscluster.be.tolerations" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.topologySpreadConstraints .Values.starrocksCluster.componentValues.topologySpreadConstraints }}
    topologySpreadConstraints:
      {{- include "starrockscluster.be.topologySpreadConstraints" . | nindent 6 }}
    {{- end }}
    terminationGracePeriodSeconds: {{ .Values.starrocksBeSpec.terminationGracePeriodSeconds }}
    {{- if .Values.starrocksBeSpec.startupProbeFailureSeconds }}
    startupProbeFailureSeconds: {{ .Values.starrocksBeSpec.startupProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.livenessProbeFailureSeconds }}
    livenessProbeFailureSeconds: {{ .Values.starrocksBeSpec.livenessProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.readinessProbeFailureSeconds }}
    readinessProbeFailureSeconds: {{ .Values.starrocksBeSpec.readinessProbeFailureSeconds }}
    {{- end }}
    minReadySeconds: {{ .Values.starrocksBeSpec.minReadySeconds }}
    podManagementPolicy: {{ .Values.starrocksBeSpec.podManagementPolicy }}
    {{- if .Values.starrocksBeSpec.lifecycle }}
    lifecycle:
      {{- toYaml .Values.starrocksBeSpec.lifecycle | nindent 6 }}
    {{- end }}
    {{- if and .Values.starrocksBeSpec.sidecarsMap .Values.starrocksBeSpec.sidecars }}
      {{ fail "starrocksBeSpec.sidecarsMap and starrocksBeSpec.sidecars cannot be set at the same time" }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.sidecarsMap .Values.starrocksBeSpec.sidecars }}
    sidecars:
      {{- if .Values.starrocksBeSpec.sidecarsMap }}
      {{- range $name, $spec := .Values.starrocksBeSpec.sidecarsMap }}
      - name: {{ $name }}
        {{- toYaml $spec | nindent 8 }}
      {{- end }}
      {{- else if .Values.starrocksBeSpec.sidecars }}
      {{- toYaml .Values.starrocksBeSpec.sidecars | nindent 6 }}
      {{- end }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.secrets }}
    secrets:
    {{- range .Values.starrocksBeSpec.secrets }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      subPath: {{ .subPath }}
    {{- end }}
    {{- end }}
    {{- if or .Values.starrocksBeSpec.configMaps .Values.starrocksBeSpec.entrypoint }}
    configMaps:
    {{- if .Values.starrocksBeSpec.configMaps }}
    {{- range .Values.starrocksBeSpec.configMaps }}
      - name: {{ .name }}
        mountPath: {{ .mountPath }}
        subPath: {{ .subPath }}
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.entrypoint }}
      - name: {{template "starrockscluster.be.entrypoint.script.configmap.name" .}}
        mountPath: {{template "starrockscluster.entrypoint.mount.path" .}}/{{ template "starrockscluster.entrypoint.script.name" .}}
        subPath: {{ template "starrockscluster.entrypoint.script.name" .}}
    {{- end }}
    {{- end }}
    configMapInfo:
      configMapName: {{template "starrockscluster.be.configmap.name" . }}
      resolveKey: be.conf
    {{- if or .Values.starrocksBeSpec.storageSpec.name .Values.starrocksBeSpec.emptyDirs .Values.starrocksBeSpec.hostPaths }}
    storageVolumes:
    {{- if .Values.starrocksBeSpec.storageSpec.name }}
    {{- if gt (int .Values.starrocksBeSpec.storageSpec.storageCount) 1 }}
    {{- $storageName := .Values.starrocksBeSpec.storageSpec.name -}}
    {{- $storageClassName := .Values.starrocksBeSpec.storageSpec.storageClassName -}}
    {{- $storageSize := .Values.starrocksBeSpec.storageSpec.storageSize -}}
    {{- $storageMountPath := include "starrockscluster.be.data.path" . -}}
    {{- range $i, $e := until (int .Values.starrocksBeSpec.storageSpec.storageCount) }}
    - name: {{ $storageName }}{{ $i }}{{template "starrockscluster.be.data.suffix" . }}
      storageClassName: {{ $storageClassName }}
      storageSize: "{{ $storageSize }}"
      mountPath: {{ $storageMountPath }}{{ $i }}
    {{- end }}
    {{- else}}
    - name: {{ .Values.starrocksBeSpec.storageSpec.name }}{{template "starrockscluster.be.data.suffix" . }}
      storageClassName: {{ .Values.starrocksBeSpec.storageSpec.storageClassName }}
      storageSize: "{{ .Values.starrocksBeSpec.storageSpec.storageSize }}"
      mountPath: {{template "starrockscluster.be.data.path" . }}
    {{- end }}
    - name: {{ .Values.starrocksBeSpec.storageSpec.name }}{{template "starrockscluster.be.log.suffix" . }}
      {{- if .Values.starrocksBeSpec.storageSpec.logStorageClassName }}
      storageClassName: {{ .Values.starrocksBeSpec.storageSpec.logStorageClassName }}
      {{- else }}
      storageClassName: {{ .Values.starrocksBeSpec.storageSpec.storageClassName }}
      {{- end }}
      storageSize: "{{ .Values.starrocksBeSpec.storageSpec.logStorageSize }}"
      mountPath: {{template "starrockscluster.be.log.path" . }}
    - name: {{ .Values.starrocksBeSpec.storageSpec.name }}{{template "starrockscluster.be.spill.suffix" . }}
      {{- if .Values.starrocksBeSpec.storageSpec.spillStorageClassName }}
      storageClassName: {{ .Values.starrocksBeSpec.storageSpec.spillStorageClassName }}
      {{- else }}
      storageClassName: {{ .Values.starrocksBeSpec.storageSpec.storageClassName }}
      {{- end }}
      storageSize: "{{ .Values.starrocksBeSpec.storageSpec.spillStorageSize}}"
      mountPath: {{template "starrockscluster.be.spill.path" . }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.emptyDirs }}
    {{- range .Values.starrocksBeSpec.emptyDirs }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      storageClassName: "emptyDir"
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.hostPaths }}
    {{- range .Values.starrocksBeSpec.hostPaths }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      storageClassName: "hostPath"
      hostPath:
        {{- toYaml .hostPath | nindent 8 }}
    {{- end }}
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksBeSpec.persistentVolumeClaimRetentionPolicy }}
    persistentVolumeClaimRetentionPolicy:
      {{- toYaml .Values.starrocksBeSpec.persistentVolumeClaimRetentionPolicy | nindent 6 }}
    {{- end }}
  {{- end }}
  {{- if .Values.starrocksCluster.enabledCn }}
  starRocksCnSpec:
    {{- if .Values.starrocksCnSpec.initContainers }}
    initContainers:
      {{- toYaml .Values.starrocksCnSpec.initContainers | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.shareProcessNamespace }}
    shareProcessNamespace: {{ .Values.starrocksCnSpec.shareProcessNamespace }}
    {{- end }}
    image: "{{ .Values.starrocksCnSpec.image.repository }}:{{ include "starrockscluster.cn.image.tag" . }}"
    {{- if .Values.starrocksCnSpec.entrypoint }}
    command: ["bash", "-c"]
    args:
      - {{template "starrockscluster.entrypoint.mount.path" .}}/{{template "starrockscluster.entrypoint.script.name" .}}
    {{- end }}
    {{- if hasKey .Values.starrocksCnSpec "replicas" }}
    replicas: {{ .Values.starrocksCnSpec.replicas }}
    {{- end }}
    imagePullPolicy: {{ .Values.starrocksCnSpec.imagePullPolicy }}
    {{- if .Values.starrocksCnSpec.maxUnavailablePods }}
    updateStrategy:
      rollingUpdate:
        maxUnavailable: {{ .Values.starrocksCnSpec.maxUnavailablePods }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.serviceAccount .Values.starrocksCluster.componentValues.serviceAccount }}
    serviceAccount: {{ include "starrockscluster.cn.serviceAccount" . }}
    {{- end }}
    runAsNonRoot: {{ include "starrockscluster.cn.runAsNonRoot" . }}
    {{- if .Values.starrocksCnSpec.readOnlyRootFilesystem }}
    readOnlyRootFilesystem: {{ .Values.starrocksCnSpec.readOnlyRootFilesystem }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.capabilities .Values.datadog.profiling.cn }}
    capabilities:
      {{- if or .Values.starrocksCnSpec.capabilities.add .Values.datadog.profiling.cn }}
      add:
        {{- if .Values.starrocksCnSpec.capabilities.add }}
        {{- toYaml .Values.starrocksCnSpec.capabilities.add | nindent 8 }}
        {{- end }}
        {{- if .Values.datadog.profiling.cn }}
        {{- if and .Values.starrocksCnSpec.capabilities.add (has "PERFMON" .Values.starrocksCnSpec.capabilities.add) | not }}
        - PERFMON
        {{- end }}
        {{- if and .Values.starrocksCnSpec.capabilities.add (has "SYS_PTRACE" .Values.starrocksCnSpec.capabilities.add) | not }}
        - SYS_PTRACE
        {{- end }}
        {{- end }}
      {{- end }}
      {{- if .Values.starrocksCnSpec.capabilities.drop }}
      drop:
        {{- toYaml .Values.starrocksCnSpec.capabilities.drop | nindent 8 }}
      {{- end }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.sysctls }}
    sysctls:
      {{- toYaml .Values.starrocksCnSpec.sysctls | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.podLabels .Values.starrocksCluster.componentValues.podLabels .Values.datadog.profiling.cn }}
    podLabels:
      {{- if or .Values.starrocksCnSpec.podLabels .Values.starrocksCluster.componentValues.podLabels }}
      {{- include "starrockscluster.cn.podLabels" . | nindent 6 }}
      {{- end }}
      {{- if .Values.datadog.profiling.cn }}
      admission.datadoghq.com/config.mode: {{ .Values.datadog.profiling.configMode }}
      admission.datadoghq.com/enabled: "true"
      {{- end }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.hostAliases .Values.starrocksCluster.componentValues.hostAliases }}
    hostAliases:
      {{- include "starrockscluster.cn.hostAliases" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.schedulerName .Values.starrocksCluster.componentValues.schedulerName }}
    schedulerName: {{ include "starrockscluster.cn.schedulerName" . }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.nodeSelector .Values.starrocksCluster.componentValues.nodeSelector }}
    nodeSelector:
      {{- include "starrockscluster.cn.nodeSelector" . | nindent 6 }}
    {{- end }}
    cnEnvVars:
      - name: TZ
        value: {{ .Values.timeZone }}
      {{- if .Values.datadog.log.enabled }}
      - name: LOG_CONSOLE
        value: "1"
      {{- end }}
      {{- if and .Values.initPassword.enabled (.Values.starrocksCnSpec.cnEnvVars | toJson | contains "MYSQL_PWD" | not) }}
      - name: "MYSQL_PWD"
        valueFrom:
          secretKeyRef:
            name: {{ template "starrockscluster.initpassword.secret.name" . }}
            key: password
      {{- end }}
      {{- if .Values.datadog.profiling.cn }}
      - name: ENABLE_DATADOG_PROFILE
        value: "true"
      - name: DD_PROFILING_ENABLED
        value: "true"
      - name: DD_SERVICE
        value: starrocks-cn
      - name: DD_ENV
        value: "{{ .Values.datadog.profiling.env }}"
      - name: DD_VERSION
        value: "{{ include "starrockscluster.cn.image.tag" . }}"
      {{- end }}
      {{- if .Values.starrocksCnSpec.cnEnvVars }}
      {{- /* if it is a map, we use range to iterate to merge environment variables */}}
      {{- if eq (kindOf .Values.starrocksCnSpec.cnEnvVars) "map" }}
      {{- range $key, $value := .Values.starrocksCnSpec.cnEnvVars }}
      - name: {{ $key }}
        {{- if eq (kindOf $value) "string" }}
        value: {{ $value | quote }}
        {{- else }}
        {{- toYaml $value | nindent 8 }}
        {{- end }}
      {{- end }}
      {{- else }}
      {{- /* the default kind is slice, we keep backward compatibility */}}
      {{- toYaml .Values.starrocksCnSpec.cnEnvVars | nindent 6 }}
      {{- end }}
      {{- end }}

    {{- if or .Values.starrocksCnSpec.affinity .Values.starrocksCluster.componentValues.affinity }}
    affinity:
      {{- include "starrockscluster.cn.affinity" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.tolerations .Values.starrocksCluster.componentValues.tolerations }}
    tolerations:
      {{- include "starrockscluster.cn.tolerations" . | nindent 6 }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.topologySpreadConstraints .Values.starrocksCluster.componentValues.topologySpreadConstraints }}
    topologySpreadConstraints:
      {{- include "starrockscluster.cn.topologySpreadConstraints" . | nindent 6 }}
    {{- end }}
    terminationGracePeriodSeconds: {{ .Values.starrocksCnSpec.terminationGracePeriodSeconds }}
    {{- if .Values.starrocksCnSpec.startupProbeFailureSeconds }}
    startupProbeFailureSeconds: {{ .Values.starrocksCnSpec.startupProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.livenessProbeFailureSeconds }}
    livenessProbeFailureSeconds: {{ .Values.starrocksCnSpec.livenessProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.readinessProbeFailureSeconds }}
    readinessProbeFailureSeconds: {{ .Values.starrocksCnSpec.readinessProbeFailureSeconds }}
    {{- end }}
    minReadySeconds: {{ .Values.starrocksCnSpec.minReadySeconds }}
    podManagementPolicy: {{ .Values.starrocksCnSpec.podManagementPolicy }}
    {{- if .Values.starrocksCnSpec.lifecycle }}
    lifecycle:
      {{- toYaml .Values.starrocksCnSpec.lifecycle | nindent 6 }}
    {{- end }}
    {{- if and .Values.starrocksCnSpec.sidecarsMap .Values.starrocksCnSpec.sidecars }}
      {{ fail "starrocksCnSpec.sidecarsMap and starrocksCnSpec.sidecars cannot be set at the same time" }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.sidecarsMap .Values.starrocksCnSpec.sidecars }}
    sidecars:
      {{- if .Values.starrocksCnSpec.sidecarsMap }}
      {{- range $name, $spec := .Values.starrocksCnSpec.sidecarsMap }}
      - name: {{ $name }}
        {{- toYaml $spec | nindent 8 }}
      {{- end }}
      {{- else if .Values.starrocksCnSpec.sidecars }}
      {{- toYaml .Values.starrocksCnSpec.sidecars | nindent 6 }}
      {{- end }}
    {{- end }}
    {{- if and .Values.starrocksCluster.enabledCn .Values.starrocksCnSpec.autoScalingPolicy }}
    autoScalingPolicy:
      {{- toYaml .Values.starrocksCnSpec.autoScalingPolicy | nindent 6 }}
    {{- end }}
    {{- /*
    support both resources and resource for backward compatibility
    */}}
    {{- if .Values.starrocksCnSpec.resources }}
    {{- include "starrockscluster.cn.resources" . | nindent 4 }}
    {{- else if .Values.starrocksCnSpec.resource }}
    {{- toYaml .Values.starrocksCnSpec.resource | nindent 4 }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.service.type }}
    service:
      type: {{ .Values.starrocksCnSpec.service.type }}
      {{- if and (eq "LoadBalancer" .Values.starrocksCnSpec.service.type) .Values.starrocksCnSpec.service.loadbalancerIP }}
      loadBalancerIP: {{ .Values.starrocksCnSpec.service.loadbalancerIP }}
      {{- end }}
      {{- if and (eq "LoadBalancer" .Values.starrocksCnSpec.service.type) .Values.starrocksCnSpec.service.loadBalancerSourceRanges}}
      loadBalancerSourceRanges:
        {{- toYaml .Values.starrocksCnSpec.service.loadBalancerSourceRanges | nindent 8 }}
      {{- end }}
      {{- if .Values.starrocksCnSpec.service.ports }}
      ports:
        {{- toYaml .Values.starrocksCnSpec.service.ports | nindent 8 }}
      {{- end }}
      {{- if or .Values.starrocksCnSpec.service.annotations .Values.datadog.metrics.enabled }}
      annotations:
        {{- if .Values.datadog.metrics.enabled }}
        prometheus.io/path: "/metrics"
        prometheus.io/port: "{{- default 8040 (include "starrockscluster.cn.webserver.port" .) }}"
        prometheus.io/scrape: "true"
        {{- end }}
        {{- if .Values.starrocksCnSpec.service.annotations }}
        {{- toYaml .Values.starrocksCnSpec.service.annotations | nindent 8 }}
        {{- end }}
      {{- end }}
      {{- if .Values.starrocksCnSpec.service.labels}}
      labels:
        {{- toYaml .Values.starrocksCnSpec.service.labels | nindent 8 }}
      {{- end }}
    {{- end }}
    annotations:
      app.starrocks.io/cn-config-hash: "{{template "starrockscluster.cn.config.hash" . }}"
      {{- if .Values.datadog.log.enabled }}
      {{- if eq (trimAll " {}" .Values.datadog.log.logConfig) "" }}
      ad.datadoghq.com/cn.logs: '[{"service":"starrocks","source":"cn"}]'
      {{- else }}
      ad.datadoghq.com/cn.logs: {{ printf "[%s]" (printf "{%s, \"source\": \"cn\", \"service\": \"starrocks\"}" (trimAll " {}" .Values.datadog.log.logConfig) | fromJson | toJson) | squote }}
      {{- end }}
      {{- end }}
      {{- if .Values.starrocksCnSpec.annotations }}
      {{- toYaml .Values.starrocksCnSpec.annotations | nindent 6 }}
      {{- end }}
      {{- if .Values.starrocksCnSpec.entrypoint }}
      app.starrocks.io/cn-entrypoint-hash: "{{ template "starrockscluster.cn.entrypoint.script.hash" . }}"
      {{- end }}
    {{- if or .Values.starrocksCnSpec.imagePullSecrets .Values.starrocksCluster.componentValues.imagePullSecrets }}
    imagePullSecrets:
      {{- include "starrockscluster.cn.imagePullSecrets" . | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.secrets }}
    secrets:
    {{- range .Values.starrocksCnSpec.secrets }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      subPath: {{ .subPath }}
    {{- end }}
    {{- end }}
    {{- if or .Values.starrocksCnSpec.configMaps .Values.starrocksCnSpec.entrypoint }}
    configMaps:
    {{- if .Values.starrocksCnSpec.configMaps }}
    {{- range .Values.starrocksCnSpec.configMaps }}
      - name: {{ .name }}
        mountPath: {{ .mountPath }}
        subPath: {{ .subPath }}
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.entrypoint }}
      - name: {{template "starrockscluster.cn.entrypoint.script.configmap.name" .}}
        mountPath: {{template "starrockscluster.entrypoint.mount.path" .}}/{{ template "starrockscluster.entrypoint.script.name" .}}
        subPath: {{ template "starrockscluster.entrypoint.script.name" .}}
    {{- end }}
    {{- end }}
    configMapInfo:
      configMapName: {{template  "starrockscluster.cn.configmap.name" . }}
      resolveKey: cn.conf
    {{- if or .Values.starrocksCnSpec.storageSpec.name .Values.starrocksCnSpec.emptyDirs .Values.starrocksCnSpec.hostPaths }}
    storageVolumes:
    {{- if .Values.starrocksCnSpec.storageSpec.name }}
    {{- if gt (int .Values.starrocksCnSpec.storageSpec.storageCount) 1 }}
    {{- $storageName := .Values.starrocksCnSpec.storageSpec.name -}}
    {{- $storageClassName := .Values.starrocksCnSpec.storageSpec.storageClassName -}}
    {{- $storageSize := .Values.starrocksCnSpec.storageSpec.storageSize -}}
    {{- $storageMountPath := include "starrockscluster.cn.data.path" . -}}
    {{- range $i, $e := until (int .Values.starrocksCnSpec.storageSpec.storageCount) }}
    - name: {{ $storageName }}{{ $i }}{{template "starrockscluster.cn.data.suffix" . }}
      storageClassName: {{ $storageClassName }}
      storageSize: "{{ $storageSize }}"
      mountPath: {{ $storageMountPath }}{{ $i }}
    {{- end }}
    {{- else }}
    - name: {{ .Values.starrocksCnSpec.storageSpec.name }}{{template "starrockscluster.cn.data.suffix" . }}
      storageClassName: {{ .Values.starrocksCnSpec.storageSpec.storageClassName }}
      storageSize: "{{ .Values.starrocksCnSpec.storageSpec.storageSize }}"
      mountPath: {{template "starrockscluster.cn.data.path" . }}
    {{- end }}
    - name: {{ .Values.starrocksCnSpec.storageSpec.name }}{{template "starrockscluster.cn.log.suffix" . }}
      {{- if .Values.starrocksCnSpec.storageSpec.logStorageClassName }}
      storageClassName: {{ .Values.starrocksCnSpec.storageSpec.logStorageClassName }}
      {{- else }}
      storageClassName: {{ .Values.starrocksCnSpec.storageSpec.storageClassName }}
      {{- end }}
      storageSize: "{{ .Values.starrocksCnSpec.storageSpec.logStorageSize }}"
      mountPath: {{template "starrockscluster.cn.log.path" . }}
    - name: {{ .Values.starrocksCnSpec.storageSpec.name }}{{template "starrockscluster.cn.spill.suffix" . }}
      {{- if .Values.starrocksCnSpec.storageSpec.spillStorageClassName }}
      storageClassName: {{ .Values.starrocksCnSpec.storageSpec.spillStorageClassName }}
      {{- else }}
      storageClassName: {{ .Values.starrocksCnSpec.storageSpec.storageClassName }}
      {{- end }}
      storageSize: "{{ .Values.starrocksCnSpec.storageSpec.spillStorageSize}}"
      mountPath: {{template "starrockscluster.cn.spill.path" . }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.emptyDirs }}
    {{- range .Values.starrocksCnSpec.emptyDirs }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      storageClassName: "emptyDir"
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.hostPaths }}
    {{- range .Values.starrocksCnSpec.hostPaths }}
    - name: {{ .name }}
      mountPath: {{ .mountPath }}
      storageClassName: "hostPath"
      hostPath:
        {{- toYaml .hostPath | nindent 8 }}
    {{- end }}
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksCnSpec.persistentVolumeClaimRetentionPolicy }}
    persistentVolumeClaimRetentionPolicy:
      {{- toYaml .Values.starrocksCnSpec.persistentVolumeClaimRetentionPolicy | nindent 6 }}
    {{- end }}
  {{- end }}

  {{- if .Values.starrocksFeProxySpec.enabled }}
  starRocksFeProxySpec:
    {{- if .Values.starrocksFeProxySpec.image.repository }}
    image: "{{ .Values.starrocksFeProxySpec.image.repository }}:{{ .Values.starrocksFeProxySpec.image.tag }}"
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.imagePullSecrets }}
    imagePullSecrets:
      {{- toYaml .Values.starrocksFeProxySpec.imagePullSecrets | nindent 4 }}
    {{- end }}
    replicas: {{ .Values.starrocksFeProxySpec.replicas }}
    imagePullPolicy: {{ .Values.starrocksFeProxySpec.imagePullPolicy }}
    resolver: {{ .Values.starrocksFeProxySpec.resolver }}
    {{- if .Values.starrocksFeProxySpec.resources }}
      {{- toYaml .Values.starrocksFeProxySpec.resources | nindent 4 }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.service.type }}
    service:
      type: {{ .Values.starrocksFeProxySpec.service.type }}
      {{- if .Values.starrocksFeProxySpec.service.annotations }}
      annotations:
        {{- toYaml .Values.starrocksFeProxySpec.service.annotations | nindent 8 }}
      {{- end }}
      {{- if .Values.starrocksFeProxySpec.service.labels}}
      labels:
        {{- toYaml .Values.starrocksFeProxySpec.service.labels | nindent 8 }}
      {{- end }}
      {{- if and (eq "LoadBalancer" .Values.starrocksFeProxySpec.service.type) .Values.starrocksFeProxySpec.service.loadbalancerIP }}
      loadBalancerIP: {{ .Values.starrocksFeProxySpec.service.loadbalancerIP }}
      {{- end }}
      {{- if and (eq "LoadBalancer" .Values.starrocksFeProxySpec.service.type) .Values.starrocksFeProxySpec.service.loadBalancerSourceRanges}}
      loadBalancerSourceRanges:
        {{- toYaml .Values.starrocksFeProxySpec.service.loadBalancerSourceRanges | nindent 8 }}
      {{- end }}
      {{- if .Values.starrocksFeProxySpec.service.ports }}
      ports:
        {{- toYaml .Values.starrocksFeProxySpec.service.ports | nindent 8 }}
      {{- end }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.nodeSelector }}
    nodeSelector:
      {{- toYaml .Values.starrocksFeProxySpec.nodeSelector | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.affinity }}
    affinity:
      {{- toYaml .Values.starrocksFeProxySpec.affinity | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.tolerations }}
    tolerations:
      {{- toYaml .Values.starrocksFeProxySpec.tolerations | nindent 6 }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.livenessProbeFailureSeconds }}
    livenessProbeFailureSeconds: {{ .Values.starrocksFeProxySpec.livenessProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.readinessProbeFailureSeconds }}
    readinessProbeFailureSeconds: {{ .Values.starrocksFeProxySpec.readinessProbeFailureSeconds }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.emptyDirs }}
    storageVolumes:
    {{- range .Values.starrocksFeProxySpec.emptyDirs }}
    - name: {{ .name }}
      storageClassName: "emptyDir"
      mountPath: {{ .mountPath }}
    {{- end }}
    {{- end }}
    {{- if .Values.starrocksFeProxySpec.podLabels }}
    podLabels:
      {{- toYaml .Values.starrocksFeProxySpec.podLabels | nindent 6 }}
    {{- end }}
  {{- end }}
