-
Notifications
You must be signed in to change notification settings - Fork 9
/
naming.go
31 lines (24 loc) · 964 Bytes
/
naming.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package kubernetes
import (
"path/filepath"
"regexp"
"strings"
"namespacelabs.dev/foundation/internal/support/naming"
"namespacelabs.dev/foundation/schema"
)
var (
validChars = regexp.MustCompile("[a-z0-9]+")
)
// We use namespaces to isolate deployments per workspace and environment.
// Using the path base plus a digest provides short, memorable names and avoids collision.
// TODO add knob to allow namespace overwrites if the need arises.
func ModuleNamespace(ws *schema.Workspace, env *schema.Environment) string {
parts := []string{strings.ToLower(env.Name)}
parts = append(parts, validChars.FindAllString(filepath.Base(ws.ModuleName), -1)...)
id := naming.StableIDN(ws.ModuleName, 5)
parts = append(parts, id)
return strings.Join(parts, "-")
}