Network Key Translation Feature and test cases (#1195)

This commit is contained in:
Mudit Verma
2019-12-01 10:19:23 +08:00
committed by Hang Yan
parent c13d50ee17
commit ac2b852955
18 changed files with 606 additions and 40 deletions
+11 -1
View File
@@ -836,7 +836,7 @@ convert::expect_success "$cmd" "/tmp/output-k8s.json"
## Test compose v3.5+
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-3.5.yaml"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/v3/output-k8s-3.5.json > /tmp/output-k8s.json
convert::expect_success "$cmd" "/tmp/output-k8s.json"
convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json"
## Test OpenShift for compose v3.3
cmd="kompose --provider openshift convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-config-long.yaml"
@@ -861,3 +861,13 @@ go test -v github.com/kubernetes/kompose/script/test/cmd
rm /tmp/output-k8s.json /tmp/output-os.json
exit $EXIT_STATUS
# Network Translation compose v3
cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/network/docker-compose-v3.yaml convert --stdout -j"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/network/output-k8s.json > /tmp/output-k8s.json
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/network/docker-compose-v3.yaml convert --stdout -j"
# OpenShift test
cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/network/docker-compose-v3.yaml convert --stdout -j"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/network/output-os.json > /tmp/output-os.json
convert::expect_success "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/network/docker-compose-v3.yaml convert --stdout -j"
+15
View File
@@ -0,0 +1,15 @@
version: '3'
networks:
app:
external:
name: app-network
web:
external:
name: web-network
services:
appFoo:
image: foo:latest
command: sh -c "echo Hello Foo"
networks:
app: {}
web: {}
+112
View File
@@ -0,0 +1,112 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "appfoo",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "appfoo"
},
"annotations": {
"kompose.cmd": "%CMD%"
"kompose.version": "%VERSION%"
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.network/app-network": "true",
"io.kompose.network/web-network": "true",
"io.kompose.service": "appfoo"
},
"annotations": {
"kompose.cmd": "%CMD%"
"kompose.version": "%VERSION%"
}
},
"spec": {
"containers": [
{
"name": "appfoo",
"image": "foo:latest",
"args": [
"sh",
"-c",
"echo Hello Foo"
],
"resources": {}
}
],
"restartPolicy": "Always"
}
},
"strategy": {}
},
"status": {}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "app-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/app-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/app-network": "true"
}
}
}
]
}
]
}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "web-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/web-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/web-network": "true"
}
}
}
]
}
]
}
}
]
}
+104
View File
@@ -0,0 +1,104 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "appfoo",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "appfoo"
},
"annotations": {
"kompose.cmd": "%CMD%"
"kompose.version": "%VERSION%"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"appfoo"
],
"from": {
"kind": "ImageStreamTag",
"name": "appfoo:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "appfoo"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.network/app-network": "true",
"io.kompose.network/web-network": "true",
"io.kompose.service": "appfoo"
}
},
"spec": {
"containers": [
{
"name": "appfoo",
"image": " ",
"args": [
"sh",
"-c",
"echo Hello Foo"
],
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "appfoo",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "appfoo"
}
},
"spec": {
"tags": [
{
"name": "latest",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "foo:latest"
},
"generation": null,
"importPolicy": {}
}
]
},
"status": {
"dockerImageRepository": ""
}
}
]
}
+29
View File
@@ -53,6 +53,7 @@
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.network/helloworld-network": "true",
"io.kompose.service": "helloworld"
},
"annotations": {
@@ -79,6 +80,34 @@
"strategy": {}
},
"status": {}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "helloworld-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/helloworld-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/helloworld-network": "true"
}
}
}
]
}
]
}
}
]
}
@@ -10,6 +10,9 @@
"name": "foo",
"creationTimestamp": null,
"labels": {
"io.kompose.network/other-network": "true",
"io.kompose.network/other-other-network": "true",
"io.kompose.network/some-network": "true",
"io.kompose.service": "foo"
}
},
@@ -344,6 +347,90 @@
}
},
"status": {}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "other-other-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/other-other-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/other-other-network": "true"
}
}
}
]
}
]
}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "some-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/some-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/some-network": "true"
}
}
}
]
}
]
}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "other-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/other-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/other-network": "true"
}
}
}
]
}
]
}
}
]
}
+87
View File
@@ -153,6 +153,9 @@
"name": "foo",
"creationTimestamp": null,
"labels": {
"io.kompose.network/other-network": "true",
"io.kompose.network/other-other-network": "true",
"io.kompose.network/some-network": "true",
"io.kompose.service": "foo"
}
},
@@ -503,6 +506,90 @@
}
},
"status": {}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "other-other-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/other-other-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/other-other-network": "true"
}
}
}
]
}
]
}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "some-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/some-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/some-network": "true"
}
}
}
]
}
]
}
},
{
"kind": "NetworkPolicy",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "other-network",
"creationTimestamp": null
},
"spec": {
"podSelector": {
"matchLabels": {
"io.kompose.network/other-network": "true"
}
},
"ingress": [
{
"from": [
{
"podSelector": {
"matchLabels": {
"io.kompose.network/other-network": "true"
}
}
}
]
}
]
}
}
]
}
+3
View File
@@ -153,6 +153,9 @@
"name": "foo",
"creationTimestamp": null,
"labels": {
"io.kompose.network/other-network": "true",
"io.kompose.network/other-other-network": "true",
"io.kompose.network/some-network": "true",
"io.kompose.service": "foo"
}
},