-
Notifications
You must be signed in to change notification settings - Fork 90
/
kots.go
42 lines (34 loc) · 1.06 KB
/
kots.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
41
42
package client
import (
"strings"
"github.com/pkg/errors"
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
"k8s.io/client-go/kubernetes/scheme"
)
func removeInternalGVK(manifests []byte) ([]byte, error) {
cleaned := []string{}
splitRenderedContents := strings.Split(string(manifests), "\n---\n")
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
for _, splitRenderedContent := range splitRenderedContents {
decode := scheme.Codecs.UniversalDeserializer().Decode
_, gvk, err := decode([]byte(splitRenderedContent), nil, nil)
if err != nil {
return nil, errors.Wrap(err, "unable to decode yaml")
}
if gvk.Group == "troubleshoot.replicated.com" {
if gvk.Version == "v1beta1" {
if gvk.Kind == "Collector" {
continue
}
if gvk.Kind == "Preflight" {
continue
}
}
}
if gvk.Group == "velero.io" && gvk.Version == "v1" && gvk.Kind == "Backup" {
continue
}
cleaned = append(cleaned, splitRenderedContent)
}
return []byte(strings.Join(cleaned, "\n---\n")), nil
}