@@ -21,6 +21,12 @@ var SecretSelectedFields = []string{
21
21
"/data/ca.crt" ,
22
22
}
23
23
24
+ // RedactFields are removed from all objects
25
+ var RedactFields = []string {
26
+ "metadata.managedFields" ,
27
+ "/metadata.annotations/kubectl.kubernetes.io~1last-applied-configuration" ,
28
+ }
29
+
24
30
// Select removes all but the supplied fields from the resource
25
31
func Select (fields []string , resource * unstructured.Unstructured ) error {
26
32
// convert the object to JSON for field filtering
@@ -45,8 +51,11 @@ func Select(fields []string, resource *unstructured.Unstructured) error {
45
51
// fail to select field if missing, just continue
46
52
continue
47
53
}
48
- pathComponents := strings .Split (v , "/" )
49
- filteredObject .Set (gObject .Data (), pathComponents [1 :]... )
54
+ pathComponents , err := gabs .JSONPointerToSlice (v )
55
+ if err != nil {
56
+ return fmt .Errorf ("invalid JSONPointer: %s" , v )
57
+ }
58
+ filteredObject .Set (gObject .Data (), pathComponents ... )
50
59
} else {
51
60
if jsonParsed .ExistsP (v ) {
52
61
filteredObject .SetP (jsonParsed .Path (v ).Data (), v )
@@ -81,7 +90,10 @@ func Redact(fields []string, resource *unstructured.Unstructured) error {
81
90
for _ , v := range fields {
82
91
// also support JSONPointers for keys containing '.' chars
83
92
if strings .HasPrefix (v , "/" ) {
84
- pathComponents := strings .Split (v , "/" )[1 :]
93
+ pathComponents , err := gabs .JSONPointerToSlice (v )
94
+ if err != nil {
95
+ return fmt .Errorf ("invalid JSONPointer: %s" , v )
96
+ }
85
97
if jsonParsed .Exists (pathComponents ... ) {
86
98
jsonParsed .Delete (pathComponents ... )
87
99
}
0 commit comments