diff --git a/.travis.yml b/.travis.yml index 342f0b93..410abaf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,14 @@ install: - true script: + - make validate + - make test-unit + + # make test-cmd requires kompose binary - make binary + # $GOPATH/bin is in $PATH - mkdir -p $GOPATH/bin - cp kompose $GOPATH/bin/ - - make test-unit - make test-cmd diff --git a/Makefile b/Makefile index a6ec7428..95e61ffd 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,14 @@ clean: test-unit: ./script/make.sh test-unit - test-cmd: ./script/make.sh test-cmd + +validate: gofmt vet + +vet: + ./script/make.sh validate-vet +lint: + ./script/make.sh validate-lint +gofmt: + ./script/make.sh validate-gofmt diff --git a/cli/app/app.go b/cli/app/app.go index 5c046b9b..773e527c 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -241,7 +241,7 @@ func getTransformer(opt kobject.ConvertOptions) transformer.Transformer { } else { // Create/Init new OpenShift object that is initialized with a newly // created Kubernetes object. Openshift inherits from Kubernetes - t = &openshift.OpenShift{kubernetes.Kubernetes{Opt: opt}} + t = &openshift.OpenShift{Kubernetes: kubernetes.Kubernetes{Opt: opt}} } return t } diff --git a/cli/app/app_test.go b/cli/app/app_test.go index 03518858..2308f6fb 100644 --- a/cli/app/app_test.go +++ b/cli/app/app_test.go @@ -106,16 +106,16 @@ func TestParseVolume(t *testing.T) { t.Errorf("In test case %q, returned unexpected error %v", test.test, err) } if name != test.name { - t.Errorf("In test case %q, returned volume name %s, expected %s", name, test.name) + t.Errorf("In test case %q, returned volume name %s, expected %s", test.test, name, test.name) } if host != test.host { - t.Errorf("In test case %q, returned host path %s, expected %s", host, test.host) + t.Errorf("In test case %q, returned host path %s, expected %s", test.test, host, test.host) } if container != test.container { - t.Errorf("In test case %q, returned container path %s, expected %s", container, test.container) + t.Errorf("In test case %q, returned container path %s, expected %s", test.test, container, test.container) } if mode != test.mode { - t.Errorf("In test case %q, returned access mode %s, expected %s", mode, test.mode) + t.Errorf("In test case %q, returned access mode %s, expected %s", test.test, mode, test.mode) } } } diff --git a/pkg/loader/bundle/bundle.go b/pkg/loader/bundle/bundle.go index 80202133..2459f563 100644 --- a/pkg/loader/bundle/bundle.go +++ b/pkg/loader/bundle/bundle.go @@ -133,12 +133,12 @@ func (b *Bundle) LoadFile(file string) kobject.KomposeObject { buf, err := ioutil.ReadFile(file) if err != nil { - logrus.Fatalf("Failed to read bundles file: ", err) + logrus.Fatalf("Failed to read bundles file: %s ", err) } reader := strings.NewReader(string(buf)) bundle, err := loadFile(reader) if err != nil { - logrus.Fatalf("Failed to parse bundles file: ", err) + logrus.Fatalf("Failed to parse bundles file: %s", err) } for name, service := range bundle.Services { diff --git a/pkg/transformer/kubernetes/k8sutils.go b/pkg/transformer/kubernetes/k8sutils.go index 2580c560..bce4bade 100644 --- a/pkg/transformer/kubernetes/k8sutils.go +++ b/pkg/transformer/kubernetes/k8sutils.go @@ -245,6 +245,7 @@ func (k *Kubernetes) CreateService(name string, service kobject.ServiceConfig, o svc.Spec.Ports = servicePorts svc.Spec.Type = api.ServiceType(service.ServiceType) + // Configure annotations annotations := transformer.ConfigAnnotations(service) svc.ObjectMeta.Annotations = annotations diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index df99c3f9..91effe17 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -382,7 +382,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con if !opt.EmptyVols { pvcStr = " and PersistentVolumeClaims " } - fmt.Println("We are going to create Kubernetes Deployments, Services" +pvcStr+ "for your Dockerized application. \n" + + fmt.Println("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. \n" + "If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead. \n") factory := cmdutil.NewFactory(nil) @@ -424,7 +424,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con } else { pvcStr = "" } - fmt.Println("\nYour application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods" +pvcStr+ "' for details.") + fmt.Println("\nYour application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods" + pvcStr + "' for details.") return nil } diff --git a/pkg/transformer/openshift/openshift.go b/pkg/transformer/openshift/openshift.go index 1319a063..2b3e6a80 100644 --- a/pkg/transformer/openshift/openshift.go +++ b/pkg/transformer/openshift/openshift.go @@ -178,7 +178,7 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv if !opt.EmptyVols { pvcStr = " and PersistentVolumeClaims " } - fmt.Println("We are going to create OpenShift DeploymentConfigs, Services" +pvcStr+ "for your Dockerized application. \n" + + fmt.Println("We are going to create OpenShift DeploymentConfigs, Services" + pvcStr + "for your Dockerized application. \n" + "If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead. \n") // initialize OpenShift Client @@ -238,7 +238,7 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv } else { pvcStr = "" } - fmt.Println("\nYour application has been deployed to OpenShift. You can run 'oc get dc,svc,is" +pvcStr+ "' for details.") + fmt.Println("\nYour application has been deployed to OpenShift. You can run 'oc get dc,svc,is" + pvcStr + "' for details.") return nil } diff --git a/script/.validate b/script/.validate index 319052e5..6730c9ab 100644 --- a/script/.validate +++ b/script/.validate @@ -14,34 +14,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ -z "$VALIDATE_UPSTREAM" ]; then - # this is kind of an expensive check, so let's not do this twice if we - # are running more than one validate bundlescript - - VALIDATE_REPO='https://github.com/kubernetes-incubator/kompose.git' - VALIDATE_BRANCH='master' - - if [ "$TRAVIS" = 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then - VALIDATE_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git" - VALIDATE_BRANCH="${TRAVIS_BRANCH}" - fi - - VALIDATE_HEAD="$(git rev-parse --verify HEAD)" - - git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" - VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" - - VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD" - VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD" - - validate_diff() { - if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then - git diff "$VALIDATE_COMMIT_DIFF" "$@" - fi - } - validate_log() { - if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then - git log "$VALIDATE_COMMIT_LOG" "$@" - fi - } -fi +# all Kompose packages (skip vendor dir) +PKGS=$( go list -e ./... | grep -v '/vendor/' ) diff --git a/script/make.sh b/script/make.sh index fdfc6200..efd3c6ca 100755 --- a/script/make.sh +++ b/script/make.sh @@ -25,10 +25,6 @@ DEFAULT_BUNDLES=( validate-lint validate-vet binary - - # test-unit - # test-integration - # test-acceptance ) bundle() { local bundle="$1"; shift diff --git a/script/validate-gofmt b/script/validate-gofmt index 0c4de39e..4455fc36 100755 --- a/script/validate-gofmt +++ b/script/validate-gofmt @@ -16,29 +16,24 @@ source "$(dirname "$BASH_SOURCE")/.validate" -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) ) -unset IFS +GO_FILES=$(find . -path ./vendor -prune -o -name '*.go' -print ) -badFiles=() -for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed is formatted - if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then - badFiles+=( "$f" ) + +for file in $GO_FILES; do + gofmtOutput=$(gofmt -l "$file") + if [ "$gofmtOutput" ]; then + errors+=("$gofmtOutput") fi -done +done -if [ ${#badFiles[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files are properly formatted.' + + +if [ ${#errors[@]} -eq 0 ]; then + echo "gofmt OK" else - { - echo "These files are not properly gofmt'd:" - for f in "${badFiles[@]}"; do - echo " - $f" - done - echo - echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' - echo - } >&2 - false -fi + echo "gofmt ERROR - These files are not formated by gofmt:" + for err in "${errors[@]}"; do + echo "$err" + done + exit 1 +fi \ No newline at end of file diff --git a/script/validate-lint b/script/validate-lint index fbd11427..f22ddbc3 100755 --- a/script/validate-lint +++ b/script/validate-lint @@ -1,4 +1,5 @@ #!/bin/bash +set -e # Copyright 2016 The Kubernetes Authors All rights reserved. # @@ -16,33 +17,21 @@ source "$(dirname "$BASH_SOURCE")/.validate" -# We will eventually get to the point where packages should be the complete list -# of subpackages, vendoring excluded, as given by: -# -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/\|^integration' || true) ) -unset IFS - -errors=() -for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed passes go lint - failedLint=$(golint "$f") - if [ "$failedLint" ]; then - errors+=( "$failedLint" ) +for pkg in $PKGS; do + lintOutput=$(golint "$pkg") + # if lineOutput is not empty, save it to errros array + if [ "$lintOutput" ]; then + errors+=("$lintOutput") fi -done +done + if [ ${#errors[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files have been linted.' + echo "golint OK" else - { - echo "Errors from golint:" - for err in "${errors[@]}"; do - echo "$err" - done - echo - echo 'Please fix the above errors. You can test via "golint" and commit the result.' - echo - } >&2 - false -fi + echo "golint ERRORS:" + for err in "${errors[@]}"; do + echo "$err" + done + exit 1 +fi \ No newline at end of file diff --git a/script/validate-vet b/script/validate-vet index d5586084..0625823a 100755 --- a/script/validate-vet +++ b/script/validate-vet @@ -1,4 +1,5 @@ #!/bin/bash +set -e # Copyright 2016 The Kubernetes Authors All rights reserved. # @@ -16,31 +17,5 @@ source "$(dirname "$BASH_SOURCE")/.validate" -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) ) -unset IFS - -errors=() -for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed passes go vet - failedVet=$(go vet "$f") - if [ "$failedVet" ]; then - errors+=( "$failedVet" ) - fi -done - - -if [ ${#errors[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files have been vetted.' -else - { - echo "Errors from go vet:" - for err in "${errors[@]}"; do - echo " - $err" - done - echo - echo 'Please fix the above errors. You can test via "go vet" and commit the result.' - echo - } >&2 - false -fi +go vet $PKGS; + \ No newline at end of file