@@ -3,6 +3,7 @@ package codegen_test
3
3
import (
4
4
"bytes"
5
5
"encoding/json"
6
+ "fmt"
6
7
"io/ioutil"
7
8
"os"
8
9
"os/exec"
@@ -39,7 +40,117 @@ var _ = Describe("Cmd", func() {
39
40
skv2Imports .External ["github.com/solo-io/cue" ] = []string {
40
41
"encoding/protobuf/cue/cue.proto" ,
41
42
}
43
+ It ("install conditional sidecars" , func () {
44
+ var (
45
+ agentConditional = "and ($.Values.glooAgent.enabled) ($.Values.glooAgent.runAsSidecar)"
46
+ )
47
+
48
+ cmd := & Command {
49
+ Chart : & Chart {
50
+ Operators : []Operator {
51
+ {
52
+ Name : "gloo-mgmt-server" ,
53
+ Service : Service {
54
+ Ports : []ServicePort {{
55
+ Name : "grpc" ,
56
+ DefaultPort : 9900 ,
57
+ }},
58
+ },
59
+ Rbac : []rbacv1.PolicyRule {{
60
+ Verbs : []string {"*" },
61
+ APIGroups : []string {"coordination.k8s.io" },
62
+ Resources : []string {"leases" },
63
+ }},
64
+ Deployment : Deployment {
65
+ Sidecars : []Sidecar {
66
+ {
67
+ Name : "gloo-agent" ,
68
+ Volumes : []v1.Volume {
69
+ {
70
+ Name : "agent-volume" ,
71
+ VolumeSource : v1.VolumeSource {
72
+ Secret : & v1.SecretVolumeSource {
73
+ SecretName : "agent-volume" ,
74
+ },
75
+ },
76
+ },
77
+ {
78
+ Name : "agent-volume-2" ,
79
+ VolumeSource : v1.VolumeSource {
80
+ Secret : & v1.SecretVolumeSource {
81
+ SecretName : "agent-volume" ,
82
+ },
83
+ },
84
+ },
85
+ },
86
+ Rbac : []rbacv1.PolicyRule {{
87
+ Verbs : []string {"*" },
88
+ APIGroups : []string {"apiextensions.k8s.io" },
89
+ Resources : []string {"customresourcedefinitions" },
90
+ }},
91
+ Container : Container {
92
+ Image : Image {
93
+ Registry : "gcr.io/gloo-mesh" ,
94
+ Repository : "gloo-mesh-agent" ,
95
+ Tag : "0.0.1" ,
96
+ },
97
+ },
98
+ Service : Service {
99
+ Ports : []ServicePort {{
100
+ Name : "grpc" ,
101
+ DefaultPort : 9977 ,
102
+ }},
103
+ },
104
+ EnableStatement : agentConditional ,
105
+ ValuesPath : "$.Values.glooAgent" ,
106
+ },
107
+ },
108
+ Container : Container {
109
+ Image : Image {
110
+ Registry : "gcr.io/gloo-mesh" ,
111
+ Repository : "gloo-mesh-mgmt-server" ,
112
+ Tag : "0.0.1" ,
113
+ },
114
+ VolumeMounts : []v1.VolumeMount {{
115
+ Name : "license-keys" ,
116
+ MountPath : "/etc/gloo-mesh/license-keys" ,
117
+ ReadOnly : true ,
118
+ }},
119
+ },
120
+ Volumes : []v1.Volume {
121
+ {
122
+ Name : "license-keys" ,
123
+ VolumeSource : v1.VolumeSource {
124
+ Secret : & v1.SecretVolumeSource {
125
+ SecretName : "license-keys" ,
126
+ },
127
+ },
128
+ },
129
+ },
130
+ },
131
+ },
132
+ {
133
+ Name : "gloo-agent" ,
134
+ CustomEnableCondition : `and ($.Values.glooAgent.enabled) (not $.Values.glooAgent.runAsSidecar)` ,
135
+ },
136
+ },
137
+ },
138
+ ManifestRoot : "codegen/test/chart/conditional-sidecar" ,
139
+ }
140
+
141
+ Expect (cmd .Execute ()).NotTo (HaveOccurred (), "failed to execute command" )
42
142
143
+ absPath , err := filepath .Abs ("./test/chart/conditional-sidecar/templates/deployment.yaml" )
144
+ Expect (err ).NotTo (HaveOccurred (), "failed to get abs path" )
145
+
146
+ deployment , err := os .ReadFile (absPath )
147
+ Expect (err ).NotTo (HaveOccurred (), "failed to read deployment.yaml" )
148
+
149
+ Expect (deployment ).To (ContainSubstring (fmt .Sprintf ("{{- if %s -}}" , agentConditional )))
150
+ Expect (deployment ).To (ContainSubstring (fmt .Sprintf ("{{- if %s }}" , "and ($.Values.glooAgent.enabled) (not $.Values.glooAgent.runAsSidecar)" )))
151
+ Expect (deployment ).To (ContainSubstring ("name: agent-volume" ))
152
+ Expect (deployment ).To (ContainSubstring ("{{ $glooAgent.ports.grpc }}" ))
153
+ })
43
154
It ("generates controller code and manifests for a proto file" , func () {
44
155
cmd := & Command {
45
156
Groups : []Group {
@@ -1107,8 +1218,8 @@ var _ = Describe("Cmd", func() {
1107
1218
Chart : & Chart {
1108
1219
Operators : []Operator {
1109
1220
{
1110
- Name : "painter" ,
1111
- EnabledDependsOn : [] string { " test1" , " test2" } ,
1221
+ Name : "painter" ,
1222
+ CustomEnableCondition : "and $painter.enabled $.Values. test1.enabled $.Values. test2.enabled" ,
1112
1223
Rbac : []rbacv1.PolicyRule {
1113
1224
{
1114
1225
Verbs : []string {"GET" },
0 commit comments