...
1
2
3
4 package filter
5
6 import (
7 "fmt"
8
9 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
10 "k8s.io/apimachinery/pkg/types"
11 "k8s.io/apimachinery/pkg/util/sets"
12 )
13
14
15
16
17 type CurrentUIDFilter struct {
18 CurrentUIDs sets.String
19 }
20
21
22 func (cuf CurrentUIDFilter) Name() string {
23 return "CurrentUIDFilter"
24 }
25
26
27
28 func (cuf CurrentUIDFilter) Filter(obj *unstructured.Unstructured) error {
29 uid := obj.GetUID()
30 if cuf.CurrentUIDs.Has(string(uid)) {
31 return &ApplyPreventedDeletionError{UID: uid}
32 }
33 return nil
34 }
35
36 type ApplyPreventedDeletionError struct {
37 UID types.UID
38 }
39
40 func (e *ApplyPreventedDeletionError) Error() string {
41 return fmt.Sprintf("object just applied (UID: %q)", e.UID)
42 }
43
44 func (e *ApplyPreventedDeletionError) Is(err error) bool {
45 if err == nil {
46 return false
47 }
48 tErr, ok := err.(*ApplyPreventedDeletionError)
49 if !ok {
50 return false
51 }
52 return e.UID == tErr.UID
53 }
54
View as plain text