Commit b10a0a80 authored by Jessica Yuen's avatar Jessica Yuen
Browse files

Fix the execution paths for the 0.8 > 0.9 migration warning



Currently the warning is only displayed on 'apply'. Other commands
should also show this warning. Logic should also be handled internally
instead of being exposed at the interface level.
Signed-off-by: default avatarJessica Yuen <im.jessicayuen@gmail.com>
parent cd2592ec
......@@ -603,6 +603,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "f44fb422720ed1d7e1a654a9c4b6f6d9baa90492bb28c459bf30552527255e83"
inputs-digest = "8b786abd404b80a5933fdf9b29cae67837bf6630041f144bffd7092fdb0e331c"
solver-name = "gps-cdcl"
solver-version = 1
......@@ -22,7 +22,6 @@ import (
"github.com/spf13/cobra"
"github.com/ksonnet/ksonnet/client"
"github.com/ksonnet/ksonnet/metadata"
"github.com/ksonnet/ksonnet/pkg/kubecfg"
)
......@@ -125,21 +124,6 @@ var applyCmd = &cobra.Command{
return err
}
// TODO remove after 1.0.0
// We are ensuring here that users aren't running a deprecated ksonnet
// app structure against a newer version of ks.
appDir, err := os.Getwd()
if err != nil {
return err
}
manager, err := metadata.Find(appDir)
if err != nil {
return err
}
if err := manager.ErrorOnSpecFile(); err != nil {
return err
}
return c.Run(objs, cwd)
},
Long: `
......
......@@ -65,7 +65,11 @@ func (m *manager) CreateEnvironment(name, server, namespace, k8sSpecFlag string)
return err
}
if _, exists := appSpec.GetEnvironmentSpec(name); exists {
exists, err := m.environmentExists(name)
if err != nil {
return err
}
if exists {
return fmt.Errorf("Environment '%s' already exists", name)
}
......@@ -135,9 +139,9 @@ func (m *manager) DeleteEnvironment(name string) error {
return err
}
env, ok := app.GetEnvironmentSpec(name)
if !ok {
return fmt.Errorf("Environment '%s' does not exist", name)
env, err := m.GetEnvironment(name)
if err != nil {
return err
}
envPath := str.AppendToPath(m.environmentsPath, env.Path)
......@@ -168,6 +172,10 @@ func (m *manager) DeleteEnvironment(name string) error {
}
func (m *manager) GetEnvironments() (app.EnvironmentSpecs, error) {
if err := m.errorOnSpecFile(); err != nil {
return nil, err
}
app, err := m.AppSpec()
if err != nil {
return nil, err
......@@ -178,6 +186,10 @@ func (m *manager) GetEnvironments() (app.EnvironmentSpecs, error) {
}
func (m *manager) GetEnvironment(name string) (*app.EnvironmentSpec, error) {
if err := m.errorOnSpecFile(); err != nil {
return nil, err
}
app, err := m.AppSpec()
if err != nil {
return nil, err
......@@ -223,9 +235,9 @@ func (m *manager) SetEnvironment(name, desiredName string) error {
return err
}
current, exists := appSpec.GetEnvironmentSpec(name)
if !exists {
return fmt.Errorf("Trying to update an environment that doesn't exist")
current, err := m.GetEnvironment(name)
if err != nil {
return err
}
err = appSpec.UpdateEnvironmentSpec(name, &app.EnvironmentSpec{
......@@ -247,7 +259,7 @@ func (m *manager) SetEnvironment(name, desiredName string) error {
pathOld := str.AppendToPath(m.environmentsPath, name)
pathNew := str.AppendToPath(m.environmentsPath, desiredName)
exists, err = afero.DirExists(m.appFS, pathNew)
exists, err := afero.DirExists(m.appFS, pathNew)
if err != nil {
return err
}
......@@ -359,17 +371,11 @@ func (m *manager) SetEnvironmentParams(env, component string, params param.Param
}
func (m *manager) EnvPaths(env string) (libPath, mainPath, paramsPath string, err error) {
app, err := m.AppSpec()
envSpec, err := m.GetEnvironment(env)
if err != nil {
return
}
envSpec, ok := app.GetEnvironmentSpec(env)
if !ok {
err = fmt.Errorf("Environment '%s' does not exist", env)
return
}
libManager := lib.NewManager(envSpec.KubernetesVersion, m.appFS, m.libPath)
envPath := str.AppendToPath(m.environmentsPath, env)
......@@ -383,7 +389,9 @@ func (m *manager) EnvPaths(env string) (libPath, mainPath, paramsPath string, er
return
}
func (m *manager) ErrorOnSpecFile() error {
// errorOnSpec file is a temporary function to help migration from ks 0.8 to 0.9.
// It will return an error if a spec.json file is found in an environment directory.
func (m *manager) errorOnSpecFile() error {
return afero.Walk(m.appFS, m.environmentsPath, func(p string, f os.FileInfo, err error) error {
if err != nil {
log.Debugf("Failed to walk path %s", p)
......@@ -498,6 +506,10 @@ func (m *manager) environmentExists(name string) (bool, error) {
return false, err
}
if err := m.errorOnSpecFile(); err != nil {
return false, err
}
_, ok := appSpec.GetEnvironmentSpec(name)
return ok, nil
}
......
......@@ -63,8 +63,6 @@ type Manager interface {
GetEnvironments() (app.EnvironmentSpecs, error)
GetEnvironment(name string) (*app.EnvironmentSpec, error)
SetEnvironment(name, desiredName string) error
// ErrorOnSpecFile is a temporary API to inform < 0.9.0 ks users of environment directory changes.
ErrorOnSpecFile() error
// Spec API.
AppSpec() (*app.Spec, error)
......
{
"server": "example.com",
"namespace": "example-ns"
}
\ No newline at end of file
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