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 Oct 29, 2022
1 parent 480ccb5 commit e4cc43f
Show file tree
Hide file tree
Showing 2 changed files with 26 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 @@ -91,9 +91,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
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 @@ -1308,7 +1324,8 @@ func makePodSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, nodeSpecUn
v1.Container{
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 e4cc43f

Please sign in to comment.