...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package annotation
17
18 import (
19 "k8s.io/apimachinery/pkg/labels"
20 "sigs.k8s.io/controller-runtime/pkg/client"
21
22 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
23 "github.com/chaos-mesh/chaos-mesh/pkg/label"
24 "github.com/chaos-mesh/chaos-mesh/pkg/selector/generic"
25 )
26
27 const Name = "annotation"
28
29 type annotationSelector struct {
30 labels.Selector
31 }
32
33 var _ generic.Selector = &annotationSelector{}
34
35 func (s *annotationSelector) ListOption() client.ListOption {
36 return nil
37 }
38
39 func (s *annotationSelector) ListFunc(_ client.Reader) generic.ListFunc {
40 return nil
41 }
42
43 func (s *annotationSelector) Match(obj client.Object) bool {
44 annotations := labels.Set(obj.GetAnnotations())
45 return s.Matches(annotations)
46 }
47
48 func New(spec v1alpha1.GenericSelectorSpec, _ generic.Option) (generic.Selector, error) {
49 selectorStr := label.Label(spec.AnnotationSelectors).String()
50 s, err := labels.Parse(selectorStr)
51 if err != nil {
52 return nil, err
53 }
54 return &annotationSelector{Selector: s}, nil
55 }
56