diff --git a/metadata/component.go b/metadata/component.go index de41c5b8..a9ce6c55 100644 --- a/metadata/component.go +++ b/metadata/component.go @@ -23,9 +23,7 @@ import ( "github.com/ksonnet/ksonnet/metadata/app" param "github.com/ksonnet/ksonnet/metadata/params" "github.com/ksonnet/ksonnet/prototype" - str "github.com/ksonnet/ksonnet/strings" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" "github.com/spf13/afero" ) @@ -87,89 +85,6 @@ func (m *manager) CreateComponent(name string, text string, params param.Params, return nil } -// DeleteComponent removes the component file and all references. -// Write operations will happen at the end to minimal-ize failures that leave -// the directory structure in a half-finished state. -func (m *manager) DeleteComponent(name string) error { - ksApp, err := m.App() - if err != nil { - return err - } - - componentPath, err := component.Path(ksApp, name) - if err != nil { - return err - } - - ns, _ := component.ExtractNamespacedComponent(ksApp, name) - - // Build the new component/params.libsonnet file. - componentParamsFile, err := afero.ReadFile(m.appFS, ns.ParamsPath()) - if err != nil { - return err - } - componentJsonnet, err := param.DeleteComponent(name, string(componentParamsFile)) - if err != nil { - return err - } - - // Build the new environment//params.libsonnet files. - // environment name -> jsonnet - envJsonnets := make(map[string]string) - envs, err := ksApp.Environments() - if err != nil { - return err - } - for _, env := range envs { - path := str.AppendToPath(m.environmentsPath, env.Name, paramsFileName) - envParamsFile, err := afero.ReadFile(m.appFS, path) - if err != nil { - return err - } - jsonnet, err := param.DeleteEnvironmentComponent(name, string(envParamsFile)) - if err != nil { - return err - } - envJsonnets[env.Name] = jsonnet - } - - // - // Delete the component references. - // - log.Infof("Removing component parameter references ...") - - // Remove the references in component/params.libsonnet. - log.Debugf("... deleting references in %s", m.componentParamsPath) - err = afero.WriteFile(m.appFS, ns.ParamsPath(), []byte(componentJsonnet), app.DefaultFilePermissions) - if err != nil { - return err - } - // Remove the component references in each environment's - // environment//params.libsonnet. - for _, env := range envs { - path := str.AppendToPath(m.environmentsPath, env.Name, paramsFileName) - log.Debugf("... deleting references in %s", path) - err = afero.WriteFile(m.appFS, path, []byte(envJsonnets[env.Name]), app.DefaultFilePermissions) - if err != nil { - return err - } - } - - // - // Delete the component file in components/. - // - log.Infof("Deleting component '%s' at path '%s'", name, componentPath) - if err := m.appFS.Remove(componentPath); err != nil { - return err - } - - // TODO: Remove, - // references in main.jsonnet. - // component references in other component files (feature does not yet exist). - log.Infof("Successfully deleted component '%s'", name) - return nil -} - func (m *manager) GetComponentParams(component string) (param.Params, error) { text, err := afero.ReadFile(m.appFS, m.componentParamsPath) if err != nil { diff --git a/metadata/environment.go b/metadata/environment.go index 12b39b06..df366d55 100644 --- a/metadata/environment.go +++ b/metadata/environment.go @@ -16,8 +16,9 @@ package metadata import ( + "path/filepath" + "github.com/ksonnet/ksonnet/pkg/env" - str "github.com/ksonnet/ksonnet/strings" param "github.com/ksonnet/ksonnet/metadata/params" ) @@ -33,16 +34,6 @@ var ( envCreate = env.Create ) -// func (m *manager) DeleteEnvironment(name string) error { -// a, err := m.App() -// if err != nil { -// return err -// } - -// // TODO: move this to actions -// return env.Delete(a, name, false) -// } - func (m *manager) GetEnvironmentParams(name, nsName string) (map[string]param.Params, error) { a, err := m.App() if err != nil { @@ -76,12 +67,12 @@ func (m *manager) EnvPaths(env string) (libPath, mainPath, paramsPath string, er } func (m *manager) makeEnvPaths(env string) (mainPath, paramsPath string) { - envPath := str.AppendToPath(m.environmentsPath, env) + envPath := filepath.Join(m.environmentsPath, env) // main.jsonnet file - mainPath = str.AppendToPath(envPath, envFileName) + mainPath = filepath.Join(envPath, envFileName) // params.libsonnet file - paramsPath = str.AppendToPath(envPath, componentParamsFile) + paramsPath = filepath.Join(envPath, componentParamsFile) return } diff --git a/metadata/interface.go b/metadata/interface.go index 53d24c08..c31324fc 100644 --- a/metadata/interface.go +++ b/metadata/interface.go @@ -39,7 +39,6 @@ type Manager interface { ComponentPaths() ([]string, error) GetAllComponents() ([]component.Component, error) CreateComponent(name string, text string, params param.Params, templateType prototype.TemplateType) error - DeleteComponent(name string) error // Params API. SetComponentParams(component string, params param.Params) error @@ -51,9 +50,6 @@ type Manager interface { // i.e.: "nginx" => {"replicas" => 1, "name": "nginx"} GetEnvironmentParams(name, nsName string) (map[string]param.Params, error) SetEnvironmentParams(env, component string, params param.Params) error - - // Environment API. - // DeleteEnvironment(name string) error } // Find will recursively search the current directory and its parents for a diff --git a/metadata/lib/lib.go b/metadata/lib/lib.go index 4feb6a79..c3f8228f 100644 --- a/metadata/lib/lib.go +++ b/metadata/lib/lib.go @@ -21,7 +21,6 @@ import ( "path" "path/filepath" - str "github.com/ksonnet/ksonnet/strings" log "github.com/sirupsen/logrus" "github.com/spf13/afero" @@ -143,7 +142,7 @@ func (m *Manager) GenerateLibData(useVersionPath bool) error { // GetLibPath returns the absolute path pointing to the directory with the // metadata files for the provided k8sVersion. func (m *Manager) GetLibPath(useVersionPath bool) (string, error) { - path := str.AppendToPath(m.libPath, m.K8sVersion) + path := filepath.Join(m.libPath, m.K8sVersion) ok, err := afero.DirExists(m.fs, string(path)) if err != nil { return "", err diff --git a/metadata/manager.go b/metadata/manager.go index 84af2d33..99b0d4f1 100644 --- a/metadata/manager.go +++ b/metadata/manager.go @@ -22,7 +22,6 @@ import ( "path/filepath" "github.com/ksonnet/ksonnet/metadata/app" - str "github.com/ksonnet/ksonnet/strings" "github.com/pkg/errors" "github.com/spf13/afero" ) @@ -116,27 +115,27 @@ func newManager(rootPath string, appFS afero.Fs) (*manager, error) { if err != nil { return nil, err } - userRootPath := str.AppendToPath(usr.HomeDir, userKsonnetRootDir) + userRootPath := filepath.Join(usr.HomeDir, userKsonnetRootDir) m := &manager{ appFS: appFS, // Application paths. rootPath: rootPath, - ksonnetPath: str.AppendToPath(rootPath, ksonnetDir), - registriesPath: str.AppendToPath(rootPath, registriesDir), - libPath: str.AppendToPath(rootPath, libDir), - componentsPath: str.AppendToPath(rootPath, componentsDir), - environmentsPath: str.AppendToPath(rootPath, environmentsDir), - vendorPath: str.AppendToPath(rootPath, vendorDir), + ksonnetPath: filepath.Join(rootPath, ksonnetDir), + registriesPath: filepath.Join(rootPath, registriesDir), + libPath: filepath.Join(rootPath, libDir), + componentsPath: filepath.Join(rootPath, componentsDir), + environmentsPath: filepath.Join(rootPath, environmentsDir), + vendorPath: filepath.Join(rootPath, vendorDir), - componentParamsPath: str.AppendToPath(rootPath, componentsDir, componentParamsFile), - baseLibsonnetPath: str.AppendToPath(rootPath, environmentsDir, baseLibsonnetFile), - appYAMLPath: str.AppendToPath(rootPath, appYAMLFile), + componentParamsPath: filepath.Join(rootPath, componentsDir, componentParamsFile), + baseLibsonnetPath: filepath.Join(rootPath, environmentsDir, baseLibsonnetFile), + appYAMLPath: filepath.Join(rootPath, appYAMLFile), // User-level paths. userKsonnetRootPath: userRootPath, - pkgSrcCachePath: str.AppendToPath(userRootPath, pkgSrcCacheDir), + pkgSrcCachePath: filepath.Join(userRootPath, pkgSrcCacheDir), } return m, nil diff --git a/metadata/registry.go b/metadata/registry.go index 25eb3d11..772432ce 100644 --- a/metadata/registry.go +++ b/metadata/registry.go @@ -19,11 +19,10 @@ import ( "path/filepath" "github.com/ksonnet/ksonnet/pkg/registry" - str "github.com/ksonnet/ksonnet/strings" ) func (m *manager) registryDir(regManager registry.Registry) string { - return str.AppendToPath(m.registriesPath, regManager.RegistrySpecDir()) + return filepath.Join(m.registriesPath, regManager.RegistrySpecDir()) } func (m *manager) registryPath(regManager registry.Registry) string { @@ -31,5 +30,5 @@ func (m *manager) registryPath(regManager registry.Registry) string { if filepath.IsAbs(path) { return path } - return str.AppendToPath(m.registriesPath, regManager.RegistrySpecFilePath()) + return filepath.Join(m.registriesPath, regManager.RegistrySpecFilePath()) } diff --git a/pkg/kubecfg/component.go b/pkg/kubecfg/component.go deleted file mode 100644 index 8337d7e9..00000000 --- a/pkg/kubecfg/component.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 The kubecfg authors -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package kubecfg - -// ComponentRmCmd stores the information necessary to remove a component from -// the ksonnet application. -type ComponentRmCmd struct { - component string -} - -// NewComponentRmCmd acts as a constructor for ComponentRmCmd. -func NewComponentRmCmd(component string) *ComponentRmCmd { - return &ComponentRmCmd{component: component} -} - -// Run executes the removing of the component. -func (c *ComponentRmCmd) Run() error { - manager, err := manager() - if err != nil { - return err - } - - return manager.DeleteComponent(c.component) -} diff --git a/strings/strings.go b/strings/strings.go index 20e91f0b..6a8b2435 100644 --- a/strings/strings.go +++ b/strings/strings.go @@ -18,7 +18,6 @@ package strings import ( "bytes" "fmt" - "path" "strings" "github.com/PuerkitoBio/purell" @@ -163,9 +162,3 @@ func padRows(rows []Row) ([]FormattedRow, error) { return result, nil } - -// AppendToPath appends one or more paths to the specified original path. -func AppendToPath(originalPath string, toAppend ...string) string { - paths := append([]string{originalPath}, toAppend...) - return path.Join(paths...) -} diff --git a/strings/strings_test.go b/strings/strings_test.go index a96c5011..22ff347d 100644 --- a/strings/strings_test.go +++ b/strings/strings_test.go @@ -232,32 +232,3 @@ Hi World require.EqualValues(t, test.expected, padded) } } - -func TestAppendToPath(t *testing.T) { - tests := []struct { - originalPath string - toAppend string - expected string - }{ - { - originalPath: "host/path/", - toAppend: "appended", - expected: "host/path/appended", - }, - { - originalPath: "host/path", - toAppend: "appended/", - expected: "host/path/appended", - }, - { - originalPath: "host/path/", - toAppend: "//appended//", - expected: "host/path/appended", - }, - } - for _, test := range tests { - result := AppendToPath(test.originalPath, test.toAppend) - - require.EqualValues(t, test.expected, result) - } -}