Skip to content

Commit 8043209

Browse files
committed
Add command args to container creation (#6)
formatting formatting
1 parent 933a659 commit 8043209

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

apis/druid/v1alpha1/druid_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@ type DruidSpec struct {
5353
// +optional
5454
DeleteOrphanPvc bool `json:"deleteOrphanPvc"`
5555

56-
// Required: path to druid start script to be run on container start
56+
// Required: Command to be run on container start
5757
StartScript string `json:"startScript"`
5858

59+
// Optional: bash/sh entry arg. Set startScript to `sh` or `bash` to customize entryArg
60+
// For example, the container can run `sh -c "${EntryArg} && ${DruidScript} {nodeType}"`
61+
EntryArg string `json:"entryArg,omitempty"`
62+
63+
// Optional: Customized druid shell script path. If not set, the default would be "bin/run-druid.sh"
64+
DruidScript string `json:"druidScript,omitempty"`
65+
5966
// Required here or at nodeSpec level
6067
Image string `json:"image,omitempty"`
6168

chart/templates/crds/druid.apache.org_druids.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,10 @@ spec:
37003700
type: array
37013701
startScript:
37023702
type: string
3703+
entryArg:
3704+
type: string
3705+
druidScript:
3706+
type: string
37033707
startUpProbes:
37043708
properties:
37053709
exec:

controllers/druid/handler.go

Lines changed: 18 additions & 1 deletion
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.
@@ -1312,7 +1328,8 @@ func makePodSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, nodeSpecUn
13121328
{
13131329
Image: firstNonEmptyStr(nodeSpec.Image, m.Spec.Image),
13141330
Name: fmt.Sprintf("%s", nodeSpecUniqueStr),
1315-
Command: []string{firstNonEmptyStr(m.Spec.StartScript, "bin/run-druid.sh"), nodeSpec.NodeType},
1331+
Command: getCommand(nodeSpec, m),
1332+
Args: getEntryArg(nodeSpec, m),
13161333
ImagePullPolicy: v1.PullPolicy(firstNonEmptyStr(string(nodeSpec.ImagePullPolicy), string(m.Spec.ImagePullPolicy))),
13171334
Ports: nodeSpec.Ports,
13181335
Resources: nodeSpec.Resources,

0 commit comments

Comments
 (0)