forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customizable user namespace templating (flyteorg#223)
- Loading branch information
Katrina Rogan
authored
Jul 20, 2021
1 parent
c435291
commit 8152f28
Showing
7 changed files
with
44 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
package common | ||
|
||
import "fmt" | ||
import ( | ||
"strings" | ||
) | ||
|
||
type NamespaceMapping int | ||
const projectTemplate = "{{ project }}" | ||
const domainTemplate = "{{ domain }}" | ||
|
||
const namespaceFormat = "%s-%s" | ||
const replaceAllInstancesOfString = -1 | ||
|
||
const ( | ||
NamespaceMappingProjectDomain NamespaceMapping = iota | ||
NamespaceMappingDomain NamespaceMapping = iota | ||
NamespaceMappingProject NamespaceMapping = iota | ||
) | ||
// GetNamespaceName returns kubernetes namespace name according to user defined template from config | ||
func GetNamespaceName(template string, project, domain string) string { | ||
var namespace = template | ||
namespace = strings.Replace(namespace, projectTemplate, project, replaceAllInstancesOfString) | ||
namespace = strings.Replace(namespace, domainTemplate, domain, replaceAllInstancesOfString) | ||
|
||
// GetNamespaceName returns kubernetes namespace name | ||
func GetNamespaceName(mapping NamespaceMapping, project, domain string) string { | ||
switch mapping { | ||
case NamespaceMappingDomain: | ||
return domain | ||
case NamespaceMappingProject: | ||
return project | ||
case NamespaceMappingProjectDomain: | ||
fallthrough | ||
default: | ||
return fmt.Sprintf(namespaceFormat, project, domain) | ||
} | ||
return namespace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package interfaces | ||
|
||
import "github.com/flyteorg/flyteadmin/pkg/common" | ||
|
||
type NamespaceMappingConfig struct { | ||
Mapping string `json:"mapping"` | ||
Mapping string `json:"mapping"` // Deprecated | ||
Template string `json:"template"` | ||
TemplateData TemplateData `json:"templateData"` | ||
} | ||
|
||
type NamespaceMappingConfiguration interface { | ||
GetNamespaceMappingConfig() common.NamespaceMapping | ||
GetNamespaceTemplate() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters