4
4
package postprocess
5
5
6
6
import (
7
- "bytes"
8
- "fmt"
9
- "os"
10
- "strings"
11
-
12
7
"github.com/gitpod-io/gitpod/installer/pkg/common"
13
8
openvsxproxy "github.com/gitpod-io/gitpod/installer/pkg/components/openvsx-proxy"
14
- "github.com/mikefarah/yq/v4/pkg/yqlib"
15
- logging "gopkg.in/op/go-logging.v1"
9
+ "github.com/gitpod-io/gitpod/installer/pkg/yq"
16
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
11
"k8s.io/utils/pointer"
18
12
)
@@ -38,52 +32,6 @@ type Processor struct {
38
32
Name * string // Optional
39
33
}
40
34
41
- // process emulates how YQ parsers the file
42
- func process (expression string , obj * common.RuntimeObject ) error {
43
- // Stop the logging to Stderr
44
- var format = logging .MustStringFormatter (
45
- `%{color}%{time:15:04:05} %{shortfunc} [%{level:.4s}]%{color:reset} %{message}` ,
46
- )
47
- var backend = logging .AddModuleLevel (
48
- logging .NewBackendFormatter (logging .NewLogBackend (os .Stderr , "" , 0 ), format ))
49
-
50
- backend .SetLevel (logging .ERROR , "" )
51
- logging .SetBackend (backend )
52
- // End of logger config
53
-
54
- yqlib .InitExpressionParser ()
55
-
56
- var writer bytes.Buffer
57
- printerWriter := yqlib .NewSinglePrinterWriter (& writer )
58
- encoder := yqlib .NewYamlEncoder (2 , false , false , true )
59
-
60
- printer := yqlib .NewPrinter (encoder , printerWriter )
61
-
62
- decoder := yqlib .NewYamlDecoder ()
63
-
64
- streamEvaluator := yqlib .NewStreamEvaluator ()
65
-
66
- reader := strings .NewReader (obj .Content )
67
-
68
- node , err := yqlib .ExpressionParser .ParseExpression (expression )
69
- if err != nil {
70
- return err
71
- }
72
-
73
- // This is used for debugging
74
- filename := fmt .Sprintf ("%s %s %s" , obj .APIVersion , obj .Kind , obj .Metadata .Name )
75
-
76
- _ , err = streamEvaluator .Evaluate (filename , reader , node , printer , "" , decoder )
77
- if err != nil {
78
- return err
79
- }
80
-
81
- // Overwrite the content with the parsed data
82
- obj .Content = writer .String ()
83
-
84
- return nil
85
- }
86
-
87
35
func useProcessor (object common.RuntimeObject , processor Processor ) bool {
88
36
if object .APIVersion == processor .Type .APIVersion && object .Kind == processor .Type .Kind {
89
37
// Name is optional
@@ -105,10 +53,11 @@ func Run(objects []common.RuntimeObject) ([]common.RuntimeObject, error) {
105
53
for _ , o := range objects {
106
54
for _ , p := range Processors {
107
55
if useProcessor (o , p ) {
108
- err := process ( p . Expression , & o )
56
+ output , err := yq . Process ( o . Content , p . Expression )
109
57
if err != nil {
110
58
return nil , err
111
59
}
60
+ o .Content = * output
112
61
}
113
62
}
114
63
0 commit comments