diff --git a/.travis.yml b/.travis.yml index f9c9ccdda7ead6ae5054e5e593b8686179948e02..ac7720436444067e42f0fa2322487fd8d321fb07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,11 +104,11 @@ install: script: - make VERSION="$VERSION" EXTRA_GO_FLAGS="$EXTRA_GO_FLAGS_TEST" test - make vet - - rm -f ./kubecfg && make VERSION="$VERSION" + - rm -f ./ks && make VERSION="$VERSION" - > - ldd ./kubecfg || otool -L ./kubecfg || : - - ./kubecfg help - - ./kubecfg version + ldd ./ks || otool -L ./ks || : + - ./ks help + - ./ks version - | if [ "$DO_INTEGRATION_TEST" = 1 ]; then minikube update-context @@ -120,8 +120,8 @@ 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 + - EXE_NAME=ks-$(go env GOOS)-$(go env GOARCH) + - cp ks $EXE_NAME - strip $EXE_NAME && ./$EXE_NAME version - > size $EXE_NAME || : diff --git a/Makefile b/Makefile index 13eeab633e564a1c897704a443c3eac30036830f..dd5c99a4fde29b9d4f4491a4ceddbaf4d702c474 100644 --- a/Makefile +++ b/Makefile @@ -31,21 +31,21 @@ GO_PACKAGES = ./cmd/... ./utils/... ./pkg/... ./metadata/... ./prototype/... # Default cluster from this config is used for integration tests KUBECONFIG = $(HOME)/.kube/config -all: kubecfg +all: ks -kubecfg: - $(GO) build $(GO_FLAGS) . +ks: + $(GO) build -o ks $(GO_FLAGS) . test: gotest jsonnettest 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 +jsonnettest: ks $(JSONNET_FILES) +# TODO: use `ks check` once implemented + ./ks -J lib show -f $(KCFG_TEST_FILE) -f $(GUESTBOOK_FILE) >/dev/null -integrationtest: kubecfg +integrationtest: ks $(GINKGO) -tags 'integration' integration -- -kubeconfig $(KUBECONFIG) -kubecfg-bin $(abspath $<) vet: @@ -55,7 +55,7 @@ fmt: $(GOFMT) -s -w $(shell $(GO) list -f '{{.Dir}}' $(GO_PACKAGES)) clean: - $(RM) ./kubecfg + $(RM) ./ks .PHONY: all test clean vet fmt -.PHONY: kubecfg +.PHONY: ks diff --git a/README.md b/README.md index e21c9ac29cf9740886c67c49e0b044f34541e104..32d67faf28133739b6f689172f12ac410617d3b5 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# kubecfg +# ksonnet -[](https://travis-ci.org/ksonnet/kubecfg) -[](https://goreportcard.com/report/github.com/ksonnet/kubecfg) +[](https://travis-ci.org/ksonnet/ksonnet) +[](https://goreportcard.com/report/github.com/ksonnet/ksonnet) A tool for managing Kubernetes resources as code. -`kubecfg` allows you to express the patterns across your +`ksonnet` 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 @@ -14,20 +14,17 @@ 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) +the [Github releases](https://github.com/ksonnet/ksonnet/releases) page. To build from source: ```console % PATH=$PATH:$GOPATH/bin -% go get github.com/ksonnet/kubecfg +% go get github.com/ksonnet/ksonnet ``` Requires golang >=1.7 and a functional cgo environment (C++ with libstdc++). @@ -38,26 +35,26 @@ avoid an immediate `Killed: 9`. ## Quickstart ```console -# Include <kubecfg.git>/lib in kubecfg/jsonnet library search path. +# Include <ksonnet.git>/lib in ksonnet/jsonnet library search path. # Can also use explicit `-J` args everywhere. -% export KUBECFG_JPATH=/path/to/kubecfg/lib +% export KUBECFG_JPATH=/path/to/ksonnet/lib # Show generated YAML -% kubecfg show -o yaml -f examples/guestbook.jsonnet +% ks show -o yaml -f examples/guestbook.jsonnet # Create resources -% kubecfg apply -f examples/guestbook.jsonnet +% ks 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 +% ks diff -f examples/guestbook.jsonnet # Update to new config -% kubecfg apply -f examples/guestbook.jsonnet +% ks apply -f examples/guestbook.jsonnet # Clean up after demo -% kubecfg delete -f examples/guestbook.jsonnet +% ks delete -f examples/guestbook.jsonnet ``` ## Features @@ -80,7 +77,7 @@ or to recover from disaster. ### Jsonnet -Kubecfg relies heavily on [jsonnet](http://jsonnet.org/) to describe +ksonnet 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) diff --git a/cmd/apply.go b/cmd/apply.go index 3d8542ff305e040c010f9cc200123dbc1d7cb27c..6dcc85df38ae58a9c33de35ad3bb8daaaa358fe2 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -129,20 +129,20 @@ files.`, Example: ` # Create or update all resources described in a ksonnet application, and # running in the 'dev' environment. Can be used in any subdirectory of the # application. - ksonnet apply dev + ks apply dev # Create or update resources described in a YAML file. Automatically picks up # the cluster's location from '$KUBECONFIG'. - ksonnet appy -f ./pod.yaml + ks appy -f ./pod.yaml # Create or update resources described in the JSON file. Changes are deployed # to the cluster pointed at the 'dev' environment. - ksonnet apply dev -f ./pod.json + ks apply dev -f ./pod.json # Update resources described in a YAML file, and running in cluster referred # to by './kubeconfig'. - ksonnet apply --kubeconfig=./kubeconfig -f ./pod.yaml + ks apply --kubeconfig=./kubeconfig -f ./pod.yaml # Display set of actions we will execute when we run 'apply'. - ksonnet apply dev --dry-run`, + ks apply dev --dry-run`, } diff --git a/cmd/delete.go b/cmd/delete.go index f736f3afc24b7d977f82ff295211e343470b16c3..6e5968baeddb68c37787ff40b3c2bd13b96b0c67 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -90,17 +90,17 @@ ksonnet applications are accepted, as well as normal JSON, YAML, and Jsonnet files.`, Example: ` # Delete all resources described in a ksonnet application, from the 'dev' # environment. Can be used in any subdirectory of the application. - ksonnet delete dev + ks delete dev # Delete resources described in a YAML file. Automatically picks up the # cluster's location from '$KUBECONFIG'. - ksonnet delete -f ./pod.yaml + ks delete -f ./pod.yaml # Delete resources described in the JSON file from the 'dev' environment. Can # be used in any subdirectory of the application. - ksonnet delete dev -f ./pod.json + ks delete dev -f ./pod.json # Delete resources described in a YAML file, and running in the cluster # specified by the current context in specified kubeconfig file. - ksonnet delete --kubeconfig=./kubeconfig -f ./pod.yaml`, + ks delete --kubeconfig=./kubeconfig -f ./pod.yaml`, } diff --git a/cmd/diff.go b/cmd/diff.go index 57f96dfef1bc56910d9ec6a2d093ad28ced2d28c..f719bfb119630cd0c0b63f3b41beac78771d39ff 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -88,17 +88,17 @@ files.`, Example: ` # Show diff between resources described in a local ksonnet application and # the cluster referenced by the 'dev' environment. Can be used in any # subdirectory of the application. - ksonnet diff dev + ks diff dev # Show diff between resources described in a YAML file and the cluster # referenced in '$KUBECONFIG'. - ksonnet diff -f ./pod.yaml + ks diff -f ./pod.yaml # Show diff between resources described in a JSON file and the cluster # referenced by the environment 'dev'. - ksonnet diff dev -f ./pod.json + ks diff dev -f ./pod.json # Show diff between resources described in a YAML file and the cluster # referred to by './kubeconfig'. - ksonnet diff --kubeconfig=./kubeconfig -f ./pod.yaml`, + ks diff --kubeconfig=./kubeconfig -f ./pod.yaml`, } diff --git a/cmd/env.go b/cmd/env.go index 179de78364fd649ffbb8af97c80adb13e7f3b6e2..8c9b06bfd394529835bd6719e322009c8d136ceb 100644 --- a/cmd/env.go +++ b/cmd/env.go @@ -58,7 +58,7 @@ var envCmd = &cobra.Command{ Use: "env", Short: `Manage ksonnet environments`, Long: `An environment acts as a sort of "named cluster", allowing for commands like -'ksonnet apply dev', which applies the ksonnet application to the "dev cluster". +'ks apply dev', which applies the ksonnet application to the "dev cluster". Additionally, environments allow users to cache data about the cluster it points to, including data needed to run 'verify', and a version of ksonnet-lib that is generated based on the flags the API server was started with (e.g., RBAC enabled @@ -135,7 +135,7 @@ var envAddCmd = &cobra.Command{ include punctuation, so names like '../foo' are not allowed. An environment acts as a sort of "named cluster", allowing for commands like -'ksonnet apply dev', which applies the ksonnet application to the "dev cluster". +'ks apply dev', which applies the ksonnet application to the "dev cluster". For more information on what an environment is and how they work, run 'help env'. @@ -157,17 +157,17 @@ environments/ swagger.json spec.json [This will contain the uri of the environment]`, Example: ` # Initialize a new staging environment at 'us-west'. Using the - # namespace 'my-namespace'. The directory structure rooted at 'us-west' in the - # documentation above will be generated. - ksonnet env add us-west/staging https://kubecfg-1.us-west.elb.amazonaws.com --namespace my-namespace + # namespace 'my-namespace'. The directory structure rooted at 'us-west' in the + # documentation above will be generated. + ks env add us-west/staging https://ksonnet-1.us-west.elb.amazonaws.com # Initialize a new staging environment at us-west, using the OpenAPI specification # generated in the Kubernetes v1.7.1 build to generate 'ksonnet-lib'. - ksonnet env add us-west/staging https://kubecfg-1.us-west.elb.amazonaws.com --api-spec=version:v1.7.1 + ks env add us-west/staging https://ksonnet-1.us-west.elb.amazonaws.com --api-spec=version:v1.7.1 # Initialize a new development environment locally. This will overwrite the # default 'default' directory structure generated by 'ksonnet-init'. - ksonnet env add default localhost:8000`, + ks env add default localhost:8000`, } var envRmCmd = &cobra.Command{ @@ -207,7 +207,7 @@ parent directories are subsequently deleted.`, Example: ` # Remove the directory 'us-west/staging' and all contents # in the 'environments' directory. This will also remove the parent directory # 'us-west' if it is empty. - ksonnet env rm us-west/staging`, + ks env rm us-west/staging`, } var envListCmd = &cobra.Command{ @@ -287,12 +287,12 @@ var envSetCmd = &cobra.Command{ the name of an environment will also update the directory structure in 'environments'.`, Example: ` # Updates the URI of the environment 'us-west/staging'. - ksonnet env set us-west/staging --uri=http://example.com + ks env set us-west/staging --uri=http://example.com # Updates the namespace of the environment 'us-west/staging'. - ksonnet env set us-west/staging --namespace=staging + ks env set us-west/staging --namespace=staging # Updates both the name and the URI of the environment 'us-west/staging'. # Updating the name will update the directory structure in 'environments' - ksonnet env set us-west/staging --uri=http://example.com --name=us-east/staging`, + ks env set us-west/staging --uri=http://example.com --name=us-east/staging`, } diff --git a/cmd/init.go b/cmd/init.go index c0bf200a7aaf17fac7ee78a1e5fae78a87f14e91..9e4e8da102911db4eff427b4cc6e4fb0215e28eb 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -115,13 +115,13 @@ consists of two steps: Example: ` # Initialize ksonnet application, using the capabilities of live cluster # specified in the $KUBECONFIG environment variable (specifically: the # current context) to generate 'ksonnet-lib'. - ksonnet init app-name + ks init app-name # Initialize ksonnet application, using the OpenAPI specification generated # in the Kubenetes v1.7.1 build to generate 'ksonnet-lib'. - ksonnet init app-name --api-spec=version:v1.7.1 + ks init app-name --api-spec=version:v1.7.1 # Initialize ksonnet application, using an OpenAPI specification file # generated by a build of Kubernetes to generate 'ksonnet-lib'. - ksonnet init app-name --api-spec=file:swagger.json`, + ks init app-name --api-spec=file:swagger.json`, } diff --git a/cmd/prototype.go b/cmd/prototype.go index a2399c2d4f4ade2a5595d8432fe34b0fa9cc024d..233e26de84d2f256e2744df85169569e159797da 100644 --- a/cmd/prototype.go +++ b/cmd/prototype.go @@ -66,21 +66,21 @@ Commands: # identifier to disambiguate it among other known prototypes, which is why # 'simple-deployment' is given as argument instead of the fully-qualified # name. - ksonnet prototype describe simple-deployment + ks prototype describe simple-deployment # Instantiate prototype 'io.ksonnet.pkg.prototype.simple-deployment', using # the 'nginx' image, and port 80 exposed. # # SEE ALSO: Note above for a description of why this subcommand can take # 'simple-deployment' instead of the fully-qualified prototype name. - ksonnet prototype use simple-deployment \ + ks prototype use simple-deployment \ --name=nginx \ --image=nginx \ --port=80 \ --portName=http # Search known prototype metadata for the string 'deployment'. - ksonnet prototype search deployment`, + ks prototype search deployment`, } var prototypeListCmd = &cobra.Command{ @@ -151,7 +151,7 @@ ambiguously, in which case 'use' will fail, while 'simple-deployment' might be unique enough to resolve to 'io.ksonnet.pkg.prototype.simple-deployment'.`, Example: ` # Display documentation about prototype, including: - ksonnet prototype describe io.ksonnet.pkg.prototype.simple-deployment + ks prototype describe io.ksonnet.pkg.prototype.simple-deployment # Display documentation about prototype using a unique suffix of an # identifier. That is, this command only requires a long enough suffix to @@ -159,7 +159,7 @@ unique enough to resolve to 'io.ksonnet.pkg.prototype.simple-deployment'.`, # 'simple-deployment' is enough to uniquely identify # 'io.ksonnet.pkg.prototype.simple-deployment', but 'deployment' might not # be, as several names end with that suffix. - ksonnet prototype describe simple-deployment`, + ks prototype describe simple-deployment`, } var prototypeSearchCmd = &cobra.Command{ @@ -186,7 +186,7 @@ var prototypeSearchCmd = &cobra.Command{ }, Long: `Search ksonnet for prototypes whose names contain 'name-substring'.`, Example: ` # Search known prototype metadata for the string 'deployment'. - ksonnet prototype search deployment`, + ks prototype search deployment`, } var prototypePreviewCmd = &cobra.Command{ @@ -248,20 +248,20 @@ unique enough to resolve to 'io.ksonnet.pkg.single-port-deployment'.`, Example: ` # Preview prototype 'io.ksonnet.pkg.single-port-deployment', using the # 'nginx' image, and port 80 exposed. - ksonnet prototype preview io.ksonnet.pkg.prototype.simple-deployment \ + ks prototype preview io.ksonnet.pkg.prototype.simple-deployment \ --name=nginx \ --image=nginx # Preview prototype using a unique suffix of an identifier. See # introduction of help message for more information on how this works. - ksonnet prototype preview simple-deployment \ + ks prototype preview simple-deployment \ --name=nginx \ --image=nginx # Preview prototype 'io.ksonnet.pkg.single-port-deployment' as YAML, # placing the result in 'components/nginx-depl.yaml. Note that some templates # do not have a YAML or JSON versions. - ksonnet prototype preview deployment nginx-depl yaml \ + ks prototype preview deployment nginx-depl yaml \ --name=nginx \ --image=nginx`, } @@ -334,7 +334,7 @@ following command will expand template 'io.ksonnet.pkg.single-port-deployment' and place it in the file 'components/nginx-depl.jsonnet' (since by default ksonnet will expand templates as Jsonnet). - ksonnet prototype use io.ksonnet.pkg.single-port-deployment nginx-depl \ + ks prototype use io.ksonnet.pkg.single-port-deployment nginx-depl \ --name=nginx \ --image=nginx @@ -350,7 +350,7 @@ unique enough to resolve to 'io.ksonnet.pkg.single-port-deployment'.`, Example: ` # Instantiate prototype 'io.ksonnet.pkg.single-port-deployment', using the # 'nginx' image. The expanded prototype is placed in # 'components/nginx-depl.jsonnet'. - ksonnet prototype use io.ksonnet.pkg.prototype.simple-deployment nginx-depl \ + ks prototype use io.ksonnet.pkg.prototype.simple-deployment nginx-depl \ --name=nginx \ --image=nginx @@ -359,14 +359,14 @@ unique enough to resolve to 'io.ksonnet.pkg.single-port-deployment'.`, # 'components/nginx-depl.jsonnet'. See introduction of help message for more # information on how this works. Note that if you have imported another # prototype with this suffix, this may resolve ambiguously for you. - ksonnet prototype use deployment nginx-depl \ + ks prototype use deployment nginx-depl \ --name=nginx \ --image=nginx # Instantiate prototype 'io.ksonnet.pkg.single-port-deployment' as YAML, # placing the result in 'components/nginx-depl.yaml. Note that some templates # do not have a YAML or JSON versions. - ksonnet prototype use deployment nginx-depl yaml \ + ks prototype use deployment nginx-depl yaml \ --name=nginx \ --image=nginx`, } diff --git a/cmd/root.go b/cmd/root.go index 345ee07465f598474466ef4bd1c2aaa82e7623ae..a507fdb3d0fd780b6d44e741761676047ffbeab1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -95,7 +95,7 @@ func bindClientGoFlags(cmd *cobra.Command) { // RootCmd is the root of cobra subcommand tree var RootCmd = &cobra.Command{ - Use: "kubecfg", + Use: "ks", Short: "Synchronise Kubernetes resources with config files", SilenceErrors: true, SilenceUsage: true, diff --git a/cmd/update.go b/cmd/update.go index e4260693ec07b5a0812315a9893a040f47828fa2..31630a35a2b289bbbab1373174e12366d98edc24 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -112,16 +112,16 @@ files.`, Example: ` # Create or update all resources described in a ksonnet application, and # running in the 'dev' environment. Can be used in any subdirectory of the # application. - ksonnet update dev + ks update dev # Create or update resources described in a YAML file. Automatically picks up # the cluster's location from '$KUBECONFIG'. - ksonnet appy -f ./pod.yaml + ks update -f ./pod.yaml # Update resources described in a YAML file, and running in cluster referred # to by './kubeconfig'. - ksonnet update --kubeconfig=./kubeconfig -f ./pod.yaml + ks update --kubeconfig=./kubeconfig -f ./pod.yaml # Display set of actions we will execute when we run 'update'. - ksonnet update dev --dry-run`, + ks update dev --dry-run`, } diff --git a/examples/guestbook.jsonnet b/examples/guestbook.jsonnet index bc86ca5383f7e34309639fc36513dc871db41d91..a584d96b260269b451336c45031ba62f74ba655d 100644 --- a/examples/guestbook.jsonnet +++ b/examples/guestbook.jsonnet @@ -23,9 +23,9 @@ // Expects to be run with ../lib in the jsonnet search path: // ``` // export KUBECFG_JPATH=$PWD/../lib -// kubecfg apply guestbook.jsonnet +// ks apply guestbook.jsonnet // # poke at $(minikube service --url frontend), etc -// kubecfg delete guestbook.jsonnet +// ks delete guestbook.jsonnet // ``` local example = import "example.libsonnet"; diff --git a/integration/integration_suite_test.go b/integration/integration_suite_test.go index cd7b9f7e7fec3a738c303a9437b79752a35f98fd..d39e957aab264e1e05a13c46b867e6dd29e4ca12 100644 --- a/integration/integration_suite_test.go +++ b/integration/integration_suite_test.go @@ -31,7 +31,7 @@ import ( ) var kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file") -var kubecfgBin = flag.String("kubecfg-bin", "kubecfg", "path to kubecfg executable under test") +var kubecfgBin = flag.String("kubecfg-bin", "ks", "path to kubecfg executable under test") func init() { if missingVersions := api.Registry.ValidateEnvRequestedVersions(); len(missingVersions) != 0 { diff --git a/lib/kubecfg_test.jsonnet b/lib/kubecfg_test.jsonnet index 5a49f71834b7e0f901d104e629d3d0301341a3e2..569a7fb09d21f2184f99db75d8a1c96beb478a33 100644 --- a/lib/kubecfg_test.jsonnet +++ b/lib/kubecfg_test.jsonnet @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Run me with `../kubecfg show -f kubecfg_test.jsonnet` +// Run me with `../ks show -f kubecfg_test.jsonnet` local kubecfg = import "kubecfg.libsonnet"; assert kubecfg.parseJson("[3, 4]") == [3, 4]; diff --git a/prototype/systemPrototypes.go b/prototype/systemPrototypes.go index 5fe490b8f436473b454aa2f7417ae23bb28973c0..b911d47db0f62aacf5e40253da69acc38e176733 100644 --- a/prototype/systemPrototypes.go +++ b/prototype/systemPrototypes.go @@ -58,7 +58,7 @@ to 'targetLabelSelector', at 'targetPort'. Since 'targetLabelSelector' is an object literal that specifies which labels the service is meant to target, this will typically look something like: - ksonnet prototype use service --targetLabelSelector "{app: 'nginx'}" [...]`, + ks prototype use service --targetLabelSelector "{app: 'nginx'}" [...]`, ShortDescription: `Service that exposes a single port`, YAMLBody: []string{ `kind: Service`,