Skip to content

Commit

Permalink
Add command args to container creation (#6)
Browse files Browse the repository at this point in the history
formatting

formatting
  • Loading branch information
CodingParsley committed Jan 7, 2022
1 parent 933a659 commit 8043209
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
9 changes: 8 additions & 1 deletion apis/druid/v1alpha1/druid_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ type DruidSpec struct {
// +optional
DeleteOrphanPvc bool `json:"deleteOrphanPvc"`

// Required: path to druid start script to be run on container start
// Required: Command to be run on container start
StartScript string `json:"startScript"`

// Optional: bash/sh entry arg. Set startScript to `sh` or `bash` to customize entryArg
// For example, the container can run `sh -c "${EntryArg} && ${DruidScript} {nodeType}"`
EntryArg string `json:"entryArg,omitempty"`

// Optional: Customized druid shell script path. If not set, the default would be "bin/run-druid.sh"
DruidScript string `json:"druidScript,omitempty"`

// Required here or at nodeSpec level
Image string `json:"image,omitempty"`

Expand Down
4 changes: 4 additions & 0 deletions chart/templates/crds/druid.apache.org_druids.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3700,6 +3700,10 @@ spec:
type: array
startScript:
type: string
entryArg:
type: string
druidScript:
type: string
startUpProbes:
properties:
exec:
Expand Down
19 changes: 18 additions & 1 deletion controllers/druid/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"regexp"
"sort"
"strings"

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

func getCommand(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) []string {
if (m.Spec.StartScript != "" && m.Spec.EntryArg != "") {
return []string{m.Spec.StartScript}
}
return []string{firstNonEmptyStr(m.Spec.StartScript, "bin/run-druid.sh"), nodeSpec.NodeType}
}

func getEntryArg(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) []string {
if (m.Spec.EntryArg != "") {
bashCommands := strings.Join([]string{m.Spec.EntryArg, "&&", firstNonEmptyStr(m.Spec.DruidScript, "bin/run-druid.sh"), nodeSpec.NodeType}, " ")
return []string{"-c", bashCommands}
}
return nil
}

func getEnv(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, configMapSHA string) []v1.EnvVar {
envHolder := firstNonNilValue(nodeSpec.Env, m.Spec.Env).([]v1.EnvVar)
// enables to do the trick to force redeployment in case of configmap changes.
Expand Down Expand Up @@ -1312,7 +1328,8 @@ func makePodSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, nodeSpecUn
{
Image: firstNonEmptyStr(nodeSpec.Image, m.Spec.Image),
Name: fmt.Sprintf("%s", nodeSpecUniqueStr),
Command: []string{firstNonEmptyStr(m.Spec.StartScript, "bin/run-druid.sh"), nodeSpec.NodeType},
Command: getCommand(nodeSpec, m),
Args: getEntryArg(nodeSpec, m),
ImagePullPolicy: v1.PullPolicy(firstNonEmptyStr(string(nodeSpec.ImagePullPolicy), string(m.Spec.ImagePullPolicy))),
Ports: nodeSpec.Ports,
Resources: nodeSpec.Resources,
Expand Down

0 comments on commit 8043209

Please sign in to comment.