forked from kro-run/kro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectors.go
59 lines (52 loc) · 2.32 KB
/
selectors.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
56
57
58
59
// Copyright 2025 The Kube Resource Orchestrator Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package metadata
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// Sometimes we need to search for resources that belong to given instance, resource graph definition or node.
// This is helpful to for garbage collection of resources that are no longer needed, or got
// orphaned due to graph evolutions.
func NewInstanceSelector(instance metav1.Object) metav1.LabelSelector {
return metav1.LabelSelector{
MatchLabels: map[string]string{
InstanceIDLabel: string(instance.GetUID()),
// InstanceNameLabel: instance.GetName(),
// InstanceNamespaceLabel: instance.GetNamespace(),
},
}
}
func NewResourceGraphDefinitionSelector(resourceGraphDefinition metav1.Object) metav1.LabelSelector {
return metav1.LabelSelector{
MatchLabels: map[string]string{
ResourceGraphDefinitionIDLabel: string(resourceGraphDefinition.GetUID()),
// ResourceGraphDefinitionNameLabel: resourceGraphDefinition.GetName(),
// ResourceGraphDefinitionNamespaceLabel: resourceGraphDefinition.GetNamespace(),
},
}
}
func NewInstanceAndResourceGraphDefinitionSelector(instance metav1.Object, resourceGraphDefinition metav1.Object) metav1.LabelSelector {
return metav1.LabelSelector{
MatchLabels: map[string]string{
InstanceIDLabel: string(instance.GetUID()),
ResourceGraphDefinitionIDLabel: string(resourceGraphDefinition.GetUID()),
},
}
}
func NewNodeAndInstanceAndResourceGraphDefinitionSelector(node metav1.Object, instance metav1.Object, resourceGraphDefinition metav1.Object) metav1.LabelSelector {
return metav1.LabelSelector{
MatchLabels: map[string]string{
NodeIDLabel: node.GetName(),
InstanceIDLabel: string(instance.GetUID()),
ResourceGraphDefinitionIDLabel: string(resourceGraphDefinition.GetUID()),
},
}
}