Unverified Commit 332a9610 authored by Bryan Liles's avatar Bryan Liles Committed by GitHub
Browse files

Merge pull request #330 from bryanl/plugins

Create support for plugins in ksonnet
parents 90a2f348 524fa4bc
......@@ -349,7 +349,7 @@
".",
"doc"
]
revision = "4673102358fdd630e3bb0eb6dee96e4b533d53ec"
revision = "a1e4933ab784095895e33dbe9f001ba10cfe2060"
[[projects]]
name = "github.com/spf13/pflag"
......@@ -600,6 +600,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "3ec216adf8721873a210ca86de7f6477993f990d180563ba88a2e167a0b7be88"
inputs-digest = "2d8337f0b0870fb8b2c0a041d7b5e3e77b66b414fe9c2d7962ee5c5842bb94e0"
solver-name = "gps-cdcl"
solver-version = 1
......@@ -78,7 +78,7 @@
[[constraint]]
name = "github.com/spf13/cobra"
revision = "4673102358fdd630e3bb0eb6dee96e4b533d53ec"
revision = "a1e4933ab784095895e33dbe9f001ba10cfe2060"
[[constraint]]
name = "github.com/spf13/pflag"
......@@ -114,4 +114,4 @@
[[constraint]]
name = "k8s.io/client-go"
version = "5.0.0"
\ No newline at end of file
version = "5.0.0"
......@@ -30,6 +30,7 @@ import (
"github.com/ksonnet/ksonnet/component"
"github.com/ksonnet/ksonnet/metadata"
"github.com/ksonnet/ksonnet/plugin"
str "github.com/ksonnet/ksonnet/strings"
"github.com/ksonnet/ksonnet/template"
"github.com/pkg/errors"
......@@ -109,6 +110,57 @@ application configuration to remote clusters.
return nil
},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cobra.NoArgs(cmd, args)
}
pluginName := args[0]
_, err := plugin.Find(appFs, pluginName)
if err != nil {
return cobra.NoArgs(cmd, args)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
}
pluginName, args := args[0], args[1:]
p, err := plugin.Find(appFs, pluginName)
if err != nil {
return err
}
return runPlugin(p, args)
},
}
func runPlugin(p plugin.Plugin, args []string) error {
env := []string{
fmt.Sprintf("KS_PLUGIN_DIR=%s", p.RootDir),
fmt.Sprintf("KS_PLUGIN_NAME=%s", p.Config.Name),
}
root, err := appRoot()
if err != nil {
return err
}
appConfig := filepath.Join(root, "app.yaml")
exists, err := afero.Exists(appFs, appConfig)
if err != nil {
return err
}
if exists {
env = append(env, fmt.Sprintf("KS_APP_DIR=%s", root))
// TODO: make kube context or something similar available to the plugin
}
cmd := p.BuildRunCmd(env, args)
return cmd.Run()
}
func logLevel(verbosity int) log.Level {
......@@ -429,3 +481,7 @@ func importEnv(manager metadata.Manager, env string) (string, error) {
return fmt.Sprintf(`%s=%s`, metadata.EnvExtCodeKey, string(marshalled)), nil
}
func appRoot() (string, error) {
return os.Getwd()
}
......@@ -5,20 +5,25 @@ Configure your application to deploy to a Kubernetes cluster
### Synopsis
You can use the `ks` commands to write, share, and deploy your Kubernetes
application configuration to remote clusters.
----
```
ks [flags]
```
### Options
```
-h, --help help for ks
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
* [ks apply](ks_apply.md) - Apply local Kubernetes manifests (components) to remote clusters
* [ks component](ks_component.md) - Manage ksonnet components
* [ks delete](ks_delete.md) - Remove component-specified Kubernetes resources from remote clusters
......
......@@ -5,7 +5,6 @@ Apply local Kubernetes manifests (components) to remote clusters
### Synopsis
The `apply`command uses local manifest(s) to update (and optionally create)
Kubernetes resources on a remote cluster. This cluster is determined by the
mandatory `<env-name>` argument.
......@@ -28,7 +27,7 @@ Note that this command needs to be run *within* a ksonnet app directory.
```
ks apply <env-name> [-c <component-name>] [--dry-run]
ks apply <env-name> [-c <component-name>] [--dry-run] [flags]
```
### Examples
......@@ -78,6 +77,7 @@ ks apply dev -c guestbook-ui -c nginx-depl --create false
-V, --ext-str stringSlice Values of external variables
--ext-str-file stringSlice Read external variable from a file
--gc-tag string A tag that's (1) added to all updated objects (2) used to garbage collect existing objects that are no longer in the manifest
-h, --help help for apply
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
-J, --jpath stringSlice Additional jsonnet library search path
--kubeconfig string Path to a kubeconfig file. Alternative to env var $KUBECONFIG.
......@@ -102,5 +102,6 @@ ks apply dev -c guestbook-ui -c nginx-depl --create false
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
......@@ -4,11 +4,16 @@ Manage ksonnet components
### Synopsis
Manage ksonnet components
```
ks component
ks component [flags]
```
### Options
```
-h, --help help for component
```
### Options inherited from parent commands
......@@ -18,6 +23,7 @@ ks component
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
* [ks component list](ks_component_list.md) - List known components
* [ks component rm](ks_component_rm.md) - Delete a component from the ksonnet application
......
......@@ -5,14 +5,13 @@ List known components
### Synopsis
The `list` command displays all known components.
### Syntax
```
ks component list
ks component list [flags]
```
### Examples
......@@ -23,6 +22,12 @@ ks component list
ks component list
```
### Options
```
-h, --help help for list
```
### Options inherited from parent commands
```
......@@ -30,5 +35,6 @@ ks component list
```
### SEE ALSO
* [ks component](ks_component.md) - Manage ksonnet components
......@@ -4,13 +4,12 @@ Delete a component from the ksonnet application
### Synopsis
Delete a component from the ksonnet application. This is equivalent to deleting the
component file in the components directory and cleaning up all component
references throughout the project.
```
ks component rm <component-name>
ks component rm <component-name> [flags]
```
### Examples
......@@ -26,6 +25,7 @@ ks component rm guestbook
```
--component string The component to be removed from components/
-h, --help help for rm
```
### Options inherited from parent commands
......@@ -35,5 +35,6 @@ ks component rm guestbook
```
### SEE ALSO
* [ks component](ks_component.md) - Manage ksonnet components
......@@ -5,7 +5,6 @@ Remove component-specified Kubernetes resources from remote clusters
### Synopsis
The `delete` command removes Kubernetes resources (described in local
*component* manifests) from a cluster. This cluster is determined by the mandatory
`<env-name>`argument.
......@@ -24,7 +23,7 @@ components.
```
ks delete [env-name] [-c <component-name>]
ks delete [env-name] [-c <component-name>] [flags]
```
### Examples
......@@ -55,6 +54,7 @@ ks delete --kubeconfig=./kubeconfig -c nginx
-V, --ext-str stringSlice Values of external variables
--ext-str-file stringSlice Read external variable from a file
--grace-period int Number of seconds given to resources to terminate gracefully. A negative value is ignored (default -1)
-h, --help help for delete
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
-J, --jpath stringSlice Additional jsonnet library search path
--kubeconfig string Path to a kubeconfig file. Alternative to env var $KUBECONFIG.
......@@ -78,5 +78,6 @@ ks delete --kubeconfig=./kubeconfig -c nginx
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
......@@ -5,7 +5,6 @@ Compare manifests, based on environment or location (local or remote)
### Synopsis
The `diff` command displays standard file diffs, and can be used to compare manifests
based on *environment* or location ('local' ksonnet app manifests or what's running
on a 'remote' server).
......@@ -34,7 +33,7 @@ the manifest for that particular component.
```
ks diff <location1:env1> [location2:env2] [-c <component-name>]
ks diff <location1:env1> [location2:env2] [-c <component-name>] [flags]
```
### Examples
......@@ -71,6 +70,7 @@ ks diff dev -c redis
--diff-strategy string Diff strategy, all or subset. (default "all")
-V, --ext-str stringSlice Values of external variables
--ext-str-file stringSlice Read external variable from a file
-h, --help help for diff
-J, --jpath stringSlice Additional jsonnet library search path
--resolve-images string Change implementation of resolveImage native function. One of: noop, registry (default "noop")
--resolve-images-error string Action when resolveImage fails. One of ignore,warn,error (default "warn")
......@@ -85,5 +85,6 @@ ks diff dev -c redis
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
......@@ -5,7 +5,6 @@ Manage ksonnet environments
### Synopsis
An environment is a deployment target for your ksonnet app and its constituent
components. You can use ksonnet to deploy a given app to *multiple* environments,
such as `dev` and `prod`.
......@@ -43,7 +42,7 @@ represented as a hierarchy in the `environments/` directory of a ksonnet app, li
```
ks env
ks env [flags]
```
### Options
......@@ -56,6 +55,7 @@ ks env
--client-key string Path to a client key file for TLS
--cluster string The name of the kubeconfig cluster to use
--context string The name of the kubeconfig context to use
-h, --help help for env
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
--kubeconfig string Path to a kubeconfig file. Alternative to env var $KUBECONFIG.
-n, --namespace string If present, the namespace scope for this CLI request
......@@ -74,6 +74,7 @@ ks env
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
* [ks env add](ks_env_add.md) - Add a new environment to a ksonnet application
* [ks env list](ks_env_list.md) - List all environments in a ksonnet application
......
......@@ -5,7 +5,6 @@ Add a new environment to a ksonnet application
### Synopsis
The `add` command creates a new environment (specifically for the ksonnet app
whose directory it's executed in). This environment is cached with the following
info:
......@@ -34,7 +33,7 @@ Note that an environment *DOES NOT* contain user-specific data such as private k
```
ks env add <env-name>
ks env add <env-name> [flags]
```
### Examples
......@@ -67,6 +66,7 @@ ks env add prod --server=https://ksonnet-1.us-west.elb.amazonaws.com
```
--api-spec string Manually specify API version from OpenAPI schema, cluster, or Kubernetes version (default "version:v1.7.0")
-h, --help help for add
```
### Options inherited from parent commands
......@@ -92,5 +92,6 @@ ks env add prod --server=https://ksonnet-1.us-west.elb.amazonaws.com
```
### SEE ALSO
* [ks env](ks_env.md) - Manage ksonnet environments
......@@ -5,7 +5,6 @@ List all environments in a ksonnet application
### Synopsis
The `list` command lists all of the available environments for the
current ksonnet app. Specifically, this will display the (1) *name*,
(2) *server*, and (3) *namespace* of each environment.
......@@ -20,7 +19,13 @@ current ksonnet app. Specifically, this will display the (1) *name*,
```
ks env list
ks env list [flags]
```
### Options
```
-h, --help help for list
```
### Options inherited from parent commands
......@@ -46,5 +51,6 @@ ks env list
```
### SEE ALSO
* [ks env](ks_env.md) - Manage ksonnet environments
......@@ -5,7 +5,6 @@ Delete an environment from a ksonnet application
### Synopsis
The `rm` command deletes an environment from a ksonnet application. This is
the same as removing the `<env-name>` environment directory and all files
contained. All empty parent directories are also subsequently deleted.
......@@ -24,7 +23,7 @@ need to use the `ks delete` command.
```
ks env rm <env-name>
ks env rm <env-name> [flags]
```
### Examples
......@@ -36,6 +35,12 @@ ks env rm <env-name>
ks env rm us-west/staging
```
### Options
```
-h, --help help for rm
```
### Options inherited from parent commands
```
......@@ -59,5 +64,6 @@ ks env rm us-west/staging
```
### SEE ALSO
* [ks env](ks_env.md) - Manage ksonnet environments
......@@ -5,7 +5,6 @@ Set environment-specific fields (name, namespace, server)
### Synopsis
The `set` command lets you change the fields of an existing environment.
You can currently only update your environment's name.
......@@ -20,7 +19,7 @@ directory structure in `environments/`.
```
ks env set <env-name>
ks env set <env-name> [flags]
```
### Examples
......@@ -34,6 +33,7 @@ ks env set us-west/staging --name=us-east/staging
### Options
```
-h, --help help for set
--name string Name used to uniquely identify the environment. Must not already exist within the ksonnet app
```
......@@ -60,5 +60,6 @@ ks env set us-west/staging --name=us-east/staging
```
### SEE ALSO
* [ks env](ks_env.md) - Manage ksonnet environments
......@@ -5,7 +5,6 @@ Use the specified prototype to generate a component manifest
### Synopsis
The `generate` command (aliased from `prototype use`) generates Kubernetes-
compatible, Jsonnet manifests for components in your ksonnet app. Each component
corresponds to a single manifest in the `components/` directory. This manifest
......@@ -43,7 +42,7 @@ different prototypes support their own unique flags.
```
ks generate <prototype-name> <component-name> [type] [parameter-flags]
ks generate <prototype-name> <component-name> [type] [parameter-flags] [flags]
```
### Examples
......@@ -68,6 +67,12 @@ ks prototype use deployment nginx-depl \
--image=nginx
```
### Options
```
-h, --help help for generate
```
### Options inherited from parent commands
```
......@@ -75,5 +80,6 @@ ks prototype use deployment nginx-depl \
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
......@@ -5,7 +5,6 @@ Initialize a ksonnet application
### Synopsis
The `init` command initializes a ksonnet application in a new directory, `app-name`.
This command generates all the project scaffolding required to begin creating and
......@@ -91,6 +90,7 @@ ks init app-name --dir=custom-location
--cluster string The name of the kubeconfig cluster to use
--context string The name of the kubeconfig context to use
--dir string Ksonnet application directory
-h, --help help for init
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
--kubeconfig string Path to a kubeconfig file. Alternative to env var $KUBECONFIG.
-n, --namespace string If present, the namespace scope for this CLI request
......@@ -109,5 +109,6 @@ ks init app-name --dir=custom-location
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
......@@ -5,7 +5,6 @@ Manage ksonnet parameters for components and environments
### Synopsis
Parameters are customizable fields that are used inside ksonnet *component*
manifests. Examples might include a deployment's 'name' or 'image'. Parameters
can also be defined on a *per-environment* basis. (Environments are ksonnet
......@@ -36,7 +35,13 @@ Jsonnet files.
```
ks param
ks param [flags]
```
### Options
```
-h, --help help for param
```
### Options inherited from parent commands
......@@ -46,6 +51,7 @@ ks param
```
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
* [ks param diff](ks_param_diff.md) - Display differences between the component parameters of two environments
* [ks param list](ks_param_list.md) - List known component parameters
......
......@@ -5,7 +5,6 @@ Display differences between the component parameters of two environments
### Synopsis
The `diff` command pretty prints differences between the component parameters
of two environments.
......@@ -21,7 +20,7 @@ is supported via a component flag.
```
ks param diff <env1> <env2> [--component <component-name>]
ks param diff <env1> <env2> [--component <component-name>] [flags]
```
### Examples
......@@ -40,6 +39,7 @@ ks param diff dev prod --component=guestbook
```
--component string Specify the component to diff against
-h, --help help for diff
```
### Options inherited from parent commands
......@@ -49,5 +49,6 @@ ks param diff dev prod --component=guestbook
```
### SEE ALSO
* [ks param](ks_param.md) - Manage ksonnet parameters for components and environments
......@@ -5,7 +5,6 @@ List known component parameters
### Synopsis
The `list` command displays all known component parameters or environment parameters.
If a component is specified, this command displays all of its specific parameters.
......@@ -20,7 +19,7 @@ Furthermore, parameters can be listed on a per-environment basis.
```
ks param list [<component-name>] [--env <env-name>]
ks param list [<component-name>] [--env <env-name>] [flags]
```
### Examples
......@@ -44,6 +43,7 @@ ks param list guestbook --env=dev
```
--env string Specify environment to list parameters for
-h, --help help for list
```
### Options inherited from parent commands
......@@ -53,5 +53,6 @@ ks param list guestbook --env=dev
```
### SEE ALSO
* [ks param](ks_param.md) - Manage ksonnet parameters for components and environments
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment