Skip to content
Snippets Groups Projects
Unverified Commit 9a2ca436 authored by Alex Clemmer's avatar Alex Clemmer Committed by GitHub
Browse files

Merge pull request #37 from jessicayuen/uri-to-server

Rename environment uri references to server
parents b70c996f 6661d25b
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
const ( const (
flagEnvName = "name" flagEnvName = "name"
flagEnvURI = "uri" flagEnvServer = "server"
flagEnvNamespace = "namespace" flagEnvNamespace = "namespace"
flagEnvContext = "context" flagEnvContext = "context"
...@@ -47,21 +47,9 @@ func init() { ...@@ -47,21 +47,9 @@ func init() {
// TODO: We need to make this default to checking the `kubeconfig` file. // TODO: We need to make this default to checking the `kubeconfig` file.
envAddCmd.PersistentFlags().String(flagAPISpec, "version:v1.7.0", envAddCmd.PersistentFlags().String(flagAPISpec, "version:v1.7.0",
"Manually specify API version from OpenAPI schema, cluster, or Kubernetes version") "Manually specify API version from OpenAPI schema, cluster, or Kubernetes version")
envAddCmd.PersistentFlags().String(flagEnvNamespace, "",
"Specify namespace that the environment cluster should use")
envAddCmd.PersistentFlags().String(flagEnvURI, "",
"Specify the server URI that the environment should use")
envAddCmd.PersistentFlags().String(flagEnvContext, "",
"Specify the context in your kubecfg file that this environment should use")
envSetCmd.PersistentFlags().String(flagEnvName, "", envSetCmd.PersistentFlags().String(flagEnvName, "",
"Specify name to rename environment to. Name must not already exist") "Specify name to rename environment to. Name must not already exist")
envSetCmd.PersistentFlags().String(flagEnvURI, "",
"Specify URI to point environment cluster to a new location")
envSetCmd.PersistentFlags().String(flagEnvNamespace, "",
"Specify namespace that the environment cluster should use")
envSetCmd.PersistentFlags().String(flagEnvContext, "",
"Specify the context in your kubecfg file that this environment should use. This will update the server URI for your environment")
} }
var envCmd = &cobra.Command{ var envCmd = &cobra.Command{
...@@ -80,7 +68,7 @@ often contained in a kubeconfig file), and ...@@ -80,7 +68,7 @@ often contained in a kubeconfig file), and
Environments are represented as a hierarchy in the 'environments' directory of a Environments are represented as a hierarchy in the 'environments' directory of a
ksonnet application. For example, in the example below, there are two ksonnet application. For example, in the example below, there are two
environments: 'default' and 'us-west/staging'. Each contains a cached version of environments: 'default' and 'us-west/staging'. Each contains a cached version of
ksonnet-lib, and a 'spec.json' that contains the URI and server cert that ksonnet-lib, and a 'spec.json' that contains the server and server cert that
uniquely identifies the cluster. uniquely identifies the cluster.
environments/ environments/
...@@ -97,7 +85,7 @@ environments/ ...@@ -97,7 +85,7 @@ environments/
k.libsonnet k.libsonnet
k8s.libsonnet k8s.libsonnet
swagger.json swagger.json
spec.json [This will contain the uri of the environment and other environment metadata] spec.json [This will contain the API server address of the environment and other environment metadata]
staging.jsonnet`, staging.jsonnet`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Command 'env' requires a subcommand\n\n%s", cmd.UsageString()) return fmt.Errorf("Command 'env' requires a subcommand\n\n%s", cmd.UsageString())
...@@ -115,7 +103,7 @@ var envAddCmd = &cobra.Command{ ...@@ -115,7 +103,7 @@ var envAddCmd = &cobra.Command{
name := args[0] name := args[0]
uri, namespace, context, err := commonEnvFlags(flags) server, namespace, context, err := commonEnvFlags(flags)
if err != nil { if err != nil {
return err return err
} }
...@@ -124,8 +112,8 @@ var envAddCmd = &cobra.Command{ ...@@ -124,8 +112,8 @@ var envAddCmd = &cobra.Command{
namespace = defaultNamespace namespace = defaultNamespace
} }
if len(uri) == 0 { if len(server) == 0 {
// If uri is not provided, use the provided context. // If server is not provided, use the provided context.
// If context is also not provided, use the current context. // If context is also not provided, use the current context.
var ctx *string var ctx *string
if len(context) != 0 { if len(context) != 0 {
...@@ -133,7 +121,7 @@ var envAddCmd = &cobra.Command{ ...@@ -133,7 +121,7 @@ var envAddCmd = &cobra.Command{
} }
var ns string var ns string
uri, ns, err = resolveContext(ctx) server, ns, err = resolveContext(ctx)
if err != nil { if err != nil {
return err return err
} }
...@@ -160,7 +148,7 @@ var envAddCmd = &cobra.Command{ ...@@ -160,7 +148,7 @@ var envAddCmd = &cobra.Command{
return err return err
} }
c, err := kubecfg.NewEnvAddCmd(name, uri, namespace, specFlag, manager) c, err := kubecfg.NewEnvAddCmd(name, server, namespace, specFlag, manager)
if err != nil { if err != nil {
return err return err
} }
...@@ -195,7 +183,7 @@ environments/ ...@@ -195,7 +183,7 @@ environments/
k.libsonnet k.libsonnet
k8s.libsonnet k8s.libsonnet
swagger.json swagger.json
spec.json [This will contain the uri of the environment and other environment metadata], spec.json [This will contain the API server address of the environment and other environment metadata],
staging.jsonnet`, staging.jsonnet`,
Example: ` # Initialize a new staging environment at 'us-west'. Example: ` # Initialize a new staging environment at 'us-west'.
# The environment will be setup using the current context in your kubecfg file. The directory # The environment will be setup using the current context in your kubecfg file. The directory
...@@ -209,8 +197,8 @@ environments/ ...@@ -209,8 +197,8 @@ environments/
# Initialize a new environment using the 'dev' context in your kubeconfig file. # Initialize a new environment using the 'dev' context in your kubeconfig file.
ks env add my-env --context=dev ks env add my-env --context=dev
# Initialize a new environment using a server URI. # Initialize a new environment using a server address.
ks env add my-env --uri=https://ksonnet-1.us-west.elb.amazonaws.com`, ks env add my-env --server=https://ksonnet-1.us-west.elb.amazonaws.com`,
} }
var envRmCmd = &cobra.Command{ var envRmCmd = &cobra.Command{
...@@ -279,12 +267,12 @@ var envListCmd = &cobra.Command{ ...@@ -279,12 +267,12 @@ var envListCmd = &cobra.Command{
return c.Run(cmd.OutOrStdout()) return c.Run(cmd.OutOrStdout())
}, Long: `List all environments in a ksonnet project. This will }, Long: `List all environments in a ksonnet project. This will
display the name, URI, and namespace of each environment within the ksonnet project.`, display the name, server, and namespace of each environment within the ksonnet project.`,
} }
var envSetCmd = &cobra.Command{ var envSetCmd = &cobra.Command{
Use: "set <env-name>", Use: "set <env-name>",
Short: "Set environment fields such as the name, cluster URI, and namespace.", Short: "Set environment fields such as the name, server, and namespace.",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
flags := cmd.Flags() flags := cmd.Flags()
if len(args) != 1 { if len(args) != 1 {
...@@ -309,7 +297,7 @@ var envSetCmd = &cobra.Command{ ...@@ -309,7 +297,7 @@ var envSetCmd = &cobra.Command{
return err return err
} }
uri, namespace, context, err := commonEnvFlags(flags) server, namespace, context, err := commonEnvFlags(flags)
if err != nil { if err != nil {
return err return err
} }
...@@ -320,39 +308,39 @@ var envSetCmd = &cobra.Command{ ...@@ -320,39 +308,39 @@ var envSetCmd = &cobra.Command{
} }
if len(context) != 0 { if len(context) != 0 {
uri, _, err = resolveContext(&context) server, _, err = resolveContext(&context)
if err != nil { if err != nil {
return err return err
} }
} }
c, err := kubecfg.NewEnvSetCmd(originalName, name, uri, namespace, manager) c, err := kubecfg.NewEnvSetCmd(originalName, name, server, namespace, manager)
if err != nil { if err != nil {
return err return err
} }
return c.Run() return c.Run()
}, },
Long: `Set environment fields such as the name, and cluster URI. Changing Long: `Set environment fields such as the name, and server. Changing
the name of an environment will also update the directory structure in the name of an environment will also update the directory structure in
'environments'.`, 'environments'.`,
Example: ` # Updates the URI of the environment 'us-west/staging'. Example: ` # Updates the API server address of the environment 'us-west/staging'.
ks env set us-west/staging --uri=http://example.com ks env set us-west/staging --server=http://example.com
# Updates the namespace of the environment 'us-west/staging'. # Updates the namespace of the environment 'us-west/staging'.
ks 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'. # Updates both the name and the server of the environment 'us-west/staging'.
# Updating the name will update the directory structure in 'environments'. # Updating the name will update the directory structure in 'environments'.
ks env set us-west/staging --uri=http://example.com --name=us-east/staging ks env set us-west/staging --server=http://example.com --name=us-east/staging
# Updates URI of the environment 'us-west/staging' based on the server URI # Updates API server address of the environment 'us-west/staging' based on the
# in the context 'staging-west' in your kubeconfig file. # server in the context 'staging-west' in your kubeconfig file.
ks env set us-west/staging --context=staging-west`, ks env set us-west/staging --context=staging-west`,
} }
func commonEnvFlags(flags *pflag.FlagSet) (uri, namespace, context string, err error) { func commonEnvFlags(flags *pflag.FlagSet) (server, namespace, context string, err error) {
uri, err = flags.GetString(flagEnvURI) server, err = flags.GetString(flagEnvServer)
if err != nil { if err != nil {
return "", "", "", err return "", "", "", err
} }
...@@ -367,10 +355,10 @@ func commonEnvFlags(flags *pflag.FlagSet) (uri, namespace, context string, err e ...@@ -367,10 +355,10 @@ func commonEnvFlags(flags *pflag.FlagSet) (uri, namespace, context string, err e
return "", "", "", err return "", "", "", err
} }
if flags.Changed(flagEnvContext) && flags.Changed(flagEnvURI) { if flags.Changed(flagEnvContext) && flags.Changed(flagEnvServer) {
return "", "", "", fmt.Errorf("flags '%s' and '%s' are mutually exclusive, because '%s' has a URI. Try setting '%s', '%s' to the desired values", return "", "", "", fmt.Errorf("flags '%s' and '%s' are mutually exclusive, because '%s' has a server. Try setting '%s', '%s' to the desired values",
flagEnvContext, flagEnvURI, flagEnvContext, flagEnvURI, flagEnvNamespace) flagEnvContext, flagEnvServer, flagEnvContext, flagEnvServer, flagEnvNamespace)
} }
return uri, namespace, context, nil return server, namespace, context, nil
} }
...@@ -132,9 +132,9 @@ func namespaceFor(c clientcmd.ClientConfig, overrides clientcmd.ConfigOverrides) ...@@ -132,9 +132,9 @@ func namespaceFor(c clientcmd.ClientConfig, overrides clientcmd.ConfigOverrides)
return ns, err return ns, err
} }
// resolveContext returns the server URI and namespace of the cluster at the provided // resolveContext returns the server and namespace of the cluster at the provided
// context. If context is nil, the current context is used. // context. If context is nil, the current context is used.
func resolveContext(context *string) (uri, namespace string, err error) { func resolveContext(context *string) (server, namespace string, err error) {
rawConfig, err := clientConfig.RawConfig() rawConfig, err := clientConfig.RawConfig()
if err != nil { if err != nil {
return "", "", err return "", "", err
...@@ -319,11 +319,11 @@ func parseEnvCmd(cmd *cobra.Command, args []string) (*envSpec, error) { ...@@ -319,11 +319,11 @@ func parseEnvCmd(cmd *cobra.Command, args []string) (*envSpec, error) {
return &envSpec{env: env, files: files}, nil return &envSpec{env: env, files: files}, nil
} }
// overrideCluster ensures that the cluster URI specified in the environment is // overrideCluster ensures that the server specified in the environment is
// associated in the user's kubeconfig file during deployment to a ksonnet // associated in the user's kubeconfig file during deployment to a ksonnet
// environment. We will error out if it is not. // environment. We will error out if it is not.
// //
// If the environment URI the user is attempting to deploy to is not the current // If the environment server the user is attempting to deploy to is not the current
// kubeconfig context, we must manually override the client-go --cluster flag // kubeconfig context, we must manually override the client-go --cluster flag
// to ensure we are deploying to the correct cluster. // to ensure we are deploying to the correct cluster.
func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overrides clientcmd.ConfigOverrides) error { func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overrides clientcmd.ConfigOverrides) error {
...@@ -343,24 +343,24 @@ func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overri ...@@ -343,24 +343,24 @@ func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overri
return err return err
} }
var clusterURIs = make(map[string]string) var servers = make(map[string]string)
for name, cluster := range rawConfig.Clusters { for name, cluster := range rawConfig.Clusters {
clusterURIs[cluster.Server] = name servers[cluster.Server] = name
} }
// //
// check to ensure that the environment we are trying to deploy to is // check to ensure that the environment we are trying to deploy to is
// created, and that the environment URI is located in kubeconfig. // created, and that the server is located in kubeconfig.
// //
log.Debugf("Validating deployment at '%s' with cluster URIs '%v'", envName, reflect.ValueOf(clusterURIs).MapKeys()) log.Debugf("Validating deployment at '%s' with server '%v'", envName, reflect.ValueOf(servers).MapKeys())
env, err := metadataManager.GetEnvironment(envName) env, err := metadataManager.GetEnvironment(envName)
if err != nil { if err != nil {
return err return err
} }
if _, ok := clusterURIs[env.URI]; ok { if _, ok := servers[env.Server]; ok {
clusterName := clusterURIs[env.URI] clusterName := servers[env.Server]
log.Debugf("Overwriting --cluster flag with '%s'", clusterName) log.Debugf("Overwriting --cluster flag with '%s'", clusterName)
overrides.Context.Cluster = clusterName overrides.Context.Cluster = clusterName
log.Debugf("Overwriting --namespace flag with '%s'", env.Namespace) log.Debugf("Overwriting --namespace flag with '%s'", env.Namespace)
...@@ -368,7 +368,7 @@ func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overri ...@@ -368,7 +368,7 @@ func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overri
return nil return nil
} }
return fmt.Errorf("Attempting to operate on environment '%s' at %s, but there are no clusters with that URI", envName, env.URI) return fmt.Errorf("Attempting to deploy to environment '%s' at '%s', but cannot locate a server at that address", envName, env.Server)
} }
// expandEnvCmdObjs finds and expands templates for the family of commands of // expandEnvCmdObjs finds and expands templates for the family of commands of
......
...@@ -45,31 +45,31 @@ const ( ...@@ -45,31 +45,31 @@ const (
type Environment struct { type Environment struct {
Path string Path string
Name string Name string
URI string Server string
Namespace string Namespace string
} }
// EnvironmentSpec represents the contents in spec.json. // EnvironmentSpec represents the contents in spec.json.
type EnvironmentSpec struct { type EnvironmentSpec struct {
URI string `json:"uri"` Server string `json:"server"`
Namespace string `json:"namespace"` Namespace string `json:"namespace"`
} }
func (m *manager) CreateEnvironment(name, uri, namespace string, spec ClusterSpec) error { func (m *manager) CreateEnvironment(name, server, namespace string, spec ClusterSpec) error {
extensionsLibData, k8sLibData, specData, err := m.generateKsonnetLibData(spec) extensionsLibData, k8sLibData, specData, err := m.generateKsonnetLibData(spec)
if err != nil { if err != nil {
log.Debugf("Failed to write '%s'", specFilename) log.Debugf("Failed to write '%s'", specFilename)
return err return err
} }
err = m.createEnvironment(name, uri, namespace, extensionsLibData, k8sLibData, specData) err = m.createEnvironment(name, server, namespace, extensionsLibData, k8sLibData, specData)
if err == nil { if err == nil {
log.Infof("Environment '%s' pointing to namespace '%s' and cluster at URI '%s' successfully created", name, namespace, uri) log.Infof("Environment '%s' pointing to namespace '%s' and server address at '%s' successfully created", name, namespace, server)
} }
return err return err
} }
func (m *manager) createEnvironment(name, uri, namespace string, extensionsLibData, k8sLibData, specData []byte) error { func (m *manager) createEnvironment(name, server, namespace string, extensionsLibData, k8sLibData, specData []byte) error {
exists, err := m.environmentExists(name) exists, err := m.environmentExists(name)
if err != nil { if err != nil {
log.Debug("Failed to check whether environment exists") log.Debug("Failed to check whether environment exists")
...@@ -84,7 +84,7 @@ func (m *manager) createEnvironment(name, uri, namespace string, extensionsLibDa ...@@ -84,7 +84,7 @@ func (m *manager) createEnvironment(name, uri, namespace string, extensionsLibDa
return fmt.Errorf("Environment name '%s' is not valid; must not contain punctuation, spaces, or begin or end with a slash", name) return fmt.Errorf("Environment name '%s' is not valid; must not contain punctuation, spaces, or begin or end with a slash", name)
} }
log.Infof("Creating environment '%s' with namespace '%s', pointing at cluster located at uri '%s'", name, namespace, uri) log.Infof("Creating environment '%s' with namespace '%s', pointing at server at address '%s'", name, namespace, server)
envPath := appendToAbsPath(m.environmentsPath, name) envPath := appendToAbsPath(m.environmentsPath, name)
err = m.appFS.MkdirAll(string(envPath), defaultFolderPermissions) err = m.appFS.MkdirAll(string(envPath), defaultFolderPermissions)
...@@ -137,7 +137,7 @@ func (m *manager) createEnvironment(name, uri, namespace string, extensionsLibDa ...@@ -137,7 +137,7 @@ func (m *manager) createEnvironment(name, uri, namespace string, extensionsLibDa
} }
// Generate the environment spec file. // Generate the environment spec file.
envSpecData, err := generateSpecData(uri, namespace) envSpecData, err := generateSpecData(server, namespace)
if err != nil { if err != nil {
return err return err
} }
...@@ -227,8 +227,8 @@ func (m *manager) GetEnvironments() ([]*Environment, error) { ...@@ -227,8 +227,8 @@ func (m *manager) GetEnvironments() ([]*Environment, error) {
return err return err
} }
log.Debugf("Found environment '%s', with uri '%s' and namespace '%s'", envName, envSpec.URI, envSpec.Namespace) log.Debugf("Found environment '%s', with server '%s' and namespace '%s'", envName, envSpec.Server, envSpec.Namespace)
envs = append(envs, &Environment{Name: envName, Path: path, URI: envSpec.URI, Namespace: envSpec.Namespace}) envs = append(envs, &Environment{Name: envName, Path: path, Server: envSpec.Server, Namespace: envSpec.Namespace})
} }
} }
...@@ -300,12 +300,12 @@ func (m *manager) SetEnvironment(name string, desired *Environment) error { ...@@ -300,12 +300,12 @@ func (m *manager) SetEnvironment(name string, desired *Environment) error {
// Update fields in spec.json. // Update fields in spec.json.
// //
var URI string var server string
if len(desired.URI) != 0 { if len(desired.Server) != 0 {
log.Infof("Setting environment URI to '%s'", desired.URI) log.Infof("Setting environment server to '%s'", desired.Server)
URI = desired.URI server = desired.Server
} else { } else {
URI = env.URI server = env.Server
} }
var namespace string var namespace string
if len(desired.Namespace) != 0 { if len(desired.Namespace) != 0 {
...@@ -315,9 +315,9 @@ func (m *manager) SetEnvironment(name string, desired *Environment) error { ...@@ -315,9 +315,9 @@ func (m *manager) SetEnvironment(name string, desired *Environment) error {
namespace = env.Namespace namespace = env.Namespace
} }
newSpec, err := generateSpecData(URI, namespace) newSpec, err := generateSpecData(server, namespace)
if err != nil { if err != nil {
log.Debugf("Failed to generate %s with URI '%s' and namespace '%s'", specFilename, URI, namespace) log.Debugf("Failed to generate %s with server '%s' and namespace '%s'", specFilename, server, namespace)
return err return err
} }
...@@ -369,9 +369,9 @@ func (m *manager) generateOverrideData() []byte { ...@@ -369,9 +369,9 @@ func (m *manager) generateOverrideData() []byte {
return buf.Bytes() return buf.Bytes()
} }
func generateSpecData(uri, namespace string) ([]byte, error) { func generateSpecData(server, namespace string) ([]byte, error) {
// Format the spec json and return; preface keys with 2 space idents. // Format the spec json and return; preface keys with 2 space idents.
return json.MarshalIndent(EnvironmentSpec{URI: uri, Namespace: namespace}, "", " ") return json.MarshalIndent(EnvironmentSpec{Server: server, Namespace: namespace}, "", " ")
} }
func (m *manager) environmentExists(name string) (bool, error) { func (m *manager) environmentExists(name string) (bool, error) {
......
...@@ -26,15 +26,15 @@ import ( ...@@ -26,15 +26,15 @@ import (
) )
const ( const (
mockSpecJSON = "spec.json" mockSpecJSON = "spec.json"
mockSpecJSONURI = "localhost:8080" mockSpecJSONServer = "localhost:8080"
mockEnvName = "us-west/test" mockEnvName = "us-west/test"
mockEnvName2 = "us-west/prod" mockEnvName2 = "us-west/prod"
mockEnvName3 = "us-east/test" mockEnvName3 = "us-east/test"
) )
var mockAPIServerURI = "http://google.com" var mockAPIServer = "http://example.com"
var mockNamespace = "some-namespace" var mockNamespace = "some-namespace"
func mockEnvironments(t *testing.T, appName string) *manager { func mockEnvironments(t *testing.T, appName string) *manager {
...@@ -44,7 +44,7 @@ func mockEnvironments(t *testing.T, appName string) *manager { ...@@ -44,7 +44,7 @@ func mockEnvironments(t *testing.T, appName string) *manager {
} }
appPath := AbsPath(appName) appPath := AbsPath(appName)
m, err := initManager(appPath, spec, &mockAPIServerURI, &mockNamespace, testFS) m, err := initManager(appPath, spec, &mockAPIServer, &mockNamespace, testFS)
if err != nil { if err != nil {
t.Fatalf("Failed to init cluster spec: %v", err) t.Fatalf("Failed to init cluster spec: %v", err)
} }
...@@ -54,9 +54,9 @@ func mockEnvironments(t *testing.T, appName string) *manager { ...@@ -54,9 +54,9 @@ func mockEnvironments(t *testing.T, appName string) *manager {
envPath := appendToAbsPath(m.environmentsPath, env) envPath := appendToAbsPath(m.environmentsPath, env)
specPath := appendToAbsPath(envPath, mockSpecJSON) specPath := appendToAbsPath(envPath, mockSpecJSON)
specData, err := generateSpecData(mockSpecJSONURI, mockNamespace) specData, err := generateSpecData(mockSpecJSONServer, mockNamespace)
if err != nil { if err != nil {
t.Fatalf("Expected to marshal:\nuri: %s\nnamespace: %s\n, but failed", mockSpecJSONURI, mockNamespace) t.Fatalf("Expected to marshal:\nserver: %s\nnamespace: %s\n, but failed", mockSpecJSONServer, mockNamespace)
} }
err = afero.WriteFile(testFS, string(specPath), specData, os.ModePerm) err = afero.WriteFile(testFS, string(specPath), specData, os.ModePerm)
if err != nil { if err != nil {
...@@ -126,8 +126,8 @@ func TestGetEnvironments(t *testing.T) { ...@@ -126,8 +126,8 @@ func TestGetEnvironments(t *testing.T) {
t.Fatalf("Expected to get %d environments, got %d", 4, len(envs)) t.Fatalf("Expected to get %d environments, got %d", 4, len(envs))
} }
if envs[0].URI != mockSpecJSONURI { if envs[0].Server != mockSpecJSONServer {
t.Fatalf("Expected env URI to be %s, got %s", mockSpecJSONURI, envs[0].URI) t.Fatalf("Expected env server to be %s, got %s", mockSpecJSONServer, envs[0].Server)
} }
} }
...@@ -136,9 +136,9 @@ func TestSetEnvironment(t *testing.T) { ...@@ -136,9 +136,9 @@ func TestSetEnvironment(t *testing.T) {
m := mockEnvironments(t, appName) m := mockEnvironments(t, appName)
setName := "new-env" setName := "new-env"
setURI := "http://example.com" setServer := "http://example.com"
setNamespace := "some-namespace" setNamespace := "some-namespace"
set := Environment{Name: setName, URI: setURI, Namespace: setNamespace} set := Environment{Name: setName, Server: setServer, Namespace: setNamespace}
// Test updating an environment that doesn't exist // Test updating an environment that doesn't exist
err := m.SetEnvironment("notexists", &set) err := m.SetEnvironment("notexists", &set)
...@@ -152,9 +152,9 @@ func TestSetEnvironment(t *testing.T) { ...@@ -152,9 +152,9 @@ func TestSetEnvironment(t *testing.T) {
t.Fatalf("Expected error when setting \"%s\" to \"%s\", because env already exists", mockEnvName, mockEnvName2) t.Fatalf("Expected error when setting \"%s\" to \"%s\", because env already exists", mockEnvName, mockEnvName2)
} }
// Test changing the name and URI of a an existing environment. // Test changing the name and server of a an existing environment.
// Ensure new env directory is created, and old directory no longer exists. // Ensure new env directory is created, and old directory no longer exists.
// Also ensure URI is set in spec.json // Also ensure server is set in spec.json
err = m.SetEnvironment(mockEnvName, &set) err = m.SetEnvironment(mockEnvName, &set)
if err != nil { if err != nil {
t.Fatalf("Could not set \"%s\", got:\n %s", mockEnvName, err) t.Fatalf("Could not set \"%s\", got:\n %s", mockEnvName, err)
...@@ -178,11 +178,11 @@ func TestSetEnvironment(t *testing.T) { ...@@ -178,11 +178,11 @@ func TestSetEnvironment(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed to read spec file:\n %s", err) t.Fatalf("Failed to read spec file:\n %s", err)
} }
if envSpec.URI != set.URI { if envSpec.Server != set.Server {
t.Fatalf("Expected set URI to be \"%s\", got:\n %s", set.URI, envSpec.URI) t.Fatalf("Expected server to be set to '%s', got: '%s'", set.Server, envSpec.Server)
} }
if envSpec.Namespace != set.Namespace { if envSpec.Namespace != set.Namespace {
t.Fatalf("Expected set Namespace to be \"%s\", got:\n %s", set.Namespace, envSpec.Namespace) t.Fatalf("Expected namespace to be set to '%s', got: '%s'", set.Namespace, envSpec.Namespace)
} }
} }
......
...@@ -60,7 +60,7 @@ func TestInitSuccess(t *testing.T) { ...@@ -60,7 +60,7 @@ func TestInitSuccess(t *testing.T) {
} }
appPath := AbsPath("/fromEmptySwagger") appPath := AbsPath("/fromEmptySwagger")
_, err = initManager(appPath, spec, &mockAPIServerURI, &mockNamespace, testFS) _, err = initManager(appPath, spec, &mockAPIServer, &mockNamespace, testFS)
if err != nil { if err != nil {
t.Fatalf("Failed to init cluster spec: %v", err) t.Fatalf("Failed to init cluster spec: %v", err)
} }
...@@ -137,7 +137,7 @@ func TestFindSuccess(t *testing.T) { ...@@ -137,7 +137,7 @@ func TestFindSuccess(t *testing.T) {
} }
appPath := AbsPath("/findSuccess") appPath := AbsPath("/findSuccess")
_, err = initManager(appPath, spec, &mockAPIServerURI, &mockNamespace, testFS) _, err = initManager(appPath, spec, &mockAPIServer, &mockNamespace, testFS)
if err != nil { if err != nil {
t.Fatalf("Failed to init cluster spec: %v", err) t.Fatalf("Failed to init cluster spec: %v", err)
} }
...@@ -165,7 +165,7 @@ func TestComponentPaths(t *testing.T) { ...@@ -165,7 +165,7 @@ func TestComponentPaths(t *testing.T) {
} }
appPath := AbsPath("/componentPaths") appPath := AbsPath("/componentPaths")
m, err := initManager(appPath, spec, &mockAPIServerURI, &mockNamespace, testFS) m, err := initManager(appPath, spec, &mockAPIServer, &mockNamespace, testFS)
if err != nil { if err != nil {
t.Fatalf("Failed to init cluster spec: %v", err) t.Fatalf("Failed to init cluster spec: %v", err)
} }
...@@ -251,13 +251,13 @@ func TestDoubleNewFailure(t *testing.T) { ...@@ -251,13 +251,13 @@ func TestDoubleNewFailure(t *testing.T) {
appPath := AbsPath("/doubleNew") appPath := AbsPath("/doubleNew")
_, err = initManager(appPath, spec, &mockAPIServerURI, &mockNamespace, testFS) _, err = initManager(appPath, spec, &mockAPIServer, &mockNamespace, testFS)
if err != nil { if err != nil {
t.Fatalf("Failed to init cluster spec: %v", err) t.Fatalf("Failed to init cluster spec: %v", err)
} }
targetErr := fmt.Sprintf("Could not create app; directory '%s' already exists", appPath) targetErr := fmt.Sprintf("Could not create app; directory '%s' already exists", appPath)
_, err = initManager(appPath, spec, &mockAPIServerURI, &mockNamespace, testFS) _, err = initManager(appPath, spec, &mockAPIServer, &mockNamespace, testFS)
if err == nil || err.Error() != targetErr { if err == nil || err.Error() != targetErr {
t.Fatalf("Expected to fail to create app with message '%s', got '%s'", targetErr, err.Error()) t.Fatalf("Expected to fail to create app with message '%s', got '%s'", targetErr, err.Error())
} }
......
...@@ -28,25 +28,25 @@ import ( ...@@ -28,25 +28,25 @@ import (
type EnvAddCmd struct { type EnvAddCmd struct {
name string name string
uri string server string
namespace string namespace string
spec metadata.ClusterSpec spec metadata.ClusterSpec
manager metadata.Manager manager metadata.Manager
} }
func NewEnvAddCmd(name, uri, namespace, specFlag string, manager metadata.Manager) (*EnvAddCmd, error) { func NewEnvAddCmd(name, server, namespace, specFlag string, manager metadata.Manager) (*EnvAddCmd, error) {
spec, err := metadata.ParseClusterSpec(specFlag) spec, err := metadata.ParseClusterSpec(specFlag)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Debugf("Generating ksonnetLib data with spec: %s", specFlag) log.Debugf("Generating ksonnetLib data with spec: %s", specFlag)
return &EnvAddCmd{name: name, uri: uri, namespace: namespace, spec: spec, manager: manager}, nil return &EnvAddCmd{name: name, server: server, namespace: namespace, spec: spec, manager: manager}, nil
} }
func (c *EnvAddCmd) Run() error { func (c *EnvAddCmd) Run() error {
return c.manager.CreateEnvironment(c.name, c.uri, c.namespace, c.spec) return c.manager.CreateEnvironment(c.name, c.server, c.namespace, c.spec)
} }
// ================================================================== // ==================================================================
...@@ -79,7 +79,7 @@ func (c *EnvListCmd) Run(out io.Writer) error { ...@@ -79,7 +79,7 @@ func (c *EnvListCmd) Run(out io.Writer) error {
const ( const (
nameHeader = "NAME" nameHeader = "NAME"
namespaceHeader = "NAMESPACE" namespaceHeader = "NAMESPACE"
uriHeader = "URI" serverHeader = "SERVER"
) )
envs, err := c.manager.GetEnvironments() envs, err := c.manager.GetEnvironments()
...@@ -93,7 +93,7 @@ func (c *EnvListCmd) Run(out io.Writer) error { ...@@ -93,7 +93,7 @@ func (c *EnvListCmd) Run(out io.Writer) error {
// Format each environment information for pretty printing. // Format each environment information for pretty printing.
// Each environment should be outputted like the following: // Each environment should be outputted like the following:
// //
// NAME NAMESPACE URI // NAME NAMESPACE SERVER
// minikube dev localhost:8080 // minikube dev localhost:8080
// us-west/staging staging http://example.com // us-west/staging staging http://example.com
// //
...@@ -118,12 +118,12 @@ func (c *EnvListCmd) Run(out io.Writer) error { ...@@ -118,12 +118,12 @@ func (c *EnvListCmd) Run(out io.Writer) error {
headerNameSpacing := strings.Repeat(" ", maxNameLen-len(nameHeader)+1) headerNameSpacing := strings.Repeat(" ", maxNameLen-len(nameHeader)+1)
headerNamespaceSpacing := strings.Repeat(" ", maxNamespaceLen-maxNameLen-len(namespaceHeader)) headerNamespaceSpacing := strings.Repeat(" ", maxNamespaceLen-maxNameLen-len(namespaceHeader))
lines = append(lines, nameHeader+headerNameSpacing+namespaceHeader+headerNamespaceSpacing+uriHeader+"\n") lines = append(lines, nameHeader+headerNameSpacing+namespaceHeader+headerNamespaceSpacing+serverHeader+"\n")
for _, env := range envs { for _, env := range envs {
nameSpacing := strings.Repeat(" ", maxNameLen-len(env.Name)+1) nameSpacing := strings.Repeat(" ", maxNameLen-len(env.Name)+1)
namespaceSpacing := strings.Repeat(" ", maxNamespaceLen-maxNameLen-len(env.Namespace)) namespaceSpacing := strings.Repeat(" ", maxNamespaceLen-maxNameLen-len(env.Namespace))
lines = append(lines, env.Name+nameSpacing+env.Namespace+namespaceSpacing+env.URI+"\n") lines = append(lines, env.Name+nameSpacing+env.Namespace+namespaceSpacing+env.Server+"\n")
} }
formattedEnvsList := strings.Join(lines, "") formattedEnvsList := strings.Join(lines, "")
...@@ -138,18 +138,18 @@ type EnvSetCmd struct { ...@@ -138,18 +138,18 @@ type EnvSetCmd struct {
name string name string
desiredName string desiredName string
desiredURI string desiredServer string
desiredNamespace string desiredNamespace string
manager metadata.Manager manager metadata.Manager
} }
func NewEnvSetCmd(name, desiredName, desiredURI, desiredNamespace string, manager metadata.Manager) (*EnvSetCmd, error) { func NewEnvSetCmd(name, desiredName, desiredServer, desiredNamespace string, manager metadata.Manager) (*EnvSetCmd, error) {
return &EnvSetCmd{name: name, desiredName: desiredName, desiredURI: desiredURI, desiredNamespace: desiredNamespace, return &EnvSetCmd{name: name, desiredName: desiredName, desiredServer: desiredServer, desiredNamespace: desiredNamespace,
manager: manager}, nil manager: manager}, nil
} }
func (c *EnvSetCmd) Run() error { func (c *EnvSetCmd) Run() error {
desired := metadata.Environment{Name: c.desiredName, URI: c.desiredURI, Namespace: c.desiredNamespace} desired := metadata.Environment{Name: c.desiredName, Server: c.desiredServer, Namespace: c.desiredNamespace}
return c.manager.SetEnvironment(c.name, &desired) return c.manager.SetEnvironment(c.name, &desired)
} }
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