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 (
OptionLibName = "lib-name"
// OptionName is name option.
OptionName = "name"
// OptionNamespaceName is namespaceName option.
OptionNamespaceName = "namespace-name"
// OptionModule is component module option.
OptionModule = "module"
// OptionNamespace is a cluster namespace option
OptionNamespace = "namespace"
// OptionNewEnvName is newEnvName option. Used for renaming environments.
OptionNewEnvName = "new-env-name"
// OptionOutput is output option.
......
......@@ -101,8 +101,8 @@ func stageFile(t *testing.T, fs afero.Fs, src, dest string) {
require.NoError(t, err)
}
func mockNsWithName(name string) *cmocks.Namespace {
m := &cmocks.Namespace{}
func mockNsWithName(name string) *cmocks.Module {
m := &cmocks.Module{}
m.On("Name").Return(name)
return m
}
......
......@@ -36,10 +36,10 @@ func RunComponentList(m map[string]interface{}) error {
return cl.Run()
}
// ComponentList create a list of components in a namespace.
// ComponentList create a list of components in a module.
type ComponentList struct {
app app.App
nsName string
module string
output string
cm component.Manager
out io.Writer
......@@ -51,7 +51,7 @@ func NewComponentList(m map[string]interface{}) (*ComponentList, error) {
cl := &ComponentList{
app: ol.loadApp(),
nsName: ol.loadString(OptionNamespaceName),
module: ol.loadString(OptionModule),
output: ol.loadString(OptionOutput),
cm: component.DefaultManager,
......@@ -67,7 +67,7 @@ func NewComponentList(m map[string]interface{}) (*ComponentList, error) {
// Run runs the ComponentList action.
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 {
return err
}
......
......@@ -28,7 +28,7 @@ import (
func TestComponentList(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
nsName := ""
module := ""
output := ""
c := &cmocks.Component{}
......@@ -36,16 +36,16 @@ func TestComponentList(t *testing.T) {
cs := []component.Component{c}
ns := &cmocks.Namespace{}
ns := &cmocks.Module{}
ns.On("Components").Return(cs, nil)
cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "").Return(ns, nil)
cm.On("Module", mock.Anything, "").Return(ns, nil)
in := map[string]interface{}{
OptionApp: appMock,
OptionNamespaceName: nsName,
OptionOutput: output,
OptionApp: appMock,
OptionModule: module,
OptionOutput: output,
}
a, err := NewComponentList(in)
......@@ -65,7 +65,7 @@ func TestComponentList(t *testing.T) {
func TestComponentList_wide(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
nsName := ""
module := ""
output := "wide"
summary := []component.Summary{
......@@ -76,16 +76,16 @@ func TestComponentList_wide(t *testing.T) {
cs := []component.Component{c}
ns := &cmocks.Namespace{}
ns := &cmocks.Module{}
ns.On("Components").Return(cs, nil)
cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "").Return(ns, nil)
cm.On("Module", mock.Anything, "").Return(ns, nil)
in := map[string]interface{}{
OptionApp: appMock,
OptionNamespaceName: nsName,
OptionOutput: output,
OptionApp: appMock,
OptionModule: module,
OptionOutput: output,
}
a, err := NewComponentList(in)
......
......@@ -30,7 +30,7 @@ func RunComponentRm(m map[string]interface{}) error {
return cr.Run()
}
// ComponentRm create a list of components in a namespace.
// ComponentRm removes a component from a module.
type ComponentRm struct {
app app.App
name string
......
......@@ -50,7 +50,7 @@ func NewEnvAdd(m map[string]interface{}) (*EnvAdd, error) {
app: ol.loadApp(),
envName: ol.loadString(OptionEnvName),
server: ol.loadString(OptionServer),
namespace: ol.loadString(OptionNamespaceName),
namespace: ol.loadString(OptionModule),
k8sSpecFlag: ol.loadString(OptionSpecFlag),
isOverride: ol.loadBool(OptionOverride),
......
......@@ -34,12 +34,12 @@ func TestEnvAdd(t *testing.T) {
aIsOverride := false
in := map[string]interface{}{
OptionApp: appMock,
OptionEnvName: aName,
OptionServer: aServer,
OptionNamespaceName: aNamespace,
OptionSpecFlag: aK8sSpecFlag,
OptionOverride: aIsOverride,
OptionApp: appMock,
OptionEnvName: aName,
OptionServer: aServer,
OptionModule: aNamespace,
OptionSpecFlag: aK8sSpecFlag,
OptionOverride: aIsOverride,
}
a, err := NewEnvAdd(in)
......
......@@ -67,7 +67,7 @@ func NewEnvSet(m map[string]interface{}) (*EnvSet, error) {
app: ol.loadApp(),
envName: ol.loadString(OptionEnvName),
newName: ol.loadOptionalString(OptionNewEnvName),
newNsName: ol.loadOptionalString(OptionNamespaceName),
newNsName: ol.loadOptionalString(OptionNamespace),
envRenameFn: env.Rename,
updateEnvFn: updateEnv,
......
......@@ -62,12 +62,12 @@ func TestEnvSet_name(t *testing.T) {
func TestEnvSet_namespace(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
envName := "default"
nsName := "ns2"
namespace := "ns2"
in := map[string]interface{}{
OptionApp: appMock,
OptionEnvName: envName,
OptionNamespaceName: nsName,
OptionApp: appMock,
OptionEnvName: envName,
OptionModule: namespace,
}
a, err := NewEnvSet(in)
require.NoError(t, err)
......@@ -80,7 +80,7 @@ func TestEnvSet_namespace(t *testing.T) {
updatedSpec := &app.EnvironmentSpec{
Destination: &app.EnvironmentDestinationSpec{
Namespace: nsName,
Namespace: namespace,
},
}
......@@ -96,13 +96,13 @@ func TestEnvSet_name_and_namespace(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
envName := "default"
newName := "dev"
nsName := "ns2"
namespace := "ns2"
in := map[string]interface{}{
OptionApp: appMock,
OptionEnvName: envName,
OptionNewEnvName: newName,
OptionNamespaceName: nsName,
OptionApp: appMock,
OptionEnvName: envName,
OptionNewEnvName: newName,
OptionModule: namespace,
}
a, err := NewEnvSet(in)
......@@ -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 {
assert.Equal(t, envName, name)
assert.Equal(t, nsName, spec.Destination.Namespace)
assert.Equal(t, namespace, spec.Destination.Namespace)
assert.False(t, override)
return nil
......@@ -132,7 +132,7 @@ func TestEnvSet_name_and_namespace(t *testing.T) {
updatedSpec := &app.EnvironmentSpec{
Destination: &app.EnvironmentDestinationSpec{
Namespace: nsName,
Namespace: namespace,
},
}
......
......@@ -34,7 +34,7 @@ func RunEnvTargets(m map[string]interface{}) error {
type EnvTargets struct {
app app.App
envName string
nsNames []string
modules []string
cm component.Manager
}
......@@ -45,7 +45,7 @@ func NewEnvTargets(m map[string]interface{}) (*EnvTargets, error) {
et := &EnvTargets{
app: ol.loadApp(),
envName: ol.loadString(OptionEnvName),
nsNames: ol.loadStringSlice(OptionNamespaceName),
modules: ol.loadStringSlice(OptionModule),
cm: component.DefaultManager,
}
......@@ -64,12 +64,12 @@ func (et *EnvTargets) Run() error {
return err
}
for _, nsName := range et.nsNames {
_, err := et.cm.Namespace(et.app, nsName)
for _, module := range et.modules {
_, err := et.cm.Module(et.app, module)
if err != nil {
return err
}
}
return et.app.UpdateTargets(et.envName, et.nsNames)
return et.app.UpdateTargets(et.envName, et.modules)
}
......@@ -30,25 +30,25 @@ import (
func TestEnvTargets(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
envName := "default"
nsNames := []string{"foo"}
modules := []string{"foo"}
env := &app.EnvironmentSpec{}
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{}{
OptionApp: appMock,
OptionEnvName: envName,
OptionNamespaceName: nsNames,
OptionApp: appMock,
OptionEnvName: envName,
OptionModule: modules,
}
a, err := NewEnvTargets(in)
require.NoError(t, err)
ns := &cmocks.Namespace{}
ns := &cmocks.Module{}
cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "foo").Return(ns, nil)
cm.On("Module", mock.Anything, "foo").Return(ns, nil)
a.cm = cm
......@@ -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) {
envName := "default"
nsNames := []string{"foo"}
modules := []string{"foo"}
env := &app.EnvironmentSpec{}
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{}{
OptionApp: appMock,
OptionEnvName: envName,
OptionNamespaceName: nsNames,
OptionApp: appMock,
OptionEnvName: envName,
OptionModule: modules,
}
a, err := NewEnvTargets(in)
require.NoError(t, err)
ns := &cmocks.Namespace{}
ns := &cmocks.Module{}
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
......@@ -90,16 +90,16 @@ func TestEnvTargets_invalid_namespace(t *testing.T) {
func TestEnvTargets_invalid_environment(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
envName := "invalid"
nsNames := []string{"foo"}
modules := []string{"foo"}
env := &app.EnvironmentSpec{}
envErr := errors.New("environment invalid was not found")
appMock.On("Environment", "invalid").Return(env, envErr)
in := map[string]interface{}{
OptionApp: appMock,
OptionEnvName: envName,
OptionNamespaceName: nsNames,
OptionApp: appMock,
OptionEnvName: envName,
OptionModule: modules,
}
a, err := NewEnvTargets(in)
......
......@@ -42,19 +42,19 @@ func RunImport(m map[string]interface{}) error {
// Import imports files or directories into ksonnet.
type Import struct {
app app.App
nsName string
module string
path string
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.
func NewImport(m map[string]interface{}) (*Import, error) {
ol := newOptionLoader(m)
i := &Import{
app: ol.loadApp(),
nsName: ol.loadString(OptionNamespaceName),
module: ol.loadString(OptionModule),
path: ol.loadString(OptionPath),
cm: component.DefaultManager,
......@@ -106,8 +106,8 @@ func (i *Import) Run() error {
func (i *Import) importFile(fileName string) error {
var name bytes.Buffer
if i.nsName != "" {
name.WriteString(i.nsName + "/")
if i.module != "" {
name.WriteString(i.module + "/")
}
base := filepath.Base(fileName)
......
......@@ -29,15 +29,15 @@ import (
func TestImport_file(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
nsName := "/"
module := "/"
path := "/file.yaml"
stageFile(t, appMock.Fs(), "import/file.yaml", path)
in := map[string]interface{}{
OptionApp: appMock,
OptionNamespaceName: nsName,
OptionPath: path,
OptionApp: appMock,
OptionModule: module,
OptionPath: path,
}
a, err := NewImport(in)
......@@ -56,15 +56,15 @@ func TestImport_file(t *testing.T) {
func TestImport_directory(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
nsName := "/"
module := "/"
path := "/import"
stageFile(t, appMock.Fs(), "import/file.yaml", "/import/file.yaml")
in := map[string]interface{}{
OptionApp: appMock,
OptionNamespaceName: nsName,
OptionPath: path,
OptionApp: appMock,
OptionModule: module,
OptionPath: path,
}
a, err := NewImport(in)
......@@ -83,13 +83,13 @@ func TestImport_directory(t *testing.T) {
func TestImport_invalid_file(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
nsName := "/"
module := "/"
path := "/import"
in := map[string]interface{}{
OptionApp: appMock,
OptionNamespaceName: nsName,
OptionPath: path,
OptionApp: appMock,
OptionModule: module,
OptionPath: path,
}
a, err := NewImport(in)
......
......@@ -27,7 +27,7 @@ const (
defaultIncubatorURI = "github.com/ksonnet/parts/tree/master/" + defaultIncubatorRegName
)
// RunInit creates a namespace.
// RunInit initializes an app.
func RunInit(m map[string]interface{}) error {
i, err := NewInit(m)
if err != nil {
......@@ -68,7 +68,7 @@ func NewInit(m map[string]interface{}) (*Init, error) {
rootPath: ol.loadString(OptionRootPath),
k8sSpecFlag: ol.loadString(OptionSpecFlag),
serverURI: ol.loadOptionalString(OptionServer),
namespace: ol.loadString(OptionNamespaceName),
namespace: ol.loadString(OptionNamespace),
skipDefaultRegistries: ol.loadBool(OptionSkipDefaultRegistries),
appInitFn: appinit.Init,
......
......@@ -57,7 +57,7 @@ func TestInit(t *testing.T) {
OptionRootPath: aRootPath,
OptionSpecFlag: aK8sSpecFlag,
OptionServer: aServerURI,
OptionNamespaceName: aNamespace,
OptionNamespace: aNamespace,
OptionSkipDefaultRegistries: tc.skipRegistries,
}
......
......@@ -21,43 +21,43 @@ import (
"github.com/pkg/errors"
)
// RunNsCreate creates a namespace.
func RunNsCreate(m map[string]interface{}) error {
nc, err := NewNsCreate(m)
// RunModuleCreate creates a module.
func RunModuleCreate(m map[string]interface{}) error {
mc, err := NewModuleCreate(m)
if err != nil {
return err
}
return nc.Run()
return mc.Run()
}
// NsCreate creates a component namespace
type NsCreate struct {
// ModuleCreate creates a component module
type ModuleCreate struct {
app app.App
nsName string
module string
cm component.Manager
}
// NewNsCreate creates an instance of NsCreate.
func NewNsCreate(m map[string]interface{}) (*NsCreate, error) {
// NewModuleCreate creates an instance of ModuleCreate.
func NewModuleCreate(m map[string]interface{}) (*ModuleCreate, error) {
ol := newOptionLoader(m)
et := &NsCreate{
mc := &ModuleCreate{
app: ol.loadApp(),
nsName: ol.loadString(OptionNamespaceName),
module: ol.loadString(OptionModule),
cm: component.DefaultManager,
}
return et, nil
return mc, nil
}
// Run runs that ns create action.
func (nc *NsCreate) Run() error {
_, err := nc.cm.Namespace(nc.app, nc.nsName)
func (mc *ModuleCreate) Run() error {
_, err := mc.cm.Module(mc.app, mc.module)
if err == nil {
return errors.Errorf("namespace %q already exists", nc.nsName)
return errors.Errorf("module %q already exists", mc.module)
}
return nc.cm.CreateNamespace(nc.app, nc.nsName)
return mc.cm.CreateModule(mc.app, mc.module)
}
......@@ -26,21 +26,21 @@ import (
"github.com/stretchr/testify/require"
)
func TestNsCreate(t *testing.T) {
func TestModuleCreate(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
in := map[string]interface{}{
OptionApp: appMock,
OptionNamespaceName: "name",
OptionApp: appMock,
OptionModule: "name",
}
a, err := NewNsCreate(in)
a, err := NewModuleCreate(in)
require.NoError(t, err)
ns := &cmocks.Namespace{}
ns := &cmocks.Module{}
cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "name").Return(ns, errors.New("it exists"))
cm.On("CreateNamespace", mock.Anything, "name").Return(nil)
cm.On("Module", mock.Anything, "name").Return(ns, errors.New("it exists"))
cm.On("CreateModule", mock.Anything, "name").Return(nil)
a.cm = cm
......@@ -50,20 +50,20 @@ func TestNsCreate(t *testing.T) {
})
}
func TestNsCreate_already_exists(t *testing.T) {
func TestModuleCreate_already_exists(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
in := map[string]interface{}{
OptionApp: appMock,
OptionNamespaceName: "name",
OptionApp: appMock,
OptionModule: "name",
}
a, err := NewNsCreate(in)
a, err := NewModuleCreate(in)
require.NoError(t, err)
ns := &cmocks.Namespace{}
ns := &cmocks.Module{}
cm := &cmocks.Manager{}
cm.On("Namespace", mock.Anything, "name").Return(ns, nil)
cm.On("Module", mock.Anything, "name").Return(ns, nil)
a.cm = cm
......
......@@ -25,9 +25,9 @@ import (
"github.com/ksonnet/ksonnet/pkg/util/table"
)
// RunNsList runs `ns list`
func RunNsList(m map[string]interface{}) error {
nl, err := NewNsList(m)
// RunModuleList runs `module list`
func RunModuleList(m map[string]interface{}) error {
nl, err := NewModuleList(m)
if err != nil {
return err
}
......@@ -35,19 +35,19 @@ func RunNsList(m map[string]interface{}) error {
return nl.Run()
}
// NsList lists namespaces.
type NsList struct {