Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stdin_open, tty support, add tests, fix #344 #350

Merged
merged 1 commit into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/kobject/kobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/loader/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
8 changes: 8 additions & 0 deletions pkg/transformer/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func newServiceConfig() kobject.ServiceConfig {
Privileged: true,
Restart: "always",
User: "user", // not supported
Stdin: true,
Tty: true,
}
}

Expand Down Expand Up @@ -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
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/transformer/openshift/openshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A log saying what this test runs will help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments are missing in other tests!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for TestOpenShiftUpdateKubernetesObjects, log messages for other tests should go in another PR. Tracked at #351


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)
}
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions script/test/cmd/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ convert::expect_success "kompose --file $KOMPOSE_ROOT/script/test/fixtures/keyon
unset $(cat $KOMPOSE_ROOT/script/test/fixtures/keyonly-envs/envs | cut -d'=' -f1)


######
# Test related to "stdin_open: true" in docker-compose
# kubernetes test
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/stdin-true/docker-compose.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/stdin-true/output-k8s.json"
# openshift test
convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/stdin-true/docker-compose.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/stdin-true/output-oc.json"


######
# Test related to "tty: true" in docker-compose
# kubernetes test
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/tty-true/docker-compose.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/tty-true/output-k8s.json"
# openshift test
convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/tty-true/docker-compose.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/tty-true/output-oc.json"


# Test related to kompose.expose.service label in docker compose file to ensure that services are exposed properly
#kubernetes tests
# when kompose.service.expose="True"
Expand Down
7 changes: 7 additions & 0 deletions script/test/fixtures/stdin-true/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "2"
services:
client:
image: registry.centos.org/centos/centos:7
ports:
- "1337"
stdin_open: true
72 changes: 72 additions & 0 deletions script/test/fixtures/stdin-true/output-k8s.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "client",
"creationTimestamp": null,
"labels": {
"service": "client"
}
},
"spec": {
"ports": [
{
"name": "1337",
"protocol": "TCP",
"port": 1337,
"targetPort": 1337
}
],
"selector": {
"service": "client"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "client",
"creationTimestamp": null
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"service": "client"
}
},
"spec": {
"containers": [
{
"name": "client",
"image": "registry.centos.org/centos/centos:7",
"ports": [
{
"containerPort": 1337,
"protocol": "TCP"
}
],
"resources": {},
"stdin": true
}
],
"restartPolicy": "Always"
}
},
"strategy": {}
},
"status": {}
}
]
}
124 changes: 124 additions & 0 deletions script/test/fixtures/stdin-true/output-oc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "client",
"creationTimestamp": null,
"labels": {
"service": "client"
}
},
"spec": {
"ports": [
{
"name": "1337",
"protocol": "TCP",
"port": 1337,
"targetPort": 1337
}
],
"selector": {
"service": "client"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "client",
"creationTimestamp": null,
"labels": {
"service": "client"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"client"
],
"from": {
"kind": "ImageStreamTag",
"name": "client:7"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"service": "client"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"service": "client"
}
},
"spec": {
"containers": [
{
"name": "client",
"image": " ",
"ports": [
{
"containerPort": 1337,
"protocol": "TCP"
}
],
"resources": {},
"stdin": true
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "client",
"creationTimestamp": null
},
"spec": {
"tags": [
{
"name": "7",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "registry.centos.org/centos/centos:7"
},
"generation": null,
"importPolicy": {}
}
]
},
"status": {
"dockerImageRepository": ""
}
}
]
}
7 changes: 7 additions & 0 deletions script/test/fixtures/tty-true/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "2"
services:
client:
image: registry.centos.org/centos/centos:7
ports:
- "1337"
tty: true
Loading