Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Strip out all kubecfg-specific bits that we don't want in the shared library #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
138 changes: 3 additions & 135 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,151 +1,19 @@
language: go

go:
- 1.9.x
- 1.8.x

os:
- linux

env:
global:
- PATH=$PATH:$GOPATH/bin
- VERSION="${TRAVIS_TAG:-build-$TRAVIS_BUILD_ID}"
- EXTRA_GO_FLAGS_TEST="-race"
- MINIKUBE_WANTUPDATENOTIFICATION=false
- MINIKUBE_WANTREPORTERRORPROMPT=false
- MINIKUBE_HOME=${HOME}
- CHANGE_MINIKUBE_NONE_USER=true

# Frequent jsonnet_cgo crashes with xcode7.3 (default)
osx_image: xcode8.3

matrix:
include:
- env: TARGET=x86_64-linux-musl EXTRA_GO_FLAGS_TEST=""
go: 1.8.x
- env: DO_INTEGRATION_TEST=1 INT_KVERS=v1.7.0
# cgo requires golang >= 1.8.1 (or other workarounds) on recent
# osx/xcode - see https://github.com/golang/go/issues/19734
# 'go test' also hangs repeatably on go-1.8.3/MacOS ?
- os: osx
go: 1.8.x
fast_finish: true
allow_failures:
# Let us know if/when 'go test' works again on MacOS..
- os: osx
go: 1.8.x

services:
- docker

addons:
apt:
packages:
# Most of these are musl-cross dependencies
- wget
- patch
- git-core
- gcc
- g++
- make
- gawk
- bzip2
- gzip
- xz-utils
- ca-certificates
- libgmp-dev
- libmpfr-dev
- libmpc-dev

before_install:
- set -e
- |
if [ -n "$TARGET" -a ! -d "$HOME/cross/$TARGET/bin" ]; then
pushd /tmp
git clone --depth=1 https://github.com/GregorR/musl-cross.git
cd musl-cross
echo CC_BASE_PREFIX=$HOME/cross >> ./config.sh
if ! ./build.sh > build.log; then
tail -100 build.log
exit 1
fi
popd
fi
- |
if [ -n "$TARGET" ]; then
PATH=$PATH:$HOME/cross/$TARGET/bin
export CC="$TARGET-gcc"
export CXX="$TARGET-g++"
export GO_LDFLAGS='-linkmode external -extldflags=-static'
fi

install:
- go build -i -ldflags "$GO_LDFLAGS" .
- |
if [ "$DO_INTEGRATION_TEST" = 1 ]; then
if ! which minikube; then
wget -O minikube \
https://storage.googleapis.com/minikube/releases/v0.21.0/minikube-$(go env GOOS)-$(go env GOARCH)
install -m 755 minikube $GOPATH/bin/minikube
fi
if ! which kubectl; then
wget https://storage.googleapis.com/kubernetes-release/release/$INT_KVERS/bin/$(go env GOOS)/$(go env GOARCH)/kubectl
install -m 755 kubectl $GOPATH/bin/kubectl
fi
mkdir -p $HOME/.kube
touch $HOME/.kube/config
sudo -E $GOPATH/bin/minikube start --vm-driver=none \
--extra-config apiserver.Authorization.Mode=RBAC \
--kubernetes-version $INT_KVERS

go get github.com/onsi/ginkgo/ginkgo
fi
- go build -i ./...

script:
- make VERSION="$VERSION" EXTRA_GO_FLAGS="$EXTRA_GO_FLAGS_TEST" test
- make GO_FLAGS="-race" test
- make vet
- rm -f ./kubecfg && make VERSION="$VERSION"
- >
ldd ./kubecfg || otool -L ./kubecfg || :
- ./kubecfg help
- ./kubecfg version
- |
if [ "$DO_INTEGRATION_TEST" = 1 ]; then
minikube update-context
minikube status
make VERSION="$VERSION" EXTRA_GO_FLAGS="$EXTRA_GO_FLAGS_TEST" integrationtest
fi

after_script: set +e

before_deploy:
- echo TARGET=$TARGET OS_NAME=$TRAVIS_OS_NAME GO_VERSION=$TRAVIS_GO_VERSION
- EXE_NAME=kubecfg-$(go env GOOS)-$(go env GOARCH)
- cp kubecfg $EXE_NAME
- strip $EXE_NAME && ./$EXE_NAME version
- >
size $EXE_NAME || :

deploy:
api_key:
secure: "T/LpWZSgeqWBgY3mUNeej55n8TbZZM7UgrHl7pej1CE2cs6YGcfyog3peiXvCcVF9NhGsm6eTXZQeFxsuWgMbWYeqlBnMkHNPPqdNpeRFgY0TkFZXHZLexfqTo2MLgrZiJ+bZl8wZnTTXukieGeLE37ugkBJyceLyfqIaxwRlpDzKPn8XtIqOMOwMq0aeUA8wjSSpuWkuwlGWKwJtI48BNExZZ1FRpPHQdAZjX6zEPT2SuRaACZdoX+3k/Fr91H6O9TplE4q5eCpEdd3y7BGGtMm3WA70SxYIZPGzfwaALGja5BapZr9Eui6ppyPGesQ8zV+zNtOsnK5Phj3QUj8M+v4BmJbxbPyhAIWmFiDlutgwZUkXI+R+SXONy1/LTuLLNSJ9WPQsC9gL09FGQmg+X0s7VpJVWxD8FScY0DJ4/bNLgeWnzwT2YTsduDktqevMpetxJWZGVQx3EN595JJKlZGtE8PouzVm7sRQEfe3Jd0XIcPfj5AV5trEBDjgHZSnU4qa9G9RdUZfswVp+R7SEwoTwEIEyOpFAwi9Qg5wkCAZFU2+86LQOLYH0Pm38//RxSXJEF1abkEb0Y/awz6KKlGBK3z1VSXvK3LQ8r9SwF2h15rD74O1mGM8Mjbs+mJXPxKpCq+BslskRYur3F8tRx45pwr8Ly9dppZd2rrswI="
file: $EXE_NAME
on:
condition: ( $TARGET = x86_64-linux-musl || $TRAVIS_OS_NAME = osx ) && ${TRAVIS_GO_VERSION}.0 =~ ^1\.8\.
tags: true
provider: releases
skip_cleanup: true

cache:
directories:
- $GOPATH/pkg
- $HOME/cross

branches:
only:
- master
# release tags
- /^v\d+\.\d+\.\d+.*$/

notifications:
email:
Expand Down
31 changes: 4 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,23 @@
VERSION = dev-$(shell date +%FT%T%z)

GO = go
EXTRA_GO_FLAGS =
GO_FLAGS = -ldflags="-X main.version=$(VERSION) $(GO_LDFLAGS)" $(EXTRA_GO_FLAGS)
GOFMT = gofmt
# GINKGO = "go test" also works if you want to avoid ginkgo tool
GINKGO = ginkgo

KCFG_TEST_FILE = lib/kubecfg_test.jsonnet
GUESTBOOK_FILE = examples/guestbook.jsonnet
JSONNET_FILES = $(KCFG_TEST_FILE) $(GUESTBOOK_FILE)
# TODO: Simplify this once ./... ignores ./vendor
GO_PACKAGES = ./cmd/... ./utils/... ./pkg/... ./metadata/... ./prototype/...
# TODO: Simplify this once ./... ignores ./vendor (go1.9)
GO_PACKAGES = ./utils/... ./pkg/... ./metadata/... ./prototype/...

# Default cluster from this config is used for integration tests
KUBECONFIG = $(HOME)/.kube/config

all: kubecfg

kubecfg:
$(GO) build $(GO_FLAGS) .

test: gotest jsonnettest
test: gotest

gotest:
$(GO) test $(GO_FLAGS) $(GO_PACKAGES)

jsonnettest: kubecfg $(JSONNET_FILES)
# TODO: use `kubecfg check` once implemented
./kubecfg -J lib show -f $(KCFG_TEST_FILE) -f $(GUESTBOOK_FILE) >/dev/null

integrationtest: kubecfg
$(GINKGO) -tags 'integration' integration -- -kubeconfig $(KUBECONFIG) -kubecfg-bin $(abspath $<)

vet:
$(GO) vet $(GO_FLAGS) $(GO_PACKAGES)

fmt:
$(GOFMT) -s -w $(shell $(GO) list -f '{{.Dir}}' $(GO_PACKAGES))

clean:
$(RM) ./kubecfg
# nothing to do?

.PHONY: all test clean vet fmt
.PHONY: kubecfg
88 changes: 2 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,3 @@
# kubecfg
# Common ksonnet golang library

[![Build Status](https://travis-ci.org/ksonnet/kubecfg.svg?branch=master)](https://travis-ci.org/ksonnet/kubecfg)
[![Go Report Card](https://goreportcard.com/badge/github.com/ksonnet/kubecfg)](https://goreportcard.com/report/github.com/ksonnet/kubecfg)

A tool for managing Kubernetes resources as code.

`kubecfg` allows you to express the patterns across your
infrastructure and reuse these powerful "templates" across many
services, and then manage those templates as files in version control.
The more complex your infrastructure is, the more you will gain from
using kubecfg.

Status: Basic functionality works, and the tool is usable. The focus
now is on clearer error reporting and advanced features.

Yes, Google employees will recognise this as being very similar to a
similarly-named internal tool ;)

## Install

Pre-compiled executables exist for some platforms on
the [Github releases](https://github.com/ksonnet/kubecfg/releases)
page.

To build from source:

```console
% PATH=$PATH:$GOPATH/bin
% go get github.com/ksonnet/kubecfg
```

Requires golang >=1.7 and a functional cgo environment (C++ with libstdc++).
Note that recent OSX environments
[require golang >=1.8.1](https://github.com/golang/go/issues/19734) to
avoid an immediate `Killed: 9`.

## Quickstart

```console
# Include <kubecfg.git>/lib in kubecfg/jsonnet library search path.
# Can also use explicit `-J` args everywhere.
% export KUBECFG_JPATH=/path/to/kubecfg/lib

# Show generated YAML
% kubecfg show -o yaml -f examples/guestbook.jsonnet

# Create resources
% kubecfg apply -f examples/guestbook.jsonnet

# Modify configuration (downgrade gb-frontend image)
% sed -i.bak '\,gcr.io/google-samples/gb-frontend,s/:v4/:v3/' examples/guestbook.jsonnet
# See differences vs server
% kubecfg diff -f examples/guestbook.jsonnet

# Update to new config
% kubecfg apply -f examples/guestbook.jsonnet

# Clean up after demo
% kubecfg delete -f examples/guestbook.jsonnet
```

## Features

- Supports JSON, YAML or jsonnet files (by file suffix).
- Best-effort sorts objects before updating, so that dependencies are
pushed to the server before objects that refer to them.
- Additional jsonnet builtin functions. See `lib/kubecfg.libsonnet`.

## Infrastructure-as-code Philosophy

The idea is to describe *as much as possible* about your configuration
as files in version control (eg: git).

Changes to the configuration follow a regular review, approve, merge,
etc code change workflow (github pull-requests, phabricator diffs,
etc). At any point, the config in version control captures the entire
desired-state, so the system can be easily recreated in a QA cluster
or to recover from disaster.

### Jsonnet

Kubecfg relies heavily on [jsonnet](http://jsonnet.org/) to describe
Kubernetes resources, and is really just a thin Kubernetes-specific
wrapper around jsonnet evaluation. You should read the jsonnet
[tutorial](http://jsonnet.org/docs/tutorial.html), and skim the functions available in the jsonnet [`std`](http://jsonnet.org/docs/stdlib.html)
library.
... as used by other ksonnet projects
Loading