add stdin_open, tty support, add tests, fix #344
This adds supports for stdin_open: bool and tty: bool support for kubernetes and openshift providers in kompose. This maps to the template.Spec.Containers[0].Stdin and template.Spec.Containers[0].TTY in Kubernets world. Also, added tests. Fixes #344
This commit is contained in:
@@ -69,6 +69,8 @@ type ServiceConfig struct {
|
||||
ServiceType string `compose:"kompose.service.type",bundle:""`
|
||||
Build string `compose:"build",bundle:""`
|
||||
ExposeService string `compose:"kompose.service.expose",bundle:""`
|
||||
Stdin bool `compose:"stdin_open",bundle:""`
|
||||
Tty bool `compose:"tty",bundle:""`
|
||||
}
|
||||
|
||||
// EnvVar holds the environment variable struct of a container
|
||||
|
||||
@@ -72,8 +72,6 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
|
||||
"VolumeDriver": false,
|
||||
"Uts": false,
|
||||
"ReadOnly": false,
|
||||
"StdinOpen": false,
|
||||
"Tty": false,
|
||||
"Ulimits": false,
|
||||
"Dockerfile": false,
|
||||
"Net": false,
|
||||
@@ -320,6 +318,8 @@ func (c *Compose) LoadFile(file string) kobject.KomposeObject {
|
||||
serviceConfig.Restart = composeServiceConfig.Restart
|
||||
serviceConfig.User = composeServiceConfig.User
|
||||
serviceConfig.VolumesFrom = composeServiceConfig.VolumesFrom
|
||||
serviceConfig.Stdin = composeServiceConfig.StdinOpen
|
||||
serviceConfig.Tty = composeServiceConfig.Tty
|
||||
|
||||
komposeObject.ServiceConfigs[name] = serviceConfig
|
||||
}
|
||||
|
||||
@@ -324,6 +324,8 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
|
||||
template.Spec.Containers[0].Args = service.Args
|
||||
template.Spec.Containers[0].WorkingDir = service.WorkingDir
|
||||
template.Spec.Containers[0].VolumeMounts = volumesMount
|
||||
template.Spec.Containers[0].Stdin = service.Stdin
|
||||
template.Spec.Containers[0].TTY = service.Tty
|
||||
template.Spec.Volumes = volumes
|
||||
|
||||
securityContext := &api.SecurityContext{}
|
||||
|
||||
@@ -53,6 +53,8 @@ func newServiceConfig() kobject.ServiceConfig {
|
||||
Privileged: true,
|
||||
Restart: "always",
|
||||
User: "user", // not supported
|
||||
Stdin: true,
|
||||
Tty: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +170,12 @@ func checkPodTemplate(config kobject.ServiceConfig, template api.PodTemplateSpec
|
||||
if config.Privileged == privilegedNilOrFalse(template) {
|
||||
return fmt.Errorf("Found different template privileged: %#v vs. %#v", config.Privileged, template.Spec.Containers[0].SecurityContext)
|
||||
}
|
||||
if config.Stdin != template.Spec.Containers[0].Stdin {
|
||||
return fmt.Errorf("Found different values for stdin: %#v vs. %#v", config.Stdin, template.Spec.Containers[0].Stdin)
|
||||
}
|
||||
if config.Tty != template.Spec.Containers[0].TTY {
|
||||
return fmt.Errorf("Found different values for TTY: %#v vs. %#v", config.Tty, template.Spec.Containers[0].TTY)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ package openshift
|
||||
|
||||
import (
|
||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -44,6 +46,32 @@ func newServiceConfig() kobject.ServiceConfig {
|
||||
Privileged: true,
|
||||
Restart: "always",
|
||||
User: "user", // not supported
|
||||
Stdin: true,
|
||||
Tty: true,
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenShiftUpdateKubernetesObjects(t *testing.T) {
|
||||
t.Log("Test case: Testing o.UpdateKubernetesObjects()")
|
||||
var object []runtime.Object
|
||||
o := OpenShift{}
|
||||
serviceConfig := newServiceConfig()
|
||||
|
||||
object = append(object, o.initDeploymentConfig("foobar", serviceConfig, 3))
|
||||
o.UpdateKubernetesObjects("foobar", serviceConfig, &object)
|
||||
|
||||
for _, obj := range object {
|
||||
switch tobj := obj.(type) {
|
||||
case *deployapi.DeploymentConfig:
|
||||
t.Log("> Testing if stdin is set correctly")
|
||||
if tobj.Spec.Template.Spec.Containers[0].Stdin != serviceConfig.Stdin {
|
||||
t.Errorf("Expected stdin to be %v, got %v instead", serviceConfig.Stdin, tobj.Spec.Template.Spec.Containers[0].Stdin)
|
||||
}
|
||||
t.Log("> Testing if TTY is set correctly")
|
||||
if tobj.Spec.Template.Spec.Containers[0].TTY != serviceConfig.Tty {
|
||||
t.Errorf("Expected TTY to be %v, got %v instead", serviceConfig.Tty, tobj.Spec.Template.Spec.Containers[0].TTY)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user