diff --git a/metadata/component.go b/metadata/component.go index 7cbe06ebf768608ca6afe3775195770b9c47b94a..709ee716b5d3331a0db025594a5e34a5e61b0644 100644 --- a/metadata/component.go +++ b/metadata/component.go @@ -171,6 +171,38 @@ func (m *manager) DeleteComponent(name string) error { return nil } +func (m *manager) GetComponentParams(component string) (param.Params, error) { + text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) + if err != nil { + return nil, err + } + + return param.GetComponentParams(component, string(text)) +} + +func (m *manager) GetAllComponentParams() (map[string]param.Params, error) { + text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) + if err != nil { + return nil, err + } + + return param.GetAllComponentParams(string(text)) +} + +func (m *manager) SetComponentParams(component string, params param.Params) error { + text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) + if err != nil { + return err + } + + jsonnet, err := param.SetComponentParams(component, string(text), params) + if err != nil { + return err + } + + return afero.WriteFile(m.appFS, string(m.componentParamsPath), []byte(jsonnet), defaultFilePermissions) +} + func (m *manager) findComponentPath(name string) (string, error) { componentPaths, err := m.ComponentPaths() if err != nil { @@ -198,3 +230,31 @@ func (m *manager) findComponentPath(name string) (string, error) { return componentPath, nil } + +func (m *manager) writeComponentParams(componentName string, params param.Params) error { + text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) + if err != nil { + return err + } + + appended, err := param.AppendComponent(componentName, string(text), params) + if err != nil { + return err + } + + return afero.WriteFile(m.appFS, string(m.componentParamsPath), []byte(appended), defaultFilePermissions) +} + +func genComponentParamsContent() []byte { + return []byte(`{ + global: { + // User-defined global parameters; accessible to all component and environments, Ex: + // replicas: 4, + }, + components: { + // Component-level parameters, defined initially from 'ks prototype use ...' + // Each object below should correspond to a component in the components/ directory + }, +} +`) +} diff --git a/metadata/component_test.go b/metadata/component_test.go index 00a5ddb299fdaa46b4f68f31111714216f3e8dd7..d5021bcd819ca377f810fcdab8d4df6396ca05ca 100644 --- a/metadata/component_test.go +++ b/metadata/component_test.go @@ -138,3 +138,21 @@ func TestFindComponentPath(t *testing.T) { t.Fatalf("m.findComponentPath failed; expected '%s', got '%s'", expected, path) } } + +func TestGenComponentParamsContent(t *testing.T) { + expected := `{ + global: { + // User-defined global parameters; accessible to all component and environments, Ex: + // replicas: 4, + }, + components: { + // Component-level parameters, defined initially from 'ks prototype use ...' + // Each object below should correspond to a component in the components/ directory + }, +} +` + content := string(genComponentParamsContent()) + if content != expected { + t.Fatalf("Expected to generate:\n%s\n, got:\n%s", expected, content) + } +} diff --git a/metadata/manager.go b/metadata/manager.go index ac400a85ba24f2277ef0727cb08618e0e9038fcd..8423f16a4254a8e2f1c4cf3353a28ecdeb9bcc65 100644 --- a/metadata/manager.go +++ b/metadata/manager.go @@ -23,7 +23,6 @@ import ( "github.com/ksonnet/ksonnet/generator" "github.com/ksonnet/ksonnet/metadata/app" - param "github.com/ksonnet/ksonnet/metadata/params" "github.com/ksonnet/ksonnet/metadata/registry" log "github.com/sirupsen/logrus" "github.com/spf13/afero" @@ -223,38 +222,6 @@ func (m *manager) EnvPaths(env string) (metadataPath, mainPath, paramsPath, spec return } -func (m *manager) GetComponentParams(component string) (param.Params, error) { - text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) - if err != nil { - return nil, err - } - - return param.GetComponentParams(component, string(text)) -} - -func (m *manager) GetAllComponentParams() (map[string]param.Params, error) { - text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) - if err != nil { - return nil, err - } - - return param.GetAllComponentParams(string(text)) -} - -func (m *manager) SetComponentParams(component string, params param.Params) error { - text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) - if err != nil { - return err - } - - jsonnet, err := param.SetComponentParams(component, string(text), params) - if err != nil { - return err - } - - return afero.WriteFile(m.appFS, string(m.componentParamsPath), []byte(jsonnet), defaultFilePermissions) -} - // AppSpec will return the specification for a ksonnet application // (typically stored in `app.yaml`) func (m *manager) AppSpec() (*app.Spec, error) { @@ -356,34 +323,6 @@ func (m *manager) createAppDirTree(name string, appYAMLData, baseLibData []byte, return nil } -func (m *manager) writeComponentParams(componentName string, params param.Params) error { - text, err := afero.ReadFile(m.appFS, string(m.componentParamsPath)) - if err != nil { - return err - } - - appended, err := param.AppendComponent(componentName, string(text), params) - if err != nil { - return err - } - - return afero.WriteFile(m.appFS, string(m.componentParamsPath), []byte(appended), defaultFilePermissions) -} - -func genComponentParamsContent() []byte { - return []byte(`{ - global: { - // User-defined global parameters; accessible to all component and environments, Ex: - // replicas: 4, - }, - components: { - // Component-level parameters, defined initially from 'ks prototype use ...' - // Each object below should correspond to a component in the components/ directory - }, -} -`) -} - func generateRegistryYAMLData(incubatorReg registry.Manager) ([]byte, error) { regSpec, err := incubatorReg.FetchRegistrySpec() if err != nil { diff --git a/metadata/manager_test.go b/metadata/manager_test.go index 9c4cf463005d0c697b6c00f40be286ebd0b21fef..88175f9556b02b9af3328f66db88e92d5bb5f86a 100644 --- a/metadata/manager_test.go +++ b/metadata/manager_test.go @@ -277,21 +277,3 @@ func TestDoubleNewFailure(t *testing.T) { t.Fatalf("Expected to fail to create app with message '%s', got '%s'", targetErr, err.Error()) } } - -func TestGenComponentParamsContent(t *testing.T) { - expected := `{ - global: { - // User-defined global parameters; accessible to all component and environments, Ex: - // replicas: 4, - }, - components: { - // Component-level parameters, defined initially from 'ks prototype use ...' - // Each object below should correspond to a component in the components/ directory - }, -} -` - content := string(genComponentParamsContent()) - if content != expected { - t.Fatalf("Expected to generate:\n%s\n, got:\n%s", expected, content) - } -}