...
1
2
3
4 package filter
5
6 import (
7 "fmt"
8
9 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
10 "sigs.k8s.io/cli-utils/pkg/common"
11 )
12
13
14
15
16 type PreventRemoveFilter struct{}
17
18 const PreventRemoveFilterName = "PreventRemoveFilter"
19
20
21
22 func (prf PreventRemoveFilter) Name() string {
23 return PreventRemoveFilterName
24 }
25
26
27
28 func (prf PreventRemoveFilter) Filter(obj *unstructured.Unstructured) error {
29 for annotation, value := range obj.GetAnnotations() {
30 if common.NoDeletion(annotation, value) {
31 return &AnnotationPreventedDeletionError{
32 Annotation: annotation,
33 Value: value,
34 }
35 }
36 }
37 return nil
38 }
39
40 type AnnotationPreventedDeletionError struct {
41 Annotation string
42 Value string
43 }
44
45 func (e *AnnotationPreventedDeletionError) Error() string {
46 return fmt.Sprintf("annotation prevents deletion (%q: %q)", e.Annotation, e.Value)
47 }
48
49 func (e *AnnotationPreventedDeletionError) Is(err error) bool {
50 if err == nil {
51 return false
52 }
53 tErr, ok := err.(*AnnotationPreventedDeletionError)
54 if !ok {
55 return false
56 }
57 return e.Annotation == tErr.Annotation &&
58 e.Value == tErr.Value
59 }
60
View as plain text