37 Star 396 Fork 71

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
common.go 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
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)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.11-rc3

搜索帮助

344bd9b3 5694891 D2dac590 5694891