From 1ef63b1159f6a0a43acfa17c2ca59739b153a671 Mon Sep 17 00:00:00 2001 From: Jeev B Date: Thu, 25 Mar 2021 11:37:11 -0700 Subject: [PATCH] Add option to use project name as namespace for the task pods (#166) * Add option to use project name as namespace for the task pods Signed-off-by: Jeev B * rename Signed-off-by: Jeev B --- pkg/common/namespace.go | 11 +++++++---- pkg/common/namespace_test.go | 5 +++-- pkg/runtime/namespace_config_provider.go | 9 ++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/common/namespace.go b/pkg/common/namespace.go index 41e7601c9d..6998fcee7c 100644 --- a/pkg/common/namespace.go +++ b/pkg/common/namespace.go @@ -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) diff --git a/pkg/common/namespace_test.go b/pkg/common/namespace_test.go index 4a4d819f2b..a23945839e 100644 --- a/pkg/common/namespace_test.go +++ b/pkg/common/namespace_test.go @@ -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 { diff --git a/pkg/runtime/namespace_config_provider.go b/pkg/runtime/namespace_config_provider.go index f7d969745c..7e07aab1f8 100644 --- a/pkg/runtime/namespace_config_provider.go +++ b/pkg/runtime/namespace_config_provider.go @@ -12,6 +12,7 @@ import ( const ( namespaceMappingKey = "namespace_mapping" domainVariable = "domain" + projectVariable = "project" projectDomainVariable = "project-domain" ) @@ -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 -") - return common.ProjectDomain + return common.NamespaceMappingProjectDomain } }