Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/postprocess/postprocess.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
/// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package postprocess
6
7
import (
8
"github.com/gitpod-io/gitpod/installer/pkg/common"
9
openvsxproxy "github.com/gitpod-io/gitpod/installer/pkg/components/openvsx-proxy"
10
"github.com/gitpod-io/gitpod/installer/pkg/yq"
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
"k8s.io/utils/pointer"
13
)
14
15
// Processors list of processes executed on each resource document
16
var Processors = []Processor{
17
// Remove "status" from root of all network policies
18
{
19
Type: common.TypeMetaNetworkPolicy,
20
Expression: "del(.status)",
21
},
22
// Remove "status" from root of OpenVSXProxy stateful sets
23
{
24
Type: common.TypeMetaStatefulSet,
25
Expression: "del(.status)",
26
Name: pointer.String(openvsxproxy.Component),
27
},
28
}
29
30
type Processor struct {
31
Type metav1.TypeMeta
32
Expression string
33
Name *string // Optional
34
}
35
36
func useProcessor(object common.RuntimeObject, processor Processor) bool {
37
if object.APIVersion == processor.Type.APIVersion && object.Kind == processor.Type.Kind {
38
// Name is optional
39
if processor.Name == nil {
40
// Name not specified - return
41
return true
42
}
43
44
// Name specified - match
45
return object.Metadata.Name == *processor.Name
46
}
47
48
return false
49
}
50
51
func Run(objects []common.RuntimeObject) ([]common.RuntimeObject, error) {
52
result := make([]common.RuntimeObject, 0)
53
54
for _, o := range objects {
55
for _, p := range Processors {
56
if useProcessor(o, p) {
57
output, err := yq.Process(o.Content, p.Expression)
58
if err != nil {
59
return nil, err
60
}
61
o.Content = *output
62
}
63
}
64
65
result = append(result, o)
66
}
67
68
return result, nil
69
}
70
71