Skip to content
Snippets Groups Projects
Commit 03c307ef authored by Jessica Yuen's avatar Jessica Yuen
Browse files

Add warning for running deprecated ks app against ks >= 0.9.0


This is a temporary piece of code that should be removed after 1.0.0.

This warning exists to tell users that are using ks < 0.9.0 with the
dated environments model (contains the 'spec.json' file), to migrate to
the newer 'app.yaml' model.

Signed-off-by: default avatarJessica Yuen <im.jessicayuen@gmail.com>
parent 074f7e64
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ import (
"github.com/spf13/cobra"
"github.com/ksonnet/ksonnet/client"
"github.com/ksonnet/ksonnet/metadata"
"github.com/ksonnet/ksonnet/pkg/kubecfg"
)
......@@ -124,6 +125,21 @@ 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: `
......
......@@ -385,6 +385,34 @@ func (m *manager) EnvPaths(env string) (libPath, mainPath, paramsPath string, er
return
}
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)
return err
}
isDir, err := afero.IsDir(m.appFS, p)
if err != nil {
log.Debugf("Failed to check whether the path at %s is a directory", p)
return err
}
if isDir {
specPath := filepath.Join(p, "spec.json")
specFileExists, err := afero.Exists(m.appFS, specPath)
if err != nil {
log.Debugf("Failed to check whether spec.json exists")
return err
}
if specFileExists {
// TODO, we should point users to a tutorial.
return fmt.Errorf("Environment's directory contains a dated model containing the 'spec.json' file. Please migrate to the new model by adding environments data to app.yaml")
}
}
return nil
})
}
func (m *manager) tryMvEnvDir(dirPathOld, dirPathNew string) error {
// first ensure none of these paths exists in the new directory
for _, p := range envPaths {
......
......@@ -63,6 +63,8 @@ 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)
......
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