Unverified Commit dc8ddd80 authored by bryanl's avatar bryanl
Browse files

Detect cluster version when adding an envirohnment



Fixes #539
Signed-off-by: default avatarbryanl <bryanliles@gmail.com>
parent e0a95996
......@@ -32,7 +32,7 @@ ks [flags]
* [ks generate](ks_generate.md) - Use the specified prototype to generate a component manifest
* [ks import](ks_import.md) - Import manifest
* [ks init](ks_init.md) - Initialize a ksonnet application
* [ks module](ks_module.md) - module
* [ks module](ks_module.md) - Manage ksonnet modules
* [ks param](ks_param.md) - Manage ksonnet parameters for components and environments
* [ks pkg](ks_pkg.md) - Manage packages and dependencies for the current ksonnet application
* [ks prototype](ks_prototype.md) - Instantiate, inspect, and get examples for ksonnet prototypes
......
......@@ -48,23 +48,7 @@ ks env [flags]
### Options
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-h, --help help for env
```
### Options inherited from parent commands
......@@ -78,10 +62,10 @@ ks env [flags]
* [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 current](ks_env_current.md) - Sets the current environment
* [ks env describe](ks_env_describe.md) - describe
* [ks env describe](ks_env_describe.md) - Describe an environment
* [ks env list](ks_env_list.md) - List all environments in a ksonnet application
* [ks env rm](ks_env_rm.md) - Delete an environment from a ksonnet application
* [ks env set](ks_env_set.md) - Set environment-specific fields (name, namespace, server)
* [ks env targets](ks_env_targets.md) - targets
* [ks env targets](ks_env_targets.md) - Set module targets for an environment
* [ks env update](ks_env_update.md) - Updates the libs for an environment
......@@ -23,10 +23,10 @@ Note that an environment *DOES NOT* contain user-specific data such as private k
### Related Commands
* `ks env list` — List all locally available ksonnet prototypes
* `ks env rm`
* `ks env set`
* `ks param set`Change component or environment parameters (e.g. replica count, name)
* `ks env list` — List all environments in a ksonnet application
* `ks env rm`Delete an environment from a ksonnet application
* `ks env set`Set environment-specific fields (name, namespace, server)
* `ks param set`Set environment-specific fields (name, namespace, server)
* `ks apply` — Apply local Kubernetes manifests (components) to remote clusters
### Syntax
......@@ -65,14 +65,7 @@ ks env add prod --server=https://ksonnet-1.us-west.elb.amazonaws.com
### Options
```
--api-spec string Manually specify API version from OpenAPI schema, cluster, or Kubernetes version (default "version:v1.7.0")
-h, --help help for add
-o, --override Add environment as override
```
### Options inherited from parent commands
```
--api-spec string Manually specify API version from OpenAPI schema, cluster, or Kubernetes version
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
......@@ -80,16 +73,23 @@ ks env add prod --server=https://ksonnet-1.us-west.elb.amazonaws.com
--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 add
--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
-o, --override Add environment as override
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### Options inherited from parent commands
```
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
......@@ -42,23 +42,7 @@ ks env current --unset
### Options inherited from parent commands
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
## ks env describe
describe
Describe an environment
### Synopsis
......@@ -19,23 +19,7 @@ ks env describe <env> [flags]
### Options inherited from parent commands
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
......@@ -32,23 +32,7 @@ ks env list [flags]
### Options inherited from parent commands
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
......@@ -14,9 +14,9 @@ need to use the `ks delete` command.
### Related Commands
* `ks env list` — List all locally available ksonnet prototypes
* `ks env add`
* `ks env set`
* `ks env list` — List all environments in a ksonnet application
* `ks env add`Add a new environment to a ksonnet application
* `ks env set`Set environment-specific fields (name, namespace, server)
* `ks delete` — Delete all the app components running in an environment (cluster)
### Syntax
......@@ -45,23 +45,7 @@ ks env rm us-west/staging
### Options inherited from parent commands
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
......@@ -33,30 +33,15 @@ 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
-h, --help help for set
--name string Name used to uniquely identify the environment. Must not already exist within the ksonnet app
--namespace string Namespace for environment.
```
### Options inherited from parent commands
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
## ks env targets
targets
Set module targets for an environment
### Synopsis
......@@ -20,23 +20,7 @@ ks env targets [flags]
### Options inherited from parent commands
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
......@@ -9,9 +9,9 @@ The `update` command updates libraries for an environment.
### Related Commands
* `ks env list` — List all locally available ksonnet prototypes
* `ks env add`
* `ks env set`
* `ks env list` — List all environments in a ksonnet application
* `ks env add`Add a new environment to a ksonnet application
* `ks env set`Set environment-specific fields (name, namespace, server)
* `ks delete` — Delete all the app components running in an environment (cluster)
### Syntax
......@@ -38,23 +38,7 @@ ks env update us-west/staging
### Options inherited from parent commands
```
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--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
--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
--password string Password for basic authentication to the API server
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
--server string The address and port of the Kubernetes API server
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
--username string Username for basic authentication to the API server
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
-v, --verbose count[=-1] Increase verbosity. May be given multiple times.
```
### SEE ALSO
......
## ks module
module
Manage ksonnet modules
### Synopsis
module
Manage ksonnet modules
### Options
......@@ -21,6 +21,6 @@ module
### SEE ALSO
* [ks](ks.md) - Configure your application to deploy to a Kubernetes cluster
* [ks module create](ks_module_create.md) - create
* [ks module list](ks_module_list.md) - list
* [ks module create](ks_module_create.md) - Create a module
* [ks module list](ks_module_list.md) - List modules
## ks module create
create
Create a module
### Synopsis
create
Create a module
```
ks module create <name> [flags]
......@@ -24,5 +24,5 @@ ks module create <name> [flags]
### SEE ALSO
* [ks module](ks_module.md) - module
* [ks module](ks_module.md) - Manage ksonnet modules
## ks module list
list
List modules
### Synopsis
list
List modules
```
ks module list [flags]
......@@ -25,5 +25,5 @@ ks module list [flags]
### SEE ALSO
* [ks module](ks_module.md) - module
* [ks module](ks_module.md) - Manage ksonnet modules
......@@ -22,6 +22,7 @@ import (
"strings"
"github.com/ksonnet/ksonnet/pkg/lib"
"github.com/sirupsen/logrus"
"github.com/pkg/errors"
"github.com/spf13/afero"
......@@ -48,6 +49,11 @@ func NewApp010(fs afero.Fs, root string) *App010 {
// AddEnvironment adds an environment spec to the app spec. If the spec already exists,
// it is overwritten.
func (a *App010) AddEnvironment(name, k8sSpecFlag string, newEnv *EnvironmentSpec, isOverride bool) error {
logrus.WithFields(logrus.Fields{
"k8s-spec-flag": k8sSpecFlag,
"name": name,
}).Debug("adding environment")
if err := a.load(); err != nil {
return errors.Wrap(err, "load configuration")
}
......
......@@ -61,6 +61,11 @@ func new(fs afero.Fs, name, rootPath, envName, k8sSpecFlag, serverURI, namespace
}
func (i *initApp) Run() error {
log.WithFields(log.Fields{
"env-name": i.envName,
"k8s-spec-flag": i.k8sSpecFlag,
}).Debug("initializing ksonnet app")
// Initialize directory structure.
if err := i.createAppDirTree(); err != nil {
return err
......
......@@ -22,8 +22,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/ksonnet/ksonnet/pkg/client"
)
const (
......@@ -34,8 +32,7 @@ const (
)
var (
envClientConfig *client.Config
envShortDesc = map[string]string{
envShortDesc = map[string]string{
"add": "Add a new environment to a ksonnet application",
"current": "Sets the current environment",
"list": "List all environments in a ksonnet application",
......@@ -47,19 +44,9 @@ var (
func init() {
RootCmd.AddCommand(envCmd)
envClientConfig = client.NewDefaultClientConfig(ka)
envClientConfig.BindClientGoFlags(envCmd)
envCmd.AddCommand(envAddCmd)
envCmd.AddCommand(envRmCmd)
// TODO: We need to make this default to checking the `kubeconfig` file.
envAddCmd.PersistentFlags().String(flagAPISpec, "version:v1.7.0",
"Manually specify API version from OpenAPI schema, cluster, or Kubernetes version")
envAddCmd.Flags().BoolP(flagOverride, shortOverride, false, "Add environment as override")
viper.BindPFlag(vEnvAddOverride, envAddCmd.Flags().Lookup(flagOverride))
envRmCmd.Flags().BoolP(flagOverride, shortOverride, false, "Remove the overridden environment")
viper.BindPFlag(vEnvRmOverride, envRmCmd.Flags().Lookup(flagOverride))
}
......
......@@ -21,6 +21,7 @@ import (
"github.com/spf13/viper"
"github.com/ksonnet/ksonnet/pkg/actions"
"github.com/ksonnet/ksonnet/pkg/client"
"github.com/spf13/cobra"
)
......@@ -28,6 +29,24 @@ const (
vEnvAddOverride = "env-add-override"
)
var (
envClientConfig *client.Config
)
func init() {
envCmd.AddCommand(envAddCmd)
envClientConfig = client.NewDefaultClientConfig(ka)
envClientConfig.BindClientGoFlags(envAddCmd)
// TODO: We need to make this default to checking the `kubeconfig` file.
envAddCmd.PersistentFlags().String(flagAPISpec, "",
"Manually specify API version from OpenAPI schema, cluster, or Kubernetes version")
envAddCmd.Flags().BoolP(flagOverride, shortOverride, false, "Add environment as override")
viper.BindPFlag(vEnvAddOverride, envAddCmd.Flags().Lookup(flagOverride))
}
var envAddCmd = &cobra.Command{
Use: "add <env-name>",
Short: envShortDesc["add"],
......@@ -87,10 +106,10 @@ Note that an environment *DOES NOT* contain user-specific data such as private k
### Related Commands
* ` + "`ks env list` " + `— ` + protoShortDesc["list"] + `
* ` + "`ks env rm` " + `— ` + protoShortDesc["rm"] + `
* ` + "`ks env set` " + `— ` + protoShortDesc["set"] + `
* ` + "`ks param set` " + `— ` + paramShortDesc["set"] + `
* ` + "`ks env list` " + `— ` + envShortDesc["list"] + `
* ` + "`ks env rm` " + `— ` + envShortDesc["rm"] + `
* ` + "`ks env set` " + `— ` + envShortDesc["set"] + `
* ` + "`ks param set` " + `— ` + envShortDesc["set"] + `
* ` + "`ks apply` " + `— ` + applyShortDesc + `
### Syntax
......
......@@ -25,7 +25,7 @@ func Test_envAddCmd(t *testing.T) {
cases := []cmdTestCase{
{
name: "in general",
args: []string{"env", "add", "prod", "--server", "http://example.com"},
args: []string{"env", "add", "prod", "--server", "http://example.com", "--api-spec", "version:v1.9.5"},
action: actionEnvAdd,
expected: map[string]interface{}{
actions.OptionApp: ka,
......@@ -33,7 +33,7 @@ func Test_envAddCmd(t *testing.T) {
actions.OptionModule: "default",
actions.OptionOverride: false,
actions.OptionServer: "http://example.com",
actions.OptionSpecFlag: "version:v1.7.0",
actions.OptionSpecFlag: "version:v1.9.5",
},
},
}
......
......@@ -24,7 +24,7 @@ import (
// envDescribeCmd represents the env describe command
var envDescribeCmd = &cobra.Command{
Use: "describe <env>",
Short: "describe",
Short: "Describe an environment",
Long: `describe`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
......
......@@ -53,9 +53,9 @@ need to use the ` + "`ks delete`" + ` command.
### Related Commands
* ` + "`ks env list` " + `— ` + protoShortDesc["list"] + `
* ` + "`ks env add` " + `— ` + protoShortDesc["add"] + `
* ` + "`ks env set` " + `— ` + protoShortDesc["set"] + `
* ` + "`ks env list` " + `— ` + envShortDesc["list"] + `
* ` + "`ks env add` " + `— ` + envShortDesc["add"] + `
* ` + "`ks env set` " + `— ` + envShortDesc["set"] + `
* ` + "`ks delete` " + `— ` + `Delete all the app components running in an environment (cluster)` + `
### Syntax
......
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