/
utils.go
47 lines (39 loc) · 1.27 KB
/
utils.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package server
import (
api "github.com/weaveworks/weave-gitops/pkg/api/core"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func getMatchingLabels(appName string) client.MatchingLabels {
return matchLabel(withPartOfLabel(appName))
}
func GetTenant(namespace, clusterName string, clusterUserNamespaces map[string][]v1.Namespace) string {
for _, ns := range clusterUserNamespaces[clusterName] {
if ns.GetName() == namespace {
return ns.Labels["toolkit.fluxcd.io/tenant"]
}
}
return ""
}
func GetClusterUserNamespacesNames(clusterUserNamespaces map[string][]v1.Namespace) []*api.ClusterNamespaceList {
clusterNamespaces := []*api.ClusterNamespaceList{}
for clusterName, namespaces := range clusterUserNamespaces {
namespaceNames := []string{}
for _, namespace := range namespaces {
namespaceNames = append(namespaceNames, namespace.Name)
}
clusterNamespaces = append(clusterNamespaces, &api.ClusterNamespaceList{
ClusterName: clusterName,
Namespaces: namespaceNames,
})
}
return clusterNamespaces
}
// ExtractValueFromMap gets string value from map or empty string if the value is empty
func ExtractStringValueFromMap(mapName map[string]string, key string) string {
value, ok := mapName[key]
if !ok {
return ""
}
return value
}