Skip to content

Commit 32af1e3

Browse files
authored
Add Namespace Mapping Configuration (flyteorg#3)
* add namepace configuration * add namespace files * remove unused var * update propeller executor config * use propeller executor configuration * to lowercase * fix conflicts * update namespace test * remove namespaceMapping variable * fix compile issues * add project-domain option and remove incorrect log messages * upd mock configuration provider * update unit tests * Merge logs on task execution event updates (flyteorg#18) * use fallthrough * Correct Lint Errors and Add Documentation on Pre-Commit (flyteorg#19) * README update * Fix lint errors * add namepace configuration * add namespace files * remove unused var * update propeller executor config * use propeller executor configuration * to lowercase * fix conflicts * update namespace test * remove namespaceMapping variable * fix compile issues * add project-domain option and remove incorrect log messages * upd mock configuration provider * update unit tests * use fallthrough * fix conflicts * fix more conflicts * lint * remove duplicate package * fix lint errors
1 parent c633f76 commit 32af1e3

19 files changed

+254
-30
lines changed

Gopkg.lock

Lines changed: 102 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/clusterresource/controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
k8serrors "k8s.io/apimachinery/pkg/api/errors"
3636
)
3737

38-
const namespaceFormat = "%s-%s"
3938
const namespaceVariable = "namespace"
4039
const templateVariableFormat = "{{ %s }}"
4140
const replaceAllInstancesOfString = -1
@@ -283,7 +282,7 @@ func (c *controller) Sync(ctx context.Context) error {
283282
var errs = make([]error, 0)
284283
for _, project := range projects {
285284
for _, domain := range *domains {
286-
namespace := fmt.Sprintf(namespaceFormat, project.Identifier, domain.Name)
285+
namespace := common.GetNamespaceName(c.config.NamespaceMappingConfiguration().GetNamespaceMappingConfig(), project.Identifier, domain.Name)
287286
err := c.syncNamespace(ctx, namespace)
288287
if err != nil {
289288
logger.Warningf(ctx, "Failed to create cluster resources for namespace [%s] with err: %v", namespace, err)

pkg/common/namespace.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package common
2+
3+
import "fmt"
4+
5+
type NamespaceMapping int
6+
7+
const namespaceFormat = "%s-%s"
8+
9+
const (
10+
ProjectDomain NamespaceMapping = iota
11+
Domain NamespaceMapping = iota
12+
)
13+
14+
// GetNamespaceName returns kubernetes namespace name
15+
func GetNamespaceName(mapping NamespaceMapping, project, domain string) string {
16+
switch mapping {
17+
case Domain:
18+
return domain
19+
case ProjectDomain:
20+
fallthrough
21+
default:
22+
return fmt.Sprintf(namespaceFormat, project, domain)
23+
}
24+
}

pkg/common/namespace_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package common
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestGetNamespaceName(t *testing.T) {
10+
testCases := []struct {
11+
mapping NamespaceMapping
12+
project string
13+
domain string
14+
want string
15+
}{
16+
{ProjectDomain, "project", "production", "project-production"},
17+
{20 /*Dummy enum value that is not supported*/, "project", "development", "project-development"},
18+
{Domain, "project", "production", "production"},
19+
}
20+
21+
for _, tc := range testCases {
22+
got := GetNamespaceName(tc.mapping, tc.project, tc.domain)
23+
assert.Equal(t, got, tc.want)
24+
}
25+
}

pkg/manager/impl/execution_manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func getMockExecutionsConfigProvider() runtimeInterfaces.Configuration {
9898
testutils.GetApplicationConfigWithDefaultProjects(),
9999
runtimeMocks.NewMockQueueConfigurationProvider(
100100
[]runtimeInterfaces.ExecutionQueue{}, []runtimeInterfaces.WorkflowConfig{}),
101-
nil, nil, nil)
101+
nil, nil, nil, nil)
102102
mockExecutionsConfigProvider.(*runtimeMocks.MockConfigurationProvider).AddRegistrationValidationConfiguration(
103103
runtimeMocks.NewMockRegistrationValidationProvider())
104104
return mockExecutionsConfigProvider
@@ -328,7 +328,7 @@ func TestCreateExecution_TaggedQueue(t *testing.T) {
328328
Tags: []string{"tag"},
329329
},
330330
}),
331-
nil, nil, nil)
331+
nil, nil, nil, nil)
332332
configProvider.(*runtimeMocks.MockConfigurationProvider).AddRegistrationValidationConfiguration(
333333
runtimeMocks.NewMockRegistrationValidationProvider())
334334
mockExecutor := workflowengineMocks.NewMockExecutor()
@@ -1548,7 +1548,7 @@ func TestExecutionManager_PublishNotifications(t *testing.T) {
15481548
&mockApplicationConfig,
15491549
runtimeMocks.NewMockQueueConfigurationProvider(
15501550
[]runtimeInterfaces.ExecutionQueue{}, []runtimeInterfaces.WorkflowConfig{}),
1551-
nil, nil, nil)
1551+
nil, nil, nil, nil)
15521552

15531553
var myExecManager = &ExecutionManager{
15541554
db: repository,
@@ -1681,7 +1681,7 @@ func TestExecutionManager_TestExecutionManager_PublishNotificationsTransformErro
16811681
&mockApplicationConfig,
16821682
runtimeMocks.NewMockQueueConfigurationProvider(
16831683
[]runtimeInterfaces.ExecutionQueue{}, []runtimeInterfaces.WorkflowConfig{}),
1684-
nil, nil, nil)
1684+
nil, nil, nil, nil)
16851685

16861686
var myExecManager = &ExecutionManager{
16871687
db: repository,

pkg/manager/impl/executions/queues_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestGetQueue(t *testing.T) {
6767
}
6868
queueAllocator := NewQueueAllocator(runtimeMocks.NewMockConfigurationProvider(
6969
nil, runtimeMocks.NewMockQueueConfigurationProvider(executionQueues, workflowConfigs),
70-
nil, nil, nil))
70+
nil, nil, nil, nil))
7171
queueConfig := singleQueueConfiguration{
7272
PrimaryQueue: "queue primary",
7373
DynamicQueue: "queue dynamic",
@@ -139,7 +139,7 @@ func TestGetQueueDefaults(t *testing.T) {
139139
}
140140
queueAllocator := NewQueueAllocator(runtimeMocks.NewMockConfigurationProvider(
141141
nil, runtimeMocks.NewMockQueueConfigurationProvider(executionQueues, workflowConfigs), nil,
142-
nil, nil))
142+
nil, nil, nil))
143143
assert.Equal(t, singleQueueConfiguration{
144144
PrimaryQueue: "default primary",
145145
DynamicQueue: "default dynamic",

pkg/manager/impl/launch_plan_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func getMockRepositoryForLpTest() repositories.RepositoryInterface {
5858

5959
func getMockConfigForLpTest() runtimeInterfaces.Configuration {
6060
mockConfig := runtimeMocks.NewMockConfigurationProvider(
61-
testutils.GetApplicationConfigWithDefaultProjects(), nil, nil, nil, nil)
61+
testutils.GetApplicationConfigWithDefaultProjects(), nil, nil, nil, nil, nil)
6262
return mockConfig
6363
}
6464

pkg/manager/impl/project_manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
var mockProjectConfigProvider = runtimeMocks.NewMockConfigurationProvider(
19-
testutils.GetApplicationConfigWithDefaultProjects(), nil, nil, nil, nil)
19+
testutils.GetApplicationConfigWithDefaultProjects(), nil, nil, nil, nil, nil)
2020

2121
var testDomainsForProjManager = []string{"domain", "development", "staging", "production"}
2222

@@ -80,7 +80,7 @@ func TestProjectManager_CreateProject(t *testing.T) {
8080
}
8181
projectManager := NewProjectManager(mockRepository,
8282
runtimeMocks.NewMockConfigurationProvider(
83-
getMockApplicationConfigForProjectManagerTest(), nil, nil, nil, nil))
83+
getMockApplicationConfigForProjectManagerTest(), nil, nil, nil, nil, nil))
8484
_, err := projectManager.CreateProject(context.Background(), admin.ProjectRegisterRequest{
8585
Project: &admin.Project{
8686
Id: "flyte-project-id",
@@ -100,7 +100,7 @@ func TestProjectManager_CreateProjectError(t *testing.T) {
100100
}
101101
projectManager := NewProjectManager(mockRepository,
102102
runtimeMocks.NewMockConfigurationProvider(
103-
getMockApplicationConfigForProjectManagerTest(), nil, nil, nil, nil))
103+
getMockApplicationConfigForProjectManagerTest(), nil, nil, nil, nil, nil))
104104
_, err := projectManager.CreateProject(context.Background(), admin.ProjectRegisterRequest{
105105
Project: &admin.Project{
106106
Id: "flyte-project-id",

pkg/manager/impl/task_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const limit = 100
3737
func getMockConfigForTaskTest() runtimeInterfaces.Configuration {
3838
mockConfig := runtimeMocks.NewMockConfigurationProvider(
3939
testutils.GetApplicationConfigWithDefaultProjects(), nil, nil, runtimeMocks.NewMockTaskResourceConfiguration(
40-
runtimeInterfaces.TaskResourceSet{}, runtimeInterfaces.TaskResourceSet{}), runtimeMocks.NewMockWhitelistConfiguration())
40+
runtimeInterfaces.TaskResourceSet{}, runtimeInterfaces.TaskResourceSet{}), runtimeMocks.NewMockWhitelistConfiguration(), nil)
4141
return mockConfig
4242
}
4343

pkg/manager/impl/workflow_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var workflowClosureBytes, _ = proto.Marshal(&workflowClosure)
6969

7070
func getMockWorkflowConfigProvider() runtimeInterfaces.Configuration {
7171
mockWorkflowConfigProvider := runtimeMocks.NewMockConfigurationProvider(
72-
testutils.GetApplicationConfigWithDefaultProjects(), nil, nil, nil, nil)
72+
testutils.GetApplicationConfigWithDefaultProjects(), nil, nil, nil, nil, nil)
7373
mockWorkflowConfigProvider.(*runtimeMocks.MockConfigurationProvider).AddRegistrationValidationConfiguration(
7474
runtimeMocks.NewMockRegistrationValidationProvider())
7575
return mockWorkflowConfigProvider

0 commit comments

Comments
 (0)