Currently, we create Fission resources in the default namespace, function-related resources are created in the fission-function namespace, whereas builder resources are created in the fission-builder namespace. This causes confusion for a lot of users. In this fix, we allow the user to set the function and builder namespace empty so that function and builder resources are created in the same namespace as the function resource always. If the user desires older behaviour they can functionNamespace and builderNamespace the same previous before the upgrade. * use default namespace for fission function and builder * support for existing fission namespaces * Replace builder and function namespace with template * Fix namespace creation template Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
125 lines
3.8 KiB
Go
125 lines
3.8 KiB
Go
package utils
|
|
|
|
import "testing"
|
|
|
|
func TestNamespaceResolver(t *testing.T) {
|
|
t.Run("GetBuilderNS", func(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
namespaceResolver *NamespaceResolver
|
|
namespace string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "should return fission-builder namespace",
|
|
namespaceResolver: getFissionNamespaces("fission-builder", "fission-function", "default"),
|
|
namespace: "default",
|
|
expected: "fission-builder",
|
|
},
|
|
{
|
|
name: "should return testns2 namespace",
|
|
namespaceResolver: getFissionNamespaces("fission-builder", "fission-function", "testns"),
|
|
namespace: "testns2",
|
|
expected: "testns2",
|
|
},
|
|
{
|
|
name: "should return testns3 namespace",
|
|
namespaceResolver: getFissionNamespaces("", "", "testns"),
|
|
namespace: "testns3",
|
|
expected: "testns3",
|
|
},
|
|
{
|
|
name: "should return default namespace",
|
|
namespaceResolver: getFissionNamespaces("fission-builder", "", "default"),
|
|
namespace: "default",
|
|
expected: "default",
|
|
},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
ns := test.namespaceResolver.GetBuilderNS(test.namespace)
|
|
if ns != test.expected {
|
|
t.Errorf("expected builder namespace %s, got %s", test.expected, ns)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
t.Run("GetFunctionNS", func(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
namespaceResolver *NamespaceResolver
|
|
namespace string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "should return fission-function namespace",
|
|
namespaceResolver: getFissionNamespaces("fission-builder", "fission-function", "default"),
|
|
namespace: "default",
|
|
expected: "fission-function",
|
|
},
|
|
{
|
|
name: "should return testns2 namespace",
|
|
namespaceResolver: getFissionNamespaces("fission-builder", "fission-function", "testns"),
|
|
namespace: "testns2",
|
|
expected: "testns2",
|
|
},
|
|
{
|
|
name: "should return testns3 namespace",
|
|
namespaceResolver: getFissionNamespaces("", "", "testns"),
|
|
namespace: "testns3",
|
|
expected: "testns3",
|
|
},
|
|
{
|
|
name: "should return default namespace",
|
|
namespaceResolver: getFissionNamespaces("", "fission-function", "default"),
|
|
namespace: "default",
|
|
expected: "default",
|
|
},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
ns := test.namespaceResolver.GetFunctionNS(test.namespace)
|
|
if ns != test.expected {
|
|
t.Errorf("expected function namespace %s, got %s", test.expected, ns)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
t.Run("ResolveNamespace", func(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
namespaceResolver *NamespaceResolver
|
|
namespace string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "should return testns namespace",
|
|
namespaceResolver: getFissionNamespaces("fission-builder", "fission-function", "default"),
|
|
namespace: "testns",
|
|
expected: "testns",
|
|
},
|
|
{
|
|
name: "should return default namespace",
|
|
namespaceResolver: getFissionNamespaces("fission-builder", "", "default"),
|
|
namespace: "testns",
|
|
expected: "default",
|
|
},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
ns := test.namespaceResolver.ResolveNamespace(test.namespace)
|
|
if ns != test.expected {
|
|
t.Errorf("expected function namespace %s, got %s", test.expected, ns)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func getFissionNamespaces(builderNS, functionNS, defaultNS string) *NamespaceResolver {
|
|
return &NamespaceResolver{
|
|
FunctionNamespace: functionNS,
|
|
BuiderNamespace: builderNS,
|
|
DefaultNamespace: defaultNS,
|
|
}
|
|
}
|