From e7cac07c748e4e4e8dfd0f7e392e79269486c429 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Tue, 24 Oct 2017 16:05:55 -0700 Subject: [PATCH] Add travis CICD coverage. Also, rename "kexpand" to "kinflate" to ease pronunciation. --- .travis.yml | 17 +++++++++++++ bin/pre-commit.sh | 37 +++++++++++++++++++++++++++++ cmd/{kexpand => kinflate}/README.md | 6 ++--- cmd/{kexpand => kinflate}/main.go | 8 ++++++- cmd/kinflate/main_test.go | 32 +++++++++++++++++++++++++ pkg/apis/manifest/v1alpha1/types.go | 8 +++---- pkg/{kexpand => kinflate}/util.go | 0 7 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 .travis.yml create mode 100755 bin/pre-commit.sh rename cmd/{kexpand => kinflate}/README.md (89%) rename cmd/{kexpand => kinflate}/main.go (85%) create mode 100644 cmd/kinflate/main_test.go rename pkg/{kexpand => kinflate}/util.go (100%) diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..675c4ac9c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: go + +go: + - 1.9.x + +go_import_path: k8s.io/kubectl + +before_install: + - go get -u github.com/golang/lint/golint + - go get -u golang.org/x/tools/cmd/goimports + +script: + - ./bin/pre-commit.sh + +# TBD, suppressing for now. +notifications: + email: false diff --git a/bin/pre-commit.sh b/bin/pre-commit.sh new file mode 100755 index 000000000..33731b0bf --- /dev/null +++ b/bin/pre-commit.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +if [ -n "$failIt" ]; then + echo "Expecting failIt to be empty." + exit 1 +fi + +tmp=$(gofmt -s -d -l . 2>&1 ) +if [ -n "$tmp" ]; then + printf >&2 'gofmt failed for:\n%s\n' "$tmp" + failIt=1 +fi + +tmp=$(goimports -l .) +if [ -n "$tmp" ]; then + printf >&2 'goimports failed for:\n%s\n' "$tmp" + failIt=1 +fi + +tmp=$(go vet -all ./... 2>&1) +if [ -n "$tmp" ]; then + printf >&2 'govet failed for:\n%s\n' "$tmp" + failIt=1 +fi + +tmp=$(golint ./...) +if [ -n "$tmp" ]; then + printf >&2 'golint failed for:\n%s\n' "$tmp" + failIt=1 +fi + +if [ -n "$failIt" ]; then + unset failIt + exit 1 +fi + +go test -v ./... diff --git a/cmd/kexpand/README.md b/cmd/kinflate/README.md similarity index 89% rename from cmd/kexpand/README.md rename to cmd/kinflate/README.md index 50abe2aa3..53c24e97e 100644 --- a/cmd/kexpand/README.md +++ b/cmd/kinflate/README.md @@ -1,8 +1,8 @@ -# kexpand +# kinflate _TODO: flesh out this placeholder documentation_ -`kexpand` is a kubernetes cluster configuration utility, +`kinflate` is a kubernetes cluster configuration utility, a prototype of ideas discussed in [this doc][DAM]. It accepts one or more file system path arguments, @@ -29,7 +29,7 @@ For example, if your current working directory contained then the command ``` -kexpand ./mycluster/instances | kubectl apply -f - +kinflate ./mycluster/instances | kubectl apply -f - ``` would modify your cluster per the resources generated from the manifests and associated diff --git a/cmd/kexpand/main.go b/cmd/kinflate/main.go similarity index 85% rename from cmd/kexpand/main.go rename to cmd/kinflate/main.go index c70601a4b..1bd51ced2 100644 --- a/cmd/kexpand/main.go +++ b/cmd/kinflate/main.go @@ -20,6 +20,12 @@ import ( "fmt" ) -func main() { +// TestableMain allows test coverage for main. +func TestableMain() error { fmt.Println("Hello world.") + return nil +} + +func main() { + TestableMain() } diff --git a/cmd/kinflate/main_test.go b/cmd/kinflate/main_test.go new file mode 100644 index 000000000..31b2df67e --- /dev/null +++ b/cmd/kinflate/main_test.go @@ -0,0 +1,32 @@ +/* +Copyright 2017 The Kubernetes Authors. + +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. +*/ + +package main + +import ( + "testing" +) + +// TODO: real tests +// e.g. make an inmemory file system, put yaml in there, inflate it +// to a buffer, compare to expected results, etc. +// a script in there, have script write file +func TestTrueMain(t *testing.T) { + err := TestableMain() + if err != nil { + t.Errorf("Unexpected error: %v", err) + } +} diff --git a/pkg/apis/manifest/v1alpha1/types.go b/pkg/apis/manifest/v1alpha1/types.go index 0daf88f62..49e086f66 100644 --- a/pkg/apis/manifest/v1alpha1/types.go +++ b/pkg/apis/manifest/v1alpha1/types.go @@ -98,14 +98,14 @@ type Manifest struct { // If a secret want to have a base and an overlay, it should go to Bases and Overlays fields. Secrets []Secret `json:"secrets,omitempty" yaml:"secrets,omitempty"` - // Whether prune resources not defined in Kube-manifest.yaml, similar to `kubectl apply --prune` behavior. + // Whether prune resources not defined in Kube-manifest.yaml, similar to `kubectl apply --prune` behavior. Prune bool `json:"prune,omitempty" yaml:"prune,omitempty"` - // TODO: figure out what the behavior details should be. + // TODO: figure out what the behavior details should be. // Whether PersistentVolumeClaims should be deleted with the other resources. // OwnPersistentVolumeClaims bool `json:"ownPersistentVolumeClaims,omitempty" yaml:"ownPersistentVolumeClaims,omitempty"` - // TODO: figure out what the behavior details should be. + // TODO: figure out what the behavior details should be. // Whether recursive look for Kube-manifest.yaml, similar to `kubectl --recursive` behavior. // Recursive bool `json:"recursive,omitempty" yaml:"recursive,omitempty"` } @@ -139,7 +139,7 @@ type Secret struct { // TLS secret. TLS TLS `json:"tls,omitempty" yaml:"tls,omitempty"` - // TODO: support more secret types, e.g. DockerRegistry + // TODO: support more secret types, e.g. DockerRegistry } // Generic contains some generic sources for configmap or secret. diff --git a/pkg/kexpand/util.go b/pkg/kinflate/util.go similarity index 100% rename from pkg/kexpand/util.go rename to pkg/kinflate/util.go