Merge remote-tracking branch 'origin/master' into kompose_labels_test

This commit is contained in:
Anush Shetty 2017-05-25 12:18:29 +05:30
commit d2ad889367
9 changed files with 472 additions and 405 deletions

View File

@ -17,6 +17,8 @@ matrix:
install: install:
- true - true
# This is required because sometimes Travis ends up in a detached HEAD state after git clone
- script/test/cmd/fix_detached_head.sh
script: script:
- make test - make test

View File

@ -41,7 +41,7 @@ Installation methods:
- [Binary (Prefered method)](README.md) - [Binary (Prefered method)](README.md)
- [Go](/docs/setup.md#go) - [Go](/docs/setup.md#go)
- [CentOS](/docs/setup.md#centos) - [CentOS](/docs/setup.md#centos)
- [Fedora](/docs/setup.mdfedora) - [Fedora](/docs/setup.md#fedora)
- [macOS (Homebrew)](/docs/setup.md#macos) - [macOS (Homebrew)](/docs/setup.md#macos)
#### Binary installation #### Binary installation

View File

@ -41,6 +41,7 @@ import (
deployapi "github.com/openshift/origin/pkg/deploy/api" deployapi "github.com/openshift/origin/pkg/deploy/api"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/kubernetes/pkg/api/resource" "k8s.io/kubernetes/pkg/api/resource"
"sort"
) )
/** /**
@ -542,3 +543,13 @@ func (k *Kubernetes) VolumesFrom(objects *[]runtime.Object, komposeObject kobjec
} }
return nil return nil
} }
//Ensure the kubernetes objects are in a consistent order
func SortedKeys(komposeObject kobject.KomposeObject) []string {
var sortedKeys []string
for name := range komposeObject.ServiceConfigs {
sortedKeys = append(sortedKeys, name)
}
sort.Strings(sortedKeys)
return sortedKeys
}

View File

@ -29,6 +29,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
"reflect"
) )
/* /*
@ -275,3 +276,23 @@ func TestRecreateStrategyWithVolumesPresent(t *testing.T) {
} }
} }
} }
func TestSortedKeys(t *testing.T) {
service := kobject.ServiceConfig{
ContainerName: "name",
Image: "image",
}
service1 := kobject.ServiceConfig{
ContainerName: "name",
Image: "image",
}
c := []string{"a", "b"}
komposeObject := kobject.KomposeObject{
ServiceConfigs: map[string]kobject.ServiceConfig{"b": service, "a": service1},
}
a := SortedKeys(komposeObject)
if !reflect.DeepEqual(a, c) {
t.Logf("Test Fail output should be %s", c)
}
}

View File

@ -19,7 +19,6 @@ package kubernetes
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"sort"
"strconv" "strconv"
"time" "time"
@ -533,13 +532,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
// this will hold all the converted data // this will hold all the converted data
var allobjects []runtime.Object var allobjects []runtime.Object
// Need to ensure the kubernetes objects are in a consistent order sortedKeys := SortedKeys(komposeObject)
var sortedKeys []string
for name := range komposeObject.ServiceConfigs {
sortedKeys = append(sortedKeys, name)
}
sort.Strings(sortedKeys)
for _, name := range sortedKeys { for _, name := range sortedKeys {
service := komposeObject.ServiceConfigs[name] service := komposeObject.ServiceConfigs[name]
var objects []runtime.Object var objects []runtime.Object

View File

@ -339,7 +339,9 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
buildRepo := opt.BuildRepo buildRepo := opt.BuildRepo
buildBranch := opt.BuildBranch buildBranch := opt.BuildBranch
for name, service := range komposeObject.ServiceConfigs { sortedKeys := kubernetes.SortedKeys(komposeObject)
for _, name := range sortedKeys {
service := komposeObject.ServiceConfigs[name]
var objects []runtime.Object var objects []runtime.Object
// Generate pod only and nothing more // Generate pod only and nothing more

View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Copyright 2017 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Reference Link: https://github.com/theochem/horton/blob/master/tools/qa/fix_detached_head.sh
# Only do something if the HEAD is detached.
if [ $(git rev-parse --abbrev-ref HEAD) == 'HEAD' ]; then
# Give the some random name that no serious person would use.
git checkout -b build_branch
fi

View File

@ -17,6 +17,19 @@
KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..)
source $KOMPOSE_ROOT/script/test/cmd/lib.sh source $KOMPOSE_ROOT/script/test/cmd/lib.sh
# Get current branch and remote url of git repository
branch=$(git branch | grep \* | cut -d ' ' -f2-)
uri=$(git remote get-url origin)
if [[ $uri != *".git"* ]]; then
uri="${uri}.git"
fi
# Warning Template
warning="Buildconfig using $uri::$branch as source."
# Replacing variables with current branch and uri
sed -e "s;%URI%;$uri;g" -e "s;%REF%;$branch;g" $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os-template.json > /tmp/output-os.json
####### #######
# Tests related to docker-compose file in /script/test/fixtures/etherpad # Tests related to docker-compose file in /script/test/fixtures/etherpad
convert::expect_failure "kompose -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yml convert --stdout" convert::expect_failure "kompose -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yml convert --stdout"
@ -45,8 +58,7 @@ unset $(cat $KOMPOSE_ROOT/script/test/fixtures/gitlab/envs | cut -d'=' -f1)
# kubernetes test # kubernetes test
convert::expect_success_and_warning "kompose -f $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-k8s.json" "Kubernetes provider doesn't support build key - ignoring" convert::expect_success_and_warning "kompose -f $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-k8s.json" "Kubernetes provider doesn't support build key - ignoring"
# openshift test # openshift test
convert::expect_success_and_warning "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." convert::expect_success_and_warning "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/docker-compose.yml convert --stdout -j" "/tmp/output-os.json" "$warning"
###### ######
# Tests related to docker-compose file in /script/test/fixtures/entrypoint-command # Tests related to docker-compose file in /script/test/fixtures/entrypoint-command
# kubernetes test # kubernetes test
@ -199,11 +211,11 @@ convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/script/test/fixture
# Test regarding build context (running kompose from various directories) # Test regarding build context (running kompose from various directories)
CURRENT_DIR=$(pwd) CURRENT_DIR=$(pwd)
cd "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/" cd "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/"
convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j" "/tmp/output-os.json" "$warning"
cd "$KOMPOSE_ROOT/script/test/fixtures/" cd "$KOMPOSE_ROOT/script/test/fixtures/"
convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f nginx-node-redis/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f nginx-node-redis/docker-compose.yml" "/tmp/output-os.json" "$warning"
cd "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/node" cd "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/node"
convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f ../docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f ../docker-compose.yml" "/tmp/output-os.json" "$warning"
cd $CURRENT_DIR cd $CURRENT_DIR
# Test related to support docker-compose.yaml beside docker-compose.yml # Test related to support docker-compose.yaml beside docker-compose.yml
@ -222,4 +234,7 @@ convert::expect_success "kompose --provider=openshift convert --stdout -j" "$KOM
# Return back to the original path # Return back to the original path
cd $CURRENT_DIR cd $CURRENT_DIR
# Removes generated output
rm -rf /tmp/output-os.json
exit $EXIT_STATUS exit $EXIT_STATUS

View File

@ -3,6 +3,58 @@
"apiVersion": "v1", "apiVersion": "v1",
"metadata": {}, "metadata": {},
"items": [ "items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "nginx",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "nginx"
}
},
"spec": {
"ports": [
{
"name": "80",
"port": 80,
"targetPort": 80
}
],
"selector": {
"io.kompose.service": "nginx"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "node1",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node1"
}
},
"spec": {
"ports": [
{
"name": "8080",
"port": 8080,
"targetPort": 8080
}
],
"selector": {
"io.kompose.service": "node1"
}
},
"status": {
"loadBalancer": {}
}
},
{ {
"kind": "Service", "kind": "Service",
"apiVersion": "v1", "apiVersion": "v1",
@ -81,391 +133,6 @@
"loadBalancer": {} "loadBalancer": {}
} }
}, },
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "nginx",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "nginx"
}
},
"spec": {
"ports": [
{
"name": "80",
"port": 80,
"targetPort": 80
}
],
"selector": {
"io.kompose.service": "nginx"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "node1",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node1"
}
},
"spec": {
"ports": [
{
"name": "8080",
"port": 8080,
"targetPort": 8080
}
],
"selector": {
"io.kompose.service": "node1"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "node2",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node2"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"node2"
],
"from": {
"kind": "ImageStreamTag",
"name": "node2:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "node2"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node2"
}
},
"spec": {
"containers": [
{
"name": "node2",
"image": " ",
"ports": [
{
"containerPort": 8080
}
],
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "node2",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node2"
}
},
"spec": {},
"status": {
"dockerImageRepository": ""
}
},
{
"kind": "BuildConfig",
"apiVersion": "v1",
"metadata": {
"name": "node2",
"creationTimestamp": null
},
"spec": {
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange"
}
],
"runPolicy": "Serial",
"source": {
"type": "Git",
"git": {
"uri": "https://github.com/kubernetes-incubator/kompose.git",
"ref": "HEAD"
},
"contextDir": "script/test/fixtures/nginx-node-redis/node/"
},
"strategy": {
"type": "Docker",
"dockerStrategy": {}
},
"output": {
"to": {
"kind": "ImageStreamTag",
"name": "node2:latest"
}
},
"resources": {},
"postCommit": {},
"nodeSelector": null
},
"status": {
"lastVersion": 0
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "node3",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node3"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"node3"
],
"from": {
"kind": "ImageStreamTag",
"name": "node3:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "node3"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node3"
}
},
"spec": {
"containers": [
{
"name": "node3",
"image": " ",
"ports": [
{
"containerPort": 8080
}
],
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "node3",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node3"
}
},
"spec": {},
"status": {
"dockerImageRepository": ""
}
},
{
"kind": "BuildConfig",
"apiVersion": "v1",
"metadata": {
"name": "node3",
"creationTimestamp": null
},
"spec": {
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange"
}
],
"runPolicy": "Serial",
"source": {
"type": "Git",
"git": {
"uri": "https://github.com/kubernetes-incubator/kompose.git",
"ref": "HEAD"
},
"contextDir": "script/test/fixtures/nginx-node-redis/node/"
},
"strategy": {
"type": "Docker",
"dockerStrategy": {}
},
"output": {
"to": {
"kind": "ImageStreamTag",
"name": "node3:latest"
}
},
"resources": {},
"postCommit": {},
"nodeSelector": null
},
"status": {
"lastVersion": 0
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"redis"
],
"from": {
"kind": "ImageStreamTag",
"name": "redis:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "redis"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": " ",
"ports": [
{
"containerPort": 6379
}
],
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"tags": [
{
"name": "latest",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "redis"
},
"generation": null,
"importPolicy": {}
}
]
},
"status": {
"dockerImageRepository": ""
}
},
{ {
"kind": "DeploymentConfig", "kind": "DeploymentConfig",
"apiVersion": "v1", "apiVersion": "v1",
@ -564,8 +231,8 @@
"source": { "source": {
"type": "Git", "type": "Git",
"git": { "git": {
"uri": "https://github.com/kubernetes-incubator/kompose.git", "uri": "%URI%",
"ref": "HEAD" "ref": "%REF%"
}, },
"contextDir": "script/test/fixtures/nginx-node-redis/nginx/" "contextDir": "script/test/fixtures/nginx-node-redis/nginx/"
}, },
@ -685,8 +352,8 @@
"source": { "source": {
"type": "Git", "type": "Git",
"git": { "git": {
"uri": "https://github.com/kubernetes-incubator/kompose.git", "uri": "%URI%",
"ref": "HEAD" "ref": "%REF%"
}, },
"contextDir": "script/test/fixtures/nginx-node-redis/node/" "contextDir": "script/test/fixtures/nginx-node-redis/node/"
}, },
@ -707,6 +374,339 @@
"status": { "status": {
"lastVersion": 0 "lastVersion": 0
} }
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "node2",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node2"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"node2"
],
"from": {
"kind": "ImageStreamTag",
"name": "node2:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "node2"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node2"
}
},
"spec": {
"containers": [
{
"name": "node2",
"image": " ",
"ports": [
{
"containerPort": 8080
}
],
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "node2",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node2"
}
},
"spec": {},
"status": {
"dockerImageRepository": ""
}
},
{
"kind": "BuildConfig",
"apiVersion": "v1",
"metadata": {
"name": "node2",
"creationTimestamp": null
},
"spec": {
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange"
}
],
"runPolicy": "Serial",
"source": {
"type": "Git",
"git": {
"uri": "%URI%",
"ref": "%REF%"
},
"contextDir": "script/test/fixtures/nginx-node-redis/node/"
},
"strategy": {
"type": "Docker",
"dockerStrategy": {}
},
"output": {
"to": {
"kind": "ImageStreamTag",
"name": "node2:latest"
}
},
"resources": {},
"postCommit": {},
"nodeSelector": null
},
"status": {
"lastVersion": 0
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "node3",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node3"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"node3"
],
"from": {
"kind": "ImageStreamTag",
"name": "node3:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "node3"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node3"
}
},
"spec": {
"containers": [
{
"name": "node3",
"image": " ",
"ports": [
{
"containerPort": 8080
}
],
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "node3",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "node3"
}
},
"spec": {},
"status": {
"dockerImageRepository": ""
}
},
{
"kind": "BuildConfig",
"apiVersion": "v1",
"metadata": {
"name": "node3",
"creationTimestamp": null
},
"spec": {
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange"
}
],
"runPolicy": "Serial",
"source": {
"type": "Git",
"git": {
"uri": "%URI%",
"ref": "%REF%"
},
"contextDir": "script/test/fixtures/nginx-node-redis/node/"
},
"strategy": {
"type": "Docker",
"dockerStrategy": {}
},
"output": {
"to": {
"kind": "ImageStreamTag",
"name": "node3:latest"
}
},
"resources": {},
"postCommit": {},
"nodeSelector": null
},
"status": {
"lastVersion": 0
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"redis"
],
"from": {
"kind": "ImageStreamTag",
"name": "redis:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "redis"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": " ",
"ports": [
{
"containerPort": 6379
}
],
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"tags": [
{
"name": "latest",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "redis"
},
"generation": null,
"importPolicy": {}
}
]
},
"status": {
"dockerImageRepository": ""
}
} }
] ]
} }