-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
labels.go
42 lines (37 loc) · 1.06 KB
/
labels.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
package indexes
import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/tools/cache"
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/workflow/common"
)
func MetaNamespaceLabelIndex(namespace, label string) string {
return namespace + "/" + label
}
func MetaWorkflowPhaseIndexFunc() cache.IndexFunc {
return func(obj interface{}) ([]string, error) {
v, err := meta.Accessor(obj)
if err != nil {
return nil, nil
}
if value, exists := v.GetLabels()[common.LabelKeyPhase]; exists {
return []string{value}, nil
} else {
// If the object doesn't have a phase set, consider it pending
return []string{string(v1alpha1.NodePending)}, nil
}
}
}
func MetaNamespaceLabelIndexFunc(label string) cache.IndexFunc {
return func(obj interface{}) ([]string, error) {
v, err := meta.Accessor(obj)
if err != nil {
return nil, nil
}
if value, exists := v.GetLabels()[label]; exists {
return []string{MetaNamespaceLabelIndex(v.GetNamespace(), value)}, nil
} else {
return nil, nil
}
}
}