@@ -2134,6 +2134,105 @@ roleRef:
2134
2134
}),
2135
2135
)
2136
2136
2137
+ DescribeTable ("rendering with GlobalFloatingUserId" ,
2138
+ func (floatingUserId bool ) {
2139
+ cmd := & Command {
2140
+ Chart : & Chart {
2141
+ Operators : []Operator {
2142
+ {
2143
+ Name : "painter" ,
2144
+ Deployment : Deployment {
2145
+ Container : Container {
2146
+ Image : Image {
2147
+ Tag : "v0.0.0" ,
2148
+ Repository : "painter" ,
2149
+ Registry : "quay.io/solo-io" ,
2150
+ PullPolicy : "IfNotPresent" ,
2151
+ },
2152
+ },
2153
+ },
2154
+ GlobalFloatingUserIdPath : ".Values.global.securitySettings.floatingUserId" ,
2155
+ },
2156
+ },
2157
+ // Because the global override comes from .Values it has to be set here, not on the painter
2158
+ Values : map [string ]interface {}{
2159
+ "global" : map [string ]interface {}{
2160
+ "securitySettings" : map [string ]interface {}{
2161
+ "floatingUserId" : floatingUserId ,
2162
+ },
2163
+ },
2164
+ },
2165
+ Data : Data {
2166
+ ApiVersion : "v1" ,
2167
+ Description : "" ,
2168
+ Name : "Painting Operator" ,
2169
+ Version : "v0.0.1" ,
2170
+ Home : "https://docs.solo.io/skv2/latest" ,
2171
+ Sources : []string {
2172
+ "https://github.com/solo-io/skv2" ,
2173
+ },
2174
+ },
2175
+ },
2176
+
2177
+ ManifestRoot : "codegen/test/chart" ,
2178
+ }
2179
+
2180
+ err := cmd .Execute ()
2181
+ Expect (err ).NotTo (HaveOccurred ())
2182
+
2183
+ runAsUser := 202020
2184
+ runAsGroup := 999
2185
+ painterValues := map [string ]interface {}{
2186
+ "enabled" : true ,
2187
+ "runAsUser" : runAsUser ,
2188
+ "podSecurityContext" : map [string ]interface {}{
2189
+ "runAsUser" : runAsUser ,
2190
+ "fsGroup" : runAsGroup ,
2191
+ },
2192
+ }
2193
+
2194
+ helmValues := map [string ]interface {}{"painter" : painterValues }
2195
+
2196
+ renderedManifests := helmTemplate ("./codegen/test/chart" , helmValues )
2197
+
2198
+ var renderedDeployment * appsv1.Deployment
2199
+ decoder := kubeyaml .NewYAMLOrJSONDecoder (bytes .NewBuffer (renderedManifests ), 4096 )
2200
+ for {
2201
+ obj := & unstructured.Unstructured {}
2202
+ err := decoder .Decode (obj )
2203
+ if err != nil {
2204
+ break
2205
+ }
2206
+ if obj .GetName () != "painter" || obj .GetKind () != "Deployment" {
2207
+ continue
2208
+ }
2209
+
2210
+ bytes , err := obj .MarshalJSON ()
2211
+ Expect (err ).NotTo (HaveOccurred ())
2212
+ renderedDeployment = & appsv1.Deployment {}
2213
+ err = json .Unmarshal (bytes , renderedDeployment )
2214
+ Expect (err ).NotTo (HaveOccurred ())
2215
+ }
2216
+
2217
+ Expect (renderedDeployment ).NotTo (BeNil ())
2218
+ renderedRunAsUser := renderedDeployment .Spec .Template .Spec .Containers [0 ].SecurityContext .RunAsUser
2219
+ renderedPodSecurityContext := renderedDeployment .Spec .Template .Spec .SecurityContext
2220
+
2221
+ // When using the global floatingUserId, the container runAsUser and RunAsUser should not be set
2222
+ if floatingUserId {
2223
+ Expect (renderedRunAsUser ).To (BeNil ())
2224
+ Expect (renderedPodSecurityContext ).To (BeNil ())
2225
+ } else {
2226
+ Expect (* renderedRunAsUser ).To (Equal (int64 (runAsUser )))
2227
+ Expect (* renderedPodSecurityContext .RunAsUser ).To (Equal (int64 (runAsUser )))
2228
+ Expect (* renderedPodSecurityContext .FSGroup ).To (Equal (int64 (runAsGroup )))
2229
+ }
2230
+
2231
+ },
2232
+ Entry ("Global floatingUserId is true" , true ),
2233
+ Entry ("Global floatingUserId is false" , false ),
2234
+ )
2235
+
2137
2236
Describe ("rendering template env vars" , func () {
2138
2237
var tmpDir string
2139
2238
0 commit comments