diff --git a/cmd/apply.go b/cmd/apply.go index 86504b0340fa5723b69531e0565fa8989bb8ee83..1db955893379ca5228ba7059917c16267d0c2d46 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -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: ` diff --git a/metadata/environment.go b/metadata/environment.go index 06aea484f9129d4d54b2e67d7c5994ae59acdae4..d23d7b71238e016129d10b7de78c139becf80699 100644 --- a/metadata/environment.go +++ b/metadata/environment.go @@ -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 { diff --git a/metadata/interface.go b/metadata/interface.go index 88407d691d91a77c04005b661a78cdf5021cd568..d60dcd82785e6567f6d697752198ab9071785cd3 100644 --- a/metadata/interface.go +++ b/metadata/interface.go @@ -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)