-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpumanagement.go
55 lines (43 loc) · 1.55 KB
/
gpumanagement.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
55
package gpu
import (
"fmt"
"github.com/rancher/rancher/pkg/ref"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type AppLevel string
const (
SystemLevel AppLevel = "system"
ClusterLevel AppLevel = "cluster"
ProjectLevel AppLevel = "project"
)
const (
cattleNamespaceName = "cattle-gpumanagement"
)
const (
//CattleMonitoringLabelKey The label info of Namespace
cattleMonitoringLabelKey = "gpumanagement.cattle.io"
// The label info of App, RoleBinding
appNameLabelKey = cattleMonitoringLabelKey + "/appName"
appTargetNamespaceLabelKey = cattleMonitoringLabelKey + "/appTargetNamespace"
appProjectIDLabelKey = cattleMonitoringLabelKey + "/projectID"
appClusterIDLabelKey = cattleMonitoringLabelKey + "/clusterID"
// The names of App
clusterLevelAppName = "cluster-gpu-management"
)
func ClusterGPUManagementInfo() (appName, appTargetNamespace string) {
return clusterLevelAppName, cattleNamespaceName
}
func OwnedAppListOptions(clusterID, appName, appTargetNamespace string) metav1.ListOptions {
return metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s, %s=%s, %s=%s", appClusterIDLabelKey, clusterID, appNameLabelKey, appName, appTargetNamespaceLabelKey, appTargetNamespace),
}
}
func OwnedLabels(appName, appTargetNamespace, appProjectName string) map[string]string {
clusterID, projectID := ref.Parse(appProjectName)
return map[string]string{
appNameLabelKey: appName,
appTargetNamespaceLabelKey: appTargetNamespace,
appProjectIDLabelKey: projectID,
appClusterIDLabelKey: clusterID,
}
}