diff --git a/internal/chart/application_chart.go b/internal/chart/application_chart.go index 9ae575ff..602a39c4 100644 --- a/internal/chart/application_chart.go +++ b/internal/chart/application_chart.go @@ -145,7 +145,7 @@ func New(application *ketchv1.App, pool *ketchv1.Pool, opts ...Option) (*Applica return nil, err } exposedPorts := options.ExposedPorts[deployment.Version] - c := NewConfigurator(deploymentSpec.KetchYaml, *procfile, exposedPorts, DefaultApplicationPort) + c := NewConfigurator(deploymentSpec.KetchYaml, *procfile, exposedPorts, DefaultApplicationPort, application.Spec.Platform) for _, processSpec := range deploymentSpec.Processes { name := processSpec.Name isRoutable := procfile.IsRoutable(name) diff --git a/internal/chart/application_chart_test.go b/internal/chart/application_chart_test.go index 250554b5..403ccdac 100644 --- a/internal/chart/application_chart_test.go +++ b/internal/chart/application_chart_test.go @@ -55,6 +55,7 @@ func TestNew(t *testing.T) { Name: "dashboard", }, Spec: ketchv1.AppSpec{ + Platform: "static", Deployments: []ketchv1.AppDeploymentSpec{ { Image: "shipasoftware/go-app:v1", diff --git a/internal/chart/configurator.go b/internal/chart/configurator.go index 98e64049..e75c35ad 100644 --- a/internal/chart/configurator.go +++ b/internal/chart/configurator.go @@ -19,10 +19,11 @@ type Configurator struct { procfile Procfile exposedPorts []ketchv1.ExposedPort defaultPort int + platform string } // NewConfigurator returns a Configurator instance. -func NewConfigurator(data *ketchv1.KetchYamlData, procfile Procfile, exposedPorts []ketchv1.ExposedPort, defaultPort int) Configurator { +func NewConfigurator(data *ketchv1.KetchYamlData, procfile Procfile, exposedPorts []ketchv1.ExposedPort, defaultPort int, platform string) Configurator { shipaYaml := ketchv1.KetchYamlData{} if data != nil { shipaYaml = *data @@ -32,6 +33,7 @@ func NewConfigurator(data *ketchv1.KetchYamlData, procfile Procfile, exposedPort procfile: procfile, exposedPorts: exposedPorts, defaultPort: defaultPort, + platform: strings.ToLower(platform), } } @@ -206,6 +208,11 @@ func (c Configurator) ServicePortsForProcess(process string) []apiv1.ServicePort } func (c Configurator) ProcessCmd(process string) []string { + // If we are not using an existing Shipa platform return the commands unmodified. In this case + // the onus is on the image creator to build an image with entry points/commands that k8s understands. + if c.platform == "" { + return c.procfile.Processes[process] + } cmd := c.procfile.Processes[process] before := "" if c.data.Hooks != nil { diff --git a/internal/chart/configurator_test.go b/internal/chart/configurator_test.go index 4706bc3b..88f2116f 100644 --- a/internal/chart/configurator_test.go +++ b/internal/chart/configurator_test.go @@ -14,6 +14,7 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) { procfile Procfile process string want []string + platform string }{ { name: "single command without changing working directory", @@ -22,8 +23,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) { "web": {"python web.py"}, }, }, - process: "web", - want: []string{"/bin/sh", "-lc", "exec python web.py"}, + process: "web", + want: []string{"/bin/sh", "-lc", "exec python web.py"}, + platform: "python", }, { name: "single command", @@ -32,8 +34,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) { "web": {"python web.py"}, }, }, - process: "web", - want: []string{"/bin/sh", "-lc", "exec python web.py"}, + process: "web", + want: []string{"/bin/sh", "-lc", "exec python web.py"}, + platform: "python", }, { name: "single command with hooks", @@ -51,8 +54,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) { "web": {"python web.py"}, }, }, - process: "web", - want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"}, + process: "web", + want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"}, + platform: "python", }, { name: "single command with hooks, without changing working directory", @@ -70,8 +74,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) { "web": {"python web.py"}, }, }, - process: "web", - want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"}, + process: "web", + want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"}, + platform: "python", }, { name: "many commands", @@ -80,8 +85,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) { "web": {"python", "web.py"}, }, }, - process: "web", - want: []string{"/bin/sh", "-lc", "exec $0 \"$@\"", "python", "web.py"}, + process: "web", + want: []string{"/bin/sh", "-lc", "exec $0 \"$@\"", "python", "web.py"}, + platform: "python", }, } for _, tt := range tests { @@ -89,6 +95,7 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) { conf := Configurator{ data: tt.data, procfile: tt.procfile, + platform: tt.platform, } if got := conf.ProcessCmd(tt.process); !reflect.DeepEqual(got, tt.want) { t.Errorf("ProcessCmd() = %v, want %v", got, tt.want)