forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_index.go
40 lines (35 loc) · 944 Bytes
/
workflow_index.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
package indexes
import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/tools/cache"
"github.com/argoproj/argo-workflows/v3/workflow/common"
"github.com/argoproj/argo-workflows/v3/workflow/util"
)
func MetaWorkflowIndexFunc(obj interface{}) ([]string, error) {
m, err := meta.Accessor(obj)
if err != nil {
return nil, nil
}
name, ok := m.GetLabels()[common.LabelKeyWorkflow]
if !ok {
return nil, nil
}
return []string{WorkflowIndexValue(m.GetNamespace(), name)}, nil
}
func WorkflowIndexValue(namespace, name string) string {
return namespace + "/" + name
}
func WorkflowSemaphoreKeysIndexFunc() cache.IndexFunc {
return func(obj interface{}) ([]string, error) {
un, ok := obj.(*unstructured.Unstructured)
if !ok {
return nil, nil
}
wf, err := util.FromUnstructured(un)
if err != nil {
return nil, nil
}
return wf.GetSemaphoreKeys(), nil
}
}