-
Notifications
You must be signed in to change notification settings - Fork 443
/
debug_print_resource.go
64 lines (55 loc) · 1.29 KB
/
debug_print_resource.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package debugprint
import (
"fmt"
"log"
"strings"
"github.com/golang/protobuf/proto"
"github.com/onsi/ginkgo/v2"
"github.com/solo-io/gloo/pkg/utils/protoutils"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd"
"github.com/solo-io/solo-kit/pkg/api/v1/resources"
"sigs.k8s.io/yaml"
)
func PrintYaml(ress ...proto.Message) {
log.Printf(SprintYaml(ress...))
}
func GinkgoPrintYaml(ress ...proto.Message) {
fmt.Fprint(ginkgo.GinkgoWriter, SprintYaml(ress...))
}
func PrintKube(crd crd.Crd, ress ...resources.InputResource) error {
for _, rs := range ress {
res, err := crd.KubeResource(rs)
if err != nil {
return err
}
yam, err := yaml.Marshal(res)
if err != nil {
return err
}
log.Printf("%s", yam)
}
return nil
}
func PrintAny(any ...interface{}) {
for _, res := range any {
yam, _ := yaml.Marshal(res)
log.Printf("%s", yam)
}
}
func SprintAny(any ...interface{}) string {
var yams []string
for _, res := range any {
yam, _ := yaml.Marshal(res)
yams = append(yams, string(yam))
}
return strings.Join(yams, "\n---\n")
}
func SprintYaml(ress ...proto.Message) string {
var yams []string
for _, res := range ress {
js, _ := protoutils.MarshalBytes(res)
yam, _ := yaml.JSONToYAML(js)
yams = append(yams, string(yam))
}
return strings.Join(yams, "\n---\n")
}