-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
54 lines (42 loc) · 1.54 KB
/
common.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
48
49
50
51
52
53
54
package common
import (
"fmt"
"github.com/rancher/rancher/pkg/ref"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
)
func GetRuleID(groupID string, ruleName string) string {
return fmt.Sprintf("%s_%s", groupID, ruleName)
}
func GetGroupID(namespace, name string) string {
return fmt.Sprintf("%s:%s", namespace, name)
}
func GetAlertManagerSecretName(appName string) string {
return fmt.Sprintf("alertmanager-%s", appName)
}
func GetAlertManagerDaemonsetName(appName string) string {
return fmt.Sprintf("alertmanager-%s", appName)
}
func formatProjectDisplayName(projectDisplayName, projectID string) string {
return fmt.Sprintf("%s (ID: %s)", projectDisplayName, projectID)
}
func formatClusterDisplayName(clusterDisplayName, clusterID string) string {
return fmt.Sprintf("%s (ID: %s)", clusterDisplayName, clusterID)
}
func GetClusterDisplayName(clusterName string, clusterLister v3.ClusterLister) string {
cluster, err := clusterLister.Get("", clusterName)
if err != nil {
logrus.Warnf("Failed to get cluster for %s: %v", clusterName, err)
return clusterName
}
return formatClusterDisplayName(cluster.Spec.DisplayName, clusterName)
}
func GetProjectDisplayName(projectID string, projectLister v3.ProjectLister) string {
clusterName, projectName := ref.Parse(projectID)
project, err := projectLister.Get(clusterName, projectName)
if err != nil {
logrus.Warnf("Failed to get project %s: %v", projectID, err)
return projectID
}
return formatProjectDisplayName(project.Spec.DisplayName, projectID)
}