generated from cloudoperators/repository-template
/
prune.go
40 lines (35 loc) · 1.18 KB
/
prune.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
// SPDX-License-Identifier: Apache-2.0
package helm
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
)
type pruneFunc func(o runtime.Object) runtime.Object
var (
// Prune the managedFields in the object to obfuscating the diff.
pruneManagedFields pruneFunc = func(o runtime.Object) runtime.Object {
metaObject, err := meta.Accessor(o)
if err != nil {
// The object might not declare the required metadata in which case the original object is returned.
return o
}
metaObject.SetManagedFields(nil)
return o
}
// Prune the last-applied annotation in the object to obfuscating the diff.
pruneLastAppliedAnnotation pruneFunc = func(o runtime.Object) runtime.Object {
metaObject, err := meta.Accessor(o)
if err != nil {
// The object might not declare the required metadata in which case the original object is returned.
return o
}
annotations := metaObject.GetAnnotations()
if annotations != nil {
delete(annotations, corev1.LastAppliedConfigAnnotation)
}
metaObject.SetAnnotations(annotations)
return o
}
)