Skip to content

Commit

Permalink
[Enhancement] Support ReadOnlyRootFilesystem
Browse files Browse the repository at this point in the history
Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao committed Nov 19, 2024
1 parent 0c8aefb commit 06af429
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 3 deletions.
21 changes: 21 additions & 0 deletions config/crd/bases/starrocks.com_starrocksclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,13 @@ spec:
type: string
description: the pod labels for user select or classify pods.
type: object
readOnlyRootFilesystem:
description: "Whether this container has a read-only root filesystem.\nDefault
is false.\nNote that:\n\t1. This field cannot be set when spec.os.name
is windows.\n\t2. The FE/BE/CN container should support read-only
root filesystem. The newest version of FE/BE/CN is 3.3.6,\n
\ and does not support read-only root filesystem"
type: boolean
readinessProbeFailureSeconds:
description: |-
ReadinessProbeFailureSeconds defines the total failure seconds of readiness Probe.
Expand Down Expand Up @@ -7581,6 +7588,13 @@ spec:
type: string
description: the pod labels for user select or classify pods.
type: object
readOnlyRootFilesystem:
description: "Whether this container has a read-only root filesystem.\nDefault
is false.\nNote that:\n\t1. This field cannot be set when spec.os.name
is windows.\n\t2. The FE/BE/CN container should support read-only
root filesystem. The newest version of FE/BE/CN is 3.3.6,\n
\ and does not support read-only root filesystem"
type: boolean
readinessProbeFailureSeconds:
description: |-
ReadinessProbeFailureSeconds defines the total failure seconds of readiness Probe.
Expand Down Expand Up @@ -13413,6 +13427,13 @@ spec:
type: string
description: the pod labels for user select or classify pods.
type: object
readOnlyRootFilesystem:
description: "Whether this container has a read-only root filesystem.\nDefault
is false.\nNote that:\n\t1. This field cannot be set when spec.os.name
is windows.\n\t2. The FE/BE/CN container should support read-only
root filesystem. The newest version of FE/BE/CN is 3.3.6,\n
\ and does not support read-only root filesystem"
type: boolean
readinessProbeFailureSeconds:
description: |-
ReadinessProbeFailureSeconds defines the total failure seconds of readiness Probe.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/starrocks.com_starrockswarehouses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,13 @@ spec:
type: string
description: the pod labels for user select or classify pods.
type: object
readOnlyRootFilesystem:
description: "Whether this container has a read-only root filesystem.\nDefault
is false.\nNote that:\n\t1. This field cannot be set when spec.os.name
is windows.\n\t2. The FE/BE/CN container should support read-only
root filesystem. The newest version of FE/BE/CN is 3.3.6,\n
\ and does not support read-only root filesystem"
type: boolean
readinessProbeFailureSeconds:
description: |-
ReadinessProbeFailureSeconds defines the total failure seconds of readiness Probe.
Expand Down
6 changes: 6 additions & 0 deletions deploy/starrocks.com_starrocksclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,8 @@ spec:
additionalProperties:
type: string
type: object
readOnlyRootFilesystem:
type: boolean
readinessProbeFailureSeconds:
format: int32
type: integer
Expand Down Expand Up @@ -3634,6 +3636,8 @@ spec:
additionalProperties:
type: string
type: object
readOnlyRootFilesystem:
type: boolean
readinessProbeFailureSeconds:
format: int32
type: integer
Expand Down Expand Up @@ -6333,6 +6337,8 @@ spec:
additionalProperties:
type: string
type: object
readOnlyRootFilesystem:
type: boolean
readinessProbeFailureSeconds:
format: int32
type: integer
Expand Down
2 changes: 2 additions & 0 deletions deploy/starrocks.com_starrockswarehouses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,8 @@ spec:
additionalProperties:
type: string
type: object
readOnlyRootFilesystem:
type: boolean
readinessProbeFailureSeconds:
format: int32
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ spec:
serviceAccount: {{ include "starrockscluster.fe.serviceAccount" . }}
{{- end }}
runAsNonRoot: {{ include "starrockscluster.fe.runAsNonRoot" . }}
{{- if .Values.starrocksFESpec.readOnlyRootFilesystem }}
readOnlyRootFilesystem: {{ .Values.starrocksFESpec.readOnlyRootFilesystem }}
{{-end }}
{{- if or .Values.starrocksFESpec.nodeSelector .Values.starrocksCluster.componentValues.nodeSelector }}
nodeSelector:
{{- include "starrockscluster.fe.nodeSelector" . | nindent 6 }}
Expand Down Expand Up @@ -319,6 +322,9 @@ spec:
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 }}
Expand Down Expand Up @@ -531,6 +537,9 @@ spec:
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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ starrocksFESpec:
# If runAsNonRoot is true, the container is run as non-root user.
# The userId will be set to 1000, and the groupID will be set to 1000.
runAsNonRoot: false
# Whether this container has a read-only root filesystem.
# Note: The FE/BE/CN container should support read-only root filesystem. The newest version of FE/BE/CN is 3.3.6, and does not support read-only root filesystem.
readOnlyRootFilesystem: false
# specify the service name and port config and serviceType
# the service type refer https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
service:
Expand Down Expand Up @@ -420,6 +423,9 @@ starrocksCnSpec:
# If runAsNonRoot is true, the container is run as non-root user.
# The userId will be set to 1000, and the groupID will be set to 1000.
runAsNonRoot: false
# Whether this container has a read-only root filesystem.
# Note: The FE/BE/CN container should support read-only root filesystem. The newest version of FE/BE/CN is 3.3.6, and does not support read-only root filesystem.
readOnlyRootFilesystem: false
# add/drop capabilities for CN container.
capabilities: {}
# add:
Expand Down Expand Up @@ -723,6 +729,9 @@ starrocksBeSpec:
# If runAsNonRoot is true, the container is run as non-root user.
# The userId will be set to 1000, and the groupID will be set to 1000.
runAsNonRoot: false
# Whether this container has a read-only root filesystem.
# Note: The FE/BE/CN container should support read-only root filesystem. The newest version of FE/BE/CN is 3.3.6, and does not support read-only root filesystem.
readOnlyRootFilesystem: false
# add/drop capabilities for BE container.
capabilities: {}
# add:
Expand Down
9 changes: 9 additions & 0 deletions helm-charts/charts/kube-starrocks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ starrocks:
# If runAsNonRoot is true, the container is run as non-root user.
# The userId will be set to 1000, and the groupID will be set to 1000.
runAsNonRoot: false
# Whether this container has a read-only root filesystem.
# Note: The FE/BE/CN container should support read-only root filesystem. The newest version of FE/BE/CN is 3.3.6, and does not support read-only root filesystem.
readOnlyRootFilesystem: false
# specify the service name and port config and serviceType
# the service type refer https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
service:
Expand Down Expand Up @@ -528,6 +531,9 @@ starrocks:
# If runAsNonRoot is true, the container is run as non-root user.
# The userId will be set to 1000, and the groupID will be set to 1000.
runAsNonRoot: false
# Whether this container has a read-only root filesystem.
# Note: The FE/BE/CN container should support read-only root filesystem. The newest version of FE/BE/CN is 3.3.6, and does not support read-only root filesystem.
readOnlyRootFilesystem: false
# add/drop capabilities for CN container.
capabilities: {}
# add:
Expand Down Expand Up @@ -831,6 +837,9 @@ starrocks:
# If runAsNonRoot is true, the container is run as non-root user.
# The userId will be set to 1000, and the groupID will be set to 1000.
runAsNonRoot: false
# Whether this container has a read-only root filesystem.
# Note: The FE/BE/CN container should support read-only root filesystem. The newest version of FE/BE/CN is 3.3.6, and does not support read-only root filesystem.
readOnlyRootFilesystem: false
# add/drop capabilities for BE container.
capabilities: {}
# add:
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/starrocks/v1/component_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ type StarRocksComponentSpec struct {
// MaxUnavailableStatefulSet feature gate enabled.
// +optional
UpdateStrategy *appv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`

// Whether this container has a read-only root filesystem.
// Default is false.
// Note that:
// 1. This field cannot be set when spec.os.name is windows.
// 2. The FE/BE/CN container should support read-only root filesystem. The newest version of FE/BE/CN is 3.3.6,
// and does not support read-only root filesystem
// +optional
ReadOnlyRootFilesystem *bool `json:"readOnlyRootFilesystem,omitempty" protobuf:"varint,6,opt,name=readOnlyRootFilesystem"`
}

// StarRocksComponentStatus represents the status of a starrocks component.
Expand Down Expand Up @@ -234,3 +243,11 @@ func ValidUpdateStrategy(updateStrategy *appv1.StatefulSetUpdateStrategy) error
}
return nil
}

func (spec *StarRocksComponentSpec) IsReadOnlyRootFilesystem() *bool {
if spec.ReadOnlyRootFilesystem == nil {
b := false
return &b
}
return spec.ReadOnlyRootFilesystem
}
10 changes: 9 additions & 1 deletion pkg/apis/starrocks/v1/starrockscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type SpecInterface interface {
GetCapabilities() *corev1.Capabilities
GetSidecars() []corev1.Container
GetInitContainers() []corev1.Container
IsReadOnlyRootFilesystem() *bool
}

var _ SpecInterface = &StarRocksFeSpec{}
Expand Down Expand Up @@ -219,7 +220,7 @@ func (spec *StarRocksFeProxySpec) GetInitContainers() []corev1.Container {

// GetCommand
// fe proxy does not have field command, the reason why implementing this method is
// // that StarRocksFeProxySpec needs to implement SpecInterface interface
// that StarRocksFeProxySpec needs to implement SpecInterface interface
func (spec *StarRocksFeProxySpec) GetCommand() []string {
return nil
}
Expand All @@ -236,6 +237,13 @@ func (spec *StarRocksFeProxySpec) GetUpdateStrategy() *appv1.StatefulSetUpdateSt
return nil
}

// IsReadOnlyRootFilesystem
// fe proxy does not have field ReadOnlyRootFilesystem, the reason why implementing this method is
// that StarRocksFeProxySpec needs to implement SpecInterface interface
func (spec *StarRocksFeProxySpec) IsReadOnlyRootFilesystem() *bool {
return nil
}

// Phase is defined under status, e.g.
// 1. StarRocksClusterStatus.Phase represents the phase of starrocks cluster.
// 2. StarRocksWarehouseStatus.Phase represents the phase of starrocks warehouse.
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/starrocks/v1/zz_generated.deepcopy.go

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

3 changes: 1 addition & 2 deletions pkg/k8sutils/templates/pod/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ func ContainerSecurityContext(spec v1.SpecInterface) *corev1.SecurityContext {
RunAsGroup: groupID,
RunAsNonRoot: runAsNonRoot,
AllowPrivilegeEscalation: func() *bool { b := false; return &b }(),
// starrocks will create pid file, e.g. /opt/starrocks/fe/bin/fe.pid, so set it to false
ReadOnlyRootFilesystem: func() *bool { b := false; return &b }(),
ReadOnlyRootFilesystem: spec.IsReadOnlyRootFilesystem(),
// set additional Capabilities
Capabilities: spec.GetCapabilities(),
}
Expand Down

0 comments on commit 06af429

Please sign in to comment.