Skip to content

Commit e4cc43f

Browse files
committed
Add command args to container creation (#6)
formatting formatting
1 parent 480ccb5 commit e4cc43f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Diff for: apis/druid/v1alpha1/druid_types.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,16 @@ type DruidSpec struct {
9191
// +optional
9292
DeleteOrphanPvc bool `json:"deleteOrphanPvc"`
9393

94-
// Required: path to druid start script to be run on container start
94+
// Required: Command to be run on container start
9595
StartScript string `json:"startScript"`
9696

97+
// Optional: bash/sh entry arg. Set startScript to `sh` or `bash` to customize entryArg
98+
// For example, the container can run `sh -c "${EntryArg} && ${DruidScript} {nodeType}"`
99+
EntryArg string `json:"entryArg,omitempty"`
100+
101+
// Optional: Customized druid shell script path. If not set, the default would be "bin/run-druid.sh"
102+
DruidScript string `json:"druidScript,omitempty"`
103+
97104
// Required here or at nodeSpec level
98105
Image string `json:"image,omitempty"`
99106

Diff for: controllers/druid/handler.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"regexp"
1111
"sort"
12+
"strings"
1213

1314
autoscalev2beta2 "k8s.io/api/autoscaling/v2beta2"
1415
networkingv1 "k8s.io/api/networking/v1"
@@ -1138,6 +1139,21 @@ func getVolume(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, nodeSpecUniq
11381139
return volumesHolder
11391140
}
11401141

1142+
func getCommand(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) []string {
1143+
if m.Spec.StartScript != "" && m.Spec.EntryArg != "" {
1144+
return []string{m.Spec.StartScript}
1145+
}
1146+
return []string{firstNonEmptyStr(m.Spec.StartScript, "bin/run-druid.sh"), nodeSpec.NodeType}
1147+
}
1148+
1149+
func getEntryArg(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) []string {
1150+
if m.Spec.EntryArg != "" {
1151+
bashCommands := strings.Join([]string{m.Spec.EntryArg, "&&", firstNonEmptyStr(m.Spec.DruidScript, "bin/run-druid.sh"), nodeSpec.NodeType}, " ")
1152+
return []string{"-c", bashCommands}
1153+
}
1154+
return nil
1155+
}
1156+
11411157
func getEnv(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, configMapSHA string) []v1.EnvVar {
11421158
envHolder := firstNonNilValue(nodeSpec.Env, m.Spec.Env).([]v1.EnvVar)
11431159
// enables to do the trick to force redeployment in case of configmap changes.
@@ -1308,7 +1324,8 @@ func makePodSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, nodeSpecUn
13081324
v1.Container{
13091325
Image: firstNonEmptyStr(nodeSpec.Image, m.Spec.Image),
13101326
Name: fmt.Sprintf("%s", nodeSpecUniqueStr),
1311-
Command: []string{firstNonEmptyStr(m.Spec.StartScript, "bin/run-druid.sh"), nodeSpec.NodeType},
1327+
Command: getCommand(nodeSpec, m),
1328+
Args: getEntryArg(nodeSpec, m),
13121329
ImagePullPolicy: v1.PullPolicy(firstNonEmptyStr(string(nodeSpec.ImagePullPolicy), string(m.Spec.ImagePullPolicy))),
13131330
Ports: nodeSpec.Ports,
13141331
Resources: nodeSpec.Resources,

0 commit comments

Comments
 (0)