Skip to content

Commit

Permalink
Merge pull request #28 from xiedeyantu/add-initcontainer
Browse files Browse the repository at this point in the history
add initcontainer to support set system parameters
  • Loading branch information
intelligentfu authored Sep 1, 2023
2 parents d822a54 + 6993e6d commit f968617
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -ldflags=$(LDFLAGS) -o bin/manager cmd/main.go
go build -ldflags=$(LDFLAGS) -o bin/dorisoperator cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down
11 changes: 11 additions & 0 deletions api/doris/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ type BaseSpec struct {
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`

PersistentVolumes []PersistentVolume `json:"persistentVolumes,omitempty"`

//SystemInitialization for fe, be and cn setting system parameters.
SystemInitialization *SystemInitialization `json:"systemInitialization,omitempty"`
}

type SystemInitialization struct {
// Entrypoint array. Not executed within a shell.
Command []string `json:"command,omitempty"`

// Arguments to the entrypoint.
Args []string `json:"args,omitempty"`
}

// PersistentVolume defines volume information and container mount information.
Expand Down
30 changes: 30 additions & 0 deletions api/doris/v1/zz_generated.deepcopy.go

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

60 changes: 60 additions & 0 deletions config/crd/bases/doris.selectdb.com_dorisclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,21 @@ spec:
serviceAccount:
description: serviceAccount for cn access cloud service.
type: string
systemInitialization:
description: SystemInitialization for fe, be and cn setting system
parameters.
properties:
args:
description: Arguments to the entrypoint.
items:
type: string
type: array
command:
description: Entrypoint array. Not executed within a shell.
items:
type: string
type: array
type: object
tolerations:
description: (Optional) Tolerations for scheduling pods onto some
dedicated nodes
Expand Down Expand Up @@ -2925,6 +2940,21 @@ spec:
serviceAccount:
description: serviceAccount for cn access cloud service.
type: string
systemInitialization:
description: SystemInitialization for fe, be and cn setting
system parameters.
properties:
args:
description: Arguments to the entrypoint.
items:
type: string
type: array
command:
description: Entrypoint array. Not executed within a shell.
items:
type: string
type: array
type: object
tolerations:
description: (Optional) Tolerations for scheduling pods onto
some dedicated nodes
Expand Down Expand Up @@ -5051,6 +5081,21 @@ spec:
serviceAccount:
description: serviceAccount for cn access cloud service.
type: string
systemInitialization:
description: SystemInitialization for fe, be and cn setting system
parameters.
properties:
args:
description: Arguments to the entrypoint.
items:
type: string
type: array
command:
description: Entrypoint array. Not executed within a shell.
items:
type: string
type: array
type: object
tolerations:
description: (Optional) Tolerations for scheduling pods onto some
dedicated nodes
Expand Down Expand Up @@ -6482,6 +6527,21 @@ spec:
serviceAccount:
description: serviceAccount for cn access cloud service.
type: string
systemInitialization:
description: SystemInitialization for fe, be and cn setting system
parameters.
properties:
args:
description: Arguments to the entrypoint.
items:
type: string
type: array
command:
description: Entrypoint array. Not executed within a shell.
items:
type: string
type: array
type: object
tolerations:
description: (Optional) Tolerations for scheduling pods onto some
dedicated nodes
Expand Down
18 changes: 18 additions & 0 deletions doc/examples/doriscluster-sample-system-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: doris.selectdb.com/v1
kind: DorisCluster
metadata:
labels:
app.kubernetes.io/name: doriscluster
app.kubernetes.io/instance: doriscluster-sample
app.kubernetes.io/part-of: doris-operator
name: doriscluster-sample-system-params
namespace: doris
spec:
feSpec:
replicas: 3
image: selectdb/doris.fe-ubuntu:latest
beSpec:
replicas: 3
image: selectdb/doris.be-ubuntu:latest
systemInitialization:
command: ["/sbin/sysctl", "-w", "vm.max_map_count=2000000"]
33 changes: 30 additions & 3 deletions pkg/common/utils/resource/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ const (
DEFAULT_ROOT_PATH = "/opt/apache-doris"
)

func NewPodTemplateSpc(dcr *v1.DorisCluster, componentType v1.ComponentType) corev1.PodTemplateSpec {
func NewPodTemplateSpec(dcr *v1.DorisCluster, componentType v1.ComponentType) corev1.PodTemplateSpec {
spec := getBaseSpecFromCluster(dcr, componentType)
var volumes []corev1.Volume
var si *v1.SystemInitialization
switch componentType {
case v1.Component_FE:
volumes = newVolumesFromBaseSpec(dcr.Spec.FeSpec.BaseSpec)
si = dcr.Spec.FeSpec.BaseSpec.SystemInitialization
case v1.Component_BE:
volumes = newVolumesFromBaseSpec(dcr.Spec.BeSpec.BaseSpec)
si = dcr.Spec.BeSpec.BaseSpec.SystemInitialization
case v1.Component_CN:
si = dcr.Spec.CnSpec.BaseSpec.SystemInitialization
default:
klog.Errorf("NewPodTemplateSpc dorisClusterName %s, namespace %s componentType %s not supported.", dcr.Name, dcr.Namespace, componentType)
klog.Errorf("NewPodTemplateSpec dorisClusterName %s, namespace %s componentType %s not supported.", dcr.Name, dcr.Namespace, componentType)
}

if len(volumes) == 0 {
Expand All @@ -53,7 +58,7 @@ func NewPodTemplateSpc(dcr *v1.DorisCluster, componentType v1.ComponentType) cor
volumes = append(volumes, configVolume)
}

return corev1.PodTemplateSpec{
pts := corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: generatePodTemplateName(dcr, componentType),
Labels: v1.GetPodLabels(dcr, componentType),
Expand All @@ -69,6 +74,13 @@ func NewPodTemplateSpc(dcr *v1.DorisCluster, componentType v1.ComponentType) cor
HostAliases: spec.HostAliases,
},
}

if si != nil {
initContainer := newBaseInitContainer("init", si)
pts.Spec.InitContainers = append(pts.Spec.InitContainers, initContainer)
}

return pts
}

func newDefaultVolume(componentType v1.ComponentType) []corev1.Volume {
Expand Down Expand Up @@ -135,6 +147,21 @@ func mergeEnvs(src []corev1.EnvVar, dst []corev1.EnvVar) []corev1.EnvVar {
return dst
}

func newBaseInitContainer(name string, si *v1.SystemInitialization) corev1.Container {
enablePrivileged := true
c := corev1.Container{
Image: "alpine:latest",
Name: name,
Command: si.Command,
ImagePullPolicy: corev1.PullIfNotPresent,
Args: si.Args,
SecurityContext: &corev1.SecurityContext{
Privileged: &enablePrivileged,
},
}
return c
}

func NewBaseMainContainer(dcr *v1.DorisCluster, config map[string]interface{}, componentType v1.ComponentType) corev1.Container {
command, args := getCommand(componentType)
var spec v1.BaseSpec
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/utils/resource/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewStatefulSet(dcr *v1.DorisCluster, componentType v1.ComponentType) appv1.
Spec: appv1.StatefulSetSpec{
Replicas: bSpec.Replicas,
Selector: &selector,
Template: NewPodTemplateSpc(dcr, componentType),
Template: NewPodTemplateSpec(dcr, componentType),
VolumeClaimTemplates: volumeClaimTemplates,
ServiceName: v1.GenerateInternalCommunicateServiceName(dcr, componentType),
RevisionHistoryLimit: metadata.GetInt32Pointer(5),
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/sub_controller/be/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package be

import (
"context"
"strconv"

v1 "github.com/selectdb/doris-operator/api/doris/v1"
"github.com/selectdb/doris-operator/pkg/common/utils/resource"
corev1 "k8s.io/api/core/v1"
"strconv"
)

func (be *Controller) buildBEPodTemplateSpec(dcr *v1.DorisCluster) corev1.PodTemplateSpec {
podTemplateSpec := resource.NewPodTemplateSpc(dcr, v1.Component_BE)
podTemplateSpec := resource.NewPodTemplateSpec(dcr, v1.Component_BE)
var containers []corev1.Container
containers = append(containers, podTemplateSpec.Spec.Containers...)
beContainer := be.beContainer(dcr)
Expand Down
11 changes: 6 additions & 5 deletions pkg/controller/sub_controller/cn/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package cn

import (
"context"
"strconv"

v1 "github.com/selectdb/doris-operator/api/doris/v1"
"github.com/selectdb/doris-operator/pkg/common/utils/resource"
corev1 "k8s.io/api/core/v1"
"strconv"
)

func (cn *Controller) buildCnPodTemplateSpec(dcr *v1.DorisCluster) corev1.PodTemplateSpec {
podTemplateSpc := resource.NewPodTemplateSpc(dcr, v1.Component_CN)
podTemplateSpec := resource.NewPodTemplateSpec(dcr, v1.Component_CN)
var containers []corev1.Container
containers = append(containers, podTemplateSpc.Spec.Containers...)
containers = append(containers, podTemplateSpec.Spec.Containers...)
cnContainer := cn.cnContainer(dcr)
containers = append(containers, cnContainer)
podTemplateSpc.Spec.Containers = containers
return podTemplateSpc
podTemplateSpec.Spec.Containers = containers
return podTemplateSpec
}

func (cn *Controller) cnContainer(dcr *v1.DorisCluster) corev1.Container {
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/sub_controller/fe/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package fe

import (
"context"
"strconv"

v1 "github.com/selectdb/doris-operator/api/doris/v1"
"github.com/selectdb/doris-operator/pkg/common/utils/resource"
corev1 "k8s.io/api/core/v1"
"strconv"
)

func (fc *Controller) buildFEPodTemplateSpec(dcr *v1.DorisCluster) corev1.PodTemplateSpec {
podTemplateSpec := resource.NewPodTemplateSpc(dcr, v1.Component_FE)
podTemplateSpec := resource.NewPodTemplateSpec(dcr, v1.Component_FE)
var containers []corev1.Container
//containers = append(containers, podTemplateSpec.Spec.Containers...)
config, _ := fc.GetConfig(context.Background(), &dcr.Spec.FeSpec.ConfigMapInfo, dcr.Namespace)
Expand Down

0 comments on commit f968617

Please sign in to comment.