Skip to content

Commit

Permalink
Add option to use project name as namespace for the task pods (flyteo…
Browse files Browse the repository at this point in the history
…rg#166)

* Add option to use project name as namespace for the task pods

Signed-off-by: Jeev B <[email protected]>

* rename

Signed-off-by: Jeev B <[email protected]>
  • Loading branch information
jeevb authored Mar 25, 2021
1 parent f0ec216 commit 1ef63b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
11 changes: 7 additions & 4 deletions pkg/common/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ type NamespaceMapping int
const namespaceFormat = "%s-%s"

const (
ProjectDomain NamespaceMapping = iota
Domain NamespaceMapping = iota
NamespaceMappingProjectDomain NamespaceMapping = iota
NamespaceMappingDomain NamespaceMapping = iota
NamespaceMappingProject NamespaceMapping = iota
)

// GetNamespaceName returns kubernetes namespace name
func GetNamespaceName(mapping NamespaceMapping, project, domain string) string {
switch mapping {
case Domain:
case NamespaceMappingDomain:
return domain
case ProjectDomain:
case NamespaceMappingProject:
return project
case NamespaceMappingProjectDomain:
fallthrough
default:
return fmt.Sprintf(namespaceFormat, project, domain)
Expand Down
5 changes: 3 additions & 2 deletions pkg/common/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ func TestGetNamespaceName(t *testing.T) {
domain string
want string
}{
{ProjectDomain, "project", "production", "project-production"},
{NamespaceMappingProjectDomain, "project", "production", "project-production"},
{20 /*Dummy enum value that is not supported*/, "project", "development", "project-development"},
{Domain, "project", "production", "production"},
{NamespaceMappingDomain, "project", "production", "production"},
{NamespaceMappingProject, "project", "production", "project"},
}

for _, tc := range testCases {
Expand Down
9 changes: 6 additions & 3 deletions pkg/runtime/namespace_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
const (
namespaceMappingKey = "namespace_mapping"
domainVariable = "domain"
projectVariable = "project"
projectDomainVariable = "project-domain"
)

Expand All @@ -27,12 +28,14 @@ func (p *NamespaceMappingConfigurationProvider) GetNamespaceMappingConfig() comm

switch mapping {
case domainVariable:
return common.Domain
return common.NamespaceMappingDomain
case projectVariable:
return common.NamespaceMappingProject
case projectDomainVariable:
return common.ProjectDomain
return common.NamespaceMappingProjectDomain
default:
logger.Warningf(context.Background(), "Unsupported value for namespace_mapping in config, defaulting to <project>-<domain>")
return common.ProjectDomain
return common.NamespaceMappingProjectDomain
}
}

Expand Down

0 comments on commit 1ef63b1

Please sign in to comment.