Unverified Commit b105f0ad authored by bryanl's avatar bryanl
Browse files

Rename component namespaces to modules



Rename component namespaces to modules to remove the ambiguous bit.
Signed-off-by: default avatarbryanl <bryanliles@gmail.com>
parent e938e5fe
...@@ -54,8 +54,10 @@ const ( ...@@ -54,8 +54,10 @@ const (
OptionLibName = "lib-name" OptionLibName = "lib-name"
// OptionName is name option. // OptionName is name option.
OptionName = "name" OptionName = "name"
// OptionNamespaceName is namespaceName option. // OptionModule is component module option.
OptionNamespaceName = "namespace-name" OptionModule = "module"
// OptionNamespace is a cluster namespace option
OptionNamespace = "namespace"
// OptionNewEnvName is newEnvName option. Used for renaming environments. // OptionNewEnvName is newEnvName option. Used for renaming environments.
OptionNewEnvName = "new-env-name" OptionNewEnvName = "new-env-name"
// OptionOutput is output option. // OptionOutput is output option.
......
...@@ -101,8 +101,8 @@ func stageFile(t *testing.T, fs afero.Fs, src, dest string) { ...@@ -101,8 +101,8 @@ func stageFile(t *testing.T, fs afero.Fs, src, dest string) {
require.NoError(t, err) require.NoError(t, err)
} }
func mockNsWithName(name string) *cmocks.Namespace { func mockNsWithName(name string) *cmocks.Module {
m := &cmocks.Namespace{} m := &cmocks.Module{}
m.On("Name").Return(name) m.On("Name").Return(name)
return m return m
} }
......
...@@ -36,10 +36,10 @@ func RunComponentList(m map[string]interface{}) error { ...@@ -36,10 +36,10 @@ func RunComponentList(m map[string]interface{}) error {
return cl.Run() return cl.Run()
} }
// ComponentList create a list of components in a namespace. // ComponentList create a list of components in a module.
type ComponentList struct { type ComponentList struct {
app app.App app app.App
nsName string module string
output string output string
cm component.Manager cm component.Manager
out io.Writer out io.Writer
...@@ -51,7 +51,7 @@ func NewComponentList(m map[string]interface{}) (*ComponentList, error) { ...@@ -51,7 +51,7 @@ func NewComponentList(m map[string]interface{}) (*ComponentList, error) {
cl := &ComponentList{ cl := &ComponentList{
app: ol.loadApp(), app: ol.loadApp(),
nsName: ol.loadString(OptionNamespaceName), module: ol.loadString(OptionModule),
output: ol.loadString(OptionOutput), output: ol.loadString(OptionOutput),
cm: component.DefaultManager, cm: component.DefaultManager,
...@@ -67,7 +67,7 @@ func NewComponentList(m map[string]interface{}) (*ComponentList, error) { ...@@ -67,7 +67,7 @@ func NewComponentList(m map[string]interface{}) (*ComponentList, error) {
// Run runs the ComponentList action. // Run runs the ComponentList action.
func (cl *ComponentList) Run() error { func (cl *ComponentList) Run() error {
ns, err := cl.cm.Namespace(cl.app, cl.nsName) ns, err := cl.cm.Module(cl.app, cl.module)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
func TestComponentList(t *testing.T) { func TestComponentList(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
nsName := "" module := ""
output := "" output := ""
c := &cmocks.Component{} c := &cmocks.Component{}
...@@ -36,16 +36,16 @@ func TestComponentList(t *testing.T) { ...@@ -36,16 +36,16 @@ func TestComponentList(t *testing.T) {
cs := []component.Component{c} cs := []component.Component{c}
ns := &cmocks.Namespace{} ns := &cmocks.Module{}
ns.On("Components").Return(cs, nil) ns.On("Components").Return(cs, nil)
cm := &cmocks.Manager{} cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "").Return(ns, nil) cm.On("Module", mock.Anything, "").Return(ns, nil)
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionNamespaceName: nsName, OptionModule: module,
OptionOutput: output, OptionOutput: output,
} }
a, err := NewComponentList(in) a, err := NewComponentList(in)
...@@ -65,7 +65,7 @@ func TestComponentList(t *testing.T) { ...@@ -65,7 +65,7 @@ func TestComponentList(t *testing.T) {
func TestComponentList_wide(t *testing.T) { func TestComponentList_wide(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
nsName := "" module := ""
output := "wide" output := "wide"
summary := []component.Summary{ summary := []component.Summary{
...@@ -76,16 +76,16 @@ func TestComponentList_wide(t *testing.T) { ...@@ -76,16 +76,16 @@ func TestComponentList_wide(t *testing.T) {
cs := []component.Component{c} cs := []component.Component{c}
ns := &cmocks.Namespace{} ns := &cmocks.Module{}
ns.On("Components").Return(cs, nil) ns.On("Components").Return(cs, nil)
cm := &cmocks.Manager{} cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "").Return(ns, nil) cm.On("Module", mock.Anything, "").Return(ns, nil)
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionNamespaceName: nsName, OptionModule: module,
OptionOutput: output, OptionOutput: output,
} }
a, err := NewComponentList(in) a, err := NewComponentList(in)
......
...@@ -30,7 +30,7 @@ func RunComponentRm(m map[string]interface{}) error { ...@@ -30,7 +30,7 @@ func RunComponentRm(m map[string]interface{}) error {
return cr.Run() return cr.Run()
} }
// ComponentRm create a list of components in a namespace. // ComponentRm removes a component from a module.
type ComponentRm struct { type ComponentRm struct {
app app.App app app.App
name string name string
......
...@@ -50,7 +50,7 @@ func NewEnvAdd(m map[string]interface{}) (*EnvAdd, error) { ...@@ -50,7 +50,7 @@ func NewEnvAdd(m map[string]interface{}) (*EnvAdd, error) {
app: ol.loadApp(), app: ol.loadApp(),
envName: ol.loadString(OptionEnvName), envName: ol.loadString(OptionEnvName),
server: ol.loadString(OptionServer), server: ol.loadString(OptionServer),
namespace: ol.loadString(OptionNamespaceName), namespace: ol.loadString(OptionModule),
k8sSpecFlag: ol.loadString(OptionSpecFlag), k8sSpecFlag: ol.loadString(OptionSpecFlag),
isOverride: ol.loadBool(OptionOverride), isOverride: ol.loadBool(OptionOverride),
......
...@@ -34,12 +34,12 @@ func TestEnvAdd(t *testing.T) { ...@@ -34,12 +34,12 @@ func TestEnvAdd(t *testing.T) {
aIsOverride := false aIsOverride := false
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionEnvName: aName, OptionEnvName: aName,
OptionServer: aServer, OptionServer: aServer,
OptionNamespaceName: aNamespace, OptionModule: aNamespace,
OptionSpecFlag: aK8sSpecFlag, OptionSpecFlag: aK8sSpecFlag,
OptionOverride: aIsOverride, OptionOverride: aIsOverride,
} }
a, err := NewEnvAdd(in) a, err := NewEnvAdd(in)
......
...@@ -67,7 +67,7 @@ func NewEnvSet(m map[string]interface{}) (*EnvSet, error) { ...@@ -67,7 +67,7 @@ func NewEnvSet(m map[string]interface{}) (*EnvSet, error) {
app: ol.loadApp(), app: ol.loadApp(),
envName: ol.loadString(OptionEnvName), envName: ol.loadString(OptionEnvName),
newName: ol.loadOptionalString(OptionNewEnvName), newName: ol.loadOptionalString(OptionNewEnvName),
newNsName: ol.loadOptionalString(OptionNamespaceName), newNsName: ol.loadOptionalString(OptionNamespace),
envRenameFn: env.Rename, envRenameFn: env.Rename,
updateEnvFn: updateEnv, updateEnvFn: updateEnv,
......
...@@ -62,12 +62,12 @@ func TestEnvSet_name(t *testing.T) { ...@@ -62,12 +62,12 @@ func TestEnvSet_name(t *testing.T) {
func TestEnvSet_namespace(t *testing.T) { func TestEnvSet_namespace(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
envName := "default" envName := "default"
nsName := "ns2" namespace := "ns2"
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionEnvName: envName, OptionEnvName: envName,
OptionNamespaceName: nsName, OptionModule: namespace,
} }
a, err := NewEnvSet(in) a, err := NewEnvSet(in)
require.NoError(t, err) require.NoError(t, err)
...@@ -80,7 +80,7 @@ func TestEnvSet_namespace(t *testing.T) { ...@@ -80,7 +80,7 @@ func TestEnvSet_namespace(t *testing.T) {
updatedSpec := &app.EnvironmentSpec{ updatedSpec := &app.EnvironmentSpec{
Destination: &app.EnvironmentDestinationSpec{ Destination: &app.EnvironmentDestinationSpec{
Namespace: nsName, Namespace: namespace,
}, },
} }
...@@ -96,13 +96,13 @@ func TestEnvSet_name_and_namespace(t *testing.T) { ...@@ -96,13 +96,13 @@ func TestEnvSet_name_and_namespace(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
envName := "default" envName := "default"
newName := "dev" newName := "dev"
nsName := "ns2" namespace := "ns2"
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionEnvName: envName, OptionEnvName: envName,
OptionNewEnvName: newName, OptionNewEnvName: newName,
OptionNamespaceName: nsName, OptionModule: namespace,
} }
a, err := NewEnvSet(in) a, err := NewEnvSet(in)
...@@ -118,7 +118,7 @@ func TestEnvSet_name_and_namespace(t *testing.T) { ...@@ -118,7 +118,7 @@ func TestEnvSet_name_and_namespace(t *testing.T) {
a.updateEnvFn = func(a app.App, name string, spec *app.EnvironmentSpec, override bool) error { a.updateEnvFn = func(a app.App, name string, spec *app.EnvironmentSpec, override bool) error {
assert.Equal(t, envName, name) assert.Equal(t, envName, name)
assert.Equal(t, nsName, spec.Destination.Namespace) assert.Equal(t, namespace, spec.Destination.Namespace)
assert.False(t, override) assert.False(t, override)
return nil return nil
...@@ -132,7 +132,7 @@ func TestEnvSet_name_and_namespace(t *testing.T) { ...@@ -132,7 +132,7 @@ func TestEnvSet_name_and_namespace(t *testing.T) {
updatedSpec := &app.EnvironmentSpec{ updatedSpec := &app.EnvironmentSpec{
Destination: &app.EnvironmentDestinationSpec{ Destination: &app.EnvironmentDestinationSpec{
Namespace: nsName, Namespace: namespace,
}, },
} }
......
...@@ -34,7 +34,7 @@ func RunEnvTargets(m map[string]interface{}) error { ...@@ -34,7 +34,7 @@ func RunEnvTargets(m map[string]interface{}) error {
type EnvTargets struct { type EnvTargets struct {
app app.App app app.App
envName string envName string
nsNames []string modules []string
cm component.Manager cm component.Manager
} }
...@@ -45,7 +45,7 @@ func NewEnvTargets(m map[string]interface{}) (*EnvTargets, error) { ...@@ -45,7 +45,7 @@ func NewEnvTargets(m map[string]interface{}) (*EnvTargets, error) {
et := &EnvTargets{ et := &EnvTargets{
app: ol.loadApp(), app: ol.loadApp(),
envName: ol.loadString(OptionEnvName), envName: ol.loadString(OptionEnvName),
nsNames: ol.loadStringSlice(OptionNamespaceName), modules: ol.loadStringSlice(OptionModule),
cm: component.DefaultManager, cm: component.DefaultManager,
} }
...@@ -64,12 +64,12 @@ func (et *EnvTargets) Run() error { ...@@ -64,12 +64,12 @@ func (et *EnvTargets) Run() error {
return err return err
} }
for _, nsName := range et.nsNames { for _, module := range et.modules {
_, err := et.cm.Namespace(et.app, nsName) _, err := et.cm.Module(et.app, module)
if err != nil { if err != nil {
return err return err
} }
} }
return et.app.UpdateTargets(et.envName, et.nsNames) return et.app.UpdateTargets(et.envName, et.modules)
} }
...@@ -30,25 +30,25 @@ import ( ...@@ -30,25 +30,25 @@ import (
func TestEnvTargets(t *testing.T) { func TestEnvTargets(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
envName := "default" envName := "default"
nsNames := []string{"foo"} modules := []string{"foo"}
env := &app.EnvironmentSpec{} env := &app.EnvironmentSpec{}
appMock.On("Environment", "default").Return(env, nil) appMock.On("Environment", "default").Return(env, nil)
appMock.On("UpdateTargets", envName, nsNames).Return(nil) appMock.On("UpdateTargets", envName, modules).Return(nil)
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionEnvName: envName, OptionEnvName: envName,
OptionNamespaceName: nsNames, OptionModule: modules,
} }
a, err := NewEnvTargets(in) a, err := NewEnvTargets(in)
require.NoError(t, err) require.NoError(t, err)
ns := &cmocks.Namespace{} ns := &cmocks.Module{}
cm := &cmocks.Manager{} cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "foo").Return(ns, nil) cm.On("Module", mock.Anything, "foo").Return(ns, nil)
a.cm = cm a.cm = cm
...@@ -57,28 +57,28 @@ func TestEnvTargets(t *testing.T) { ...@@ -57,28 +57,28 @@ func TestEnvTargets(t *testing.T) {
}) })
} }
func TestEnvTargets_invalid_namespace(t *testing.T) { func TestEnvTargets_invalid_module(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
envName := "default" envName := "default"
nsNames := []string{"foo"} modules := []string{"foo"}
env := &app.EnvironmentSpec{} env := &app.EnvironmentSpec{}
appMock.On("Environment", "default").Return(env, nil) appMock.On("Environment", "default").Return(env, nil)
appMock.On("UpdateTargets", envName, nsNames).Return(nil) appMock.On("UpdateTargets", envName, modules).Return(nil)
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionEnvName: envName, OptionEnvName: envName,
OptionNamespaceName: nsNames, OptionModule: modules,
} }
a, err := NewEnvTargets(in) a, err := NewEnvTargets(in)
require.NoError(t, err) require.NoError(t, err)
ns := &cmocks.Namespace{} ns := &cmocks.Module{}
cm := &cmocks.Manager{} cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "foo").Return(ns, errors.New("fail")) cm.On("Module", mock.Anything, "foo").Return(ns, errors.New("fail"))
a.cm = cm a.cm = cm
...@@ -90,16 +90,16 @@ func TestEnvTargets_invalid_namespace(t *testing.T) { ...@@ -90,16 +90,16 @@ func TestEnvTargets_invalid_namespace(t *testing.T) {
func TestEnvTargets_invalid_environment(t *testing.T) { func TestEnvTargets_invalid_environment(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
envName := "invalid" envName := "invalid"
nsNames := []string{"foo"} modules := []string{"foo"}
env := &app.EnvironmentSpec{} env := &app.EnvironmentSpec{}
envErr := errors.New("environment invalid was not found") envErr := errors.New("environment invalid was not found")
appMock.On("Environment", "invalid").Return(env, envErr) appMock.On("Environment", "invalid").Return(env, envErr)
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionEnvName: envName, OptionEnvName: envName,
OptionNamespaceName: nsNames, OptionModule: modules,
} }
a, err := NewEnvTargets(in) a, err := NewEnvTargets(in)
......
...@@ -42,19 +42,19 @@ func RunImport(m map[string]interface{}) error { ...@@ -42,19 +42,19 @@ func RunImport(m map[string]interface{}) error {
// Import imports files or directories into ksonnet. // Import imports files or directories into ksonnet.
type Import struct { type Import struct {
app app.App app app.App
nsName string module string
path string path string
cm component.Manager cm component.Manager
} }
// NewImport creates an instance of Import. `nsName` is the name of the component and // NewImport creates an instance of Import. `module` is the name of the component and
// entity is the file or directory to import. // entity is the file or directory to import.
func NewImport(m map[string]interface{}) (*Import, error) { func NewImport(m map[string]interface{}) (*Import, error) {
ol := newOptionLoader(m) ol := newOptionLoader(m)
i := &Import{ i := &Import{
app: ol.loadApp(), app: ol.loadApp(),
nsName: ol.loadString(OptionNamespaceName), module: ol.loadString(OptionModule),
path: ol.loadString(OptionPath), path: ol.loadString(OptionPath),
cm: component.DefaultManager, cm: component.DefaultManager,
...@@ -106,8 +106,8 @@ func (i *Import) Run() error { ...@@ -106,8 +106,8 @@ func (i *Import) Run() error {
func (i *Import) importFile(fileName string) error { func (i *Import) importFile(fileName string) error {
var name bytes.Buffer var name bytes.Buffer
if i.nsName != "" { if i.module != "" {
name.WriteString(i.nsName + "/") name.WriteString(i.module + "/")
} }
base := filepath.Base(fileName) base := filepath.Base(fileName)
......
...@@ -29,15 +29,15 @@ import ( ...@@ -29,15 +29,15 @@ import (
func TestImport_file(t *testing.T) { func TestImport_file(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
nsName := "/" module := "/"
path := "/file.yaml" path := "/file.yaml"
stageFile(t, appMock.Fs(), "import/file.yaml", path) stageFile(t, appMock.Fs(), "import/file.yaml", path)
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionNamespaceName: nsName, OptionModule: module,
OptionPath: path, OptionPath: path,
} }
a, err := NewImport(in) a, err := NewImport(in)
...@@ -56,15 +56,15 @@ func TestImport_file(t *testing.T) { ...@@ -56,15 +56,15 @@ func TestImport_file(t *testing.T) {
func TestImport_directory(t *testing.T) { func TestImport_directory(t *testing.T) {
withApp(t, func(appMock *amocks.App) { withApp(t, func(appMock *amocks.App) {
nsName := "/" module := "/"
path := "/import" path := "/import"
stageFile(t, appMock.Fs(), "import/file.yaml", "/import/file.yaml") stageFile(t, appMock.Fs(), "import/file.yaml", "/import/file.yaml")
in := map[string]interface{}{ in := map[string]interface{}{
OptionApp: appMock, OptionApp: appMock,
OptionNamespaceName: nsName, OptionModule: module,
OptionPath: path, OptionPath: path,
} }
a, err := NewImport(in) a, err := NewImport(in)