@@ -2341,6 +2341,105 @@ roleRef:
2341
2341
}),
2342
2342
)
2343
2343
2344
+ DescribeTable ("rendering with GlobalFloatingUserId" ,
2345
+ func (floatingUserId bool ) {
2346
+ cmd := & Command {
2347
+ Chart : & Chart {
2348
+ Operators : []Operator {
2349
+ {
2350
+ Name : "painter" ,
2351
+ Deployment : Deployment {
2352
+ Container : Container {
2353
+ Image : Image {
2354
+ Tag : "v0.0.0" ,
2355
+ Repository : "painter" ,
2356
+ Registry : "quay.io/solo-io" ,
2357
+ PullPolicy : "IfNotPresent" ,
2358
+ },
2359
+ },
2360
+ },
2361
+ GlobalFloatingUserIdPath : ".Values.global.securitySettings.floatingUserId" ,
2362
+ },
2363
+ },
2364
+ // Because the global override comes from .Values it has to be set here, not on the painter
2365
+ Values : map [string ]interface {}{
2366
+ "global" : map [string ]interface {}{
2367
+ "securitySettings" : map [string ]interface {}{
2368
+ "floatingUserId" : floatingUserId ,
2369
+ },
2370
+ },
2371
+ },
2372
+ Data : Data {
2373
+ ApiVersion : "v1" ,
2374
+ Description : "" ,
2375
+ Name : "Painting Operator" ,
2376
+ Version : "v0.0.1" ,
2377
+ Home : "https://docs.solo.io/skv2/latest" ,
2378
+ Sources : []string {
2379
+ "https://github.com/solo-io/skv2" ,
2380
+ },
2381
+ },
2382
+ },
2383
+
2384
+ ManifestRoot : "codegen/test/chart" ,
2385
+ }
2386
+
2387
+ err := cmd .Execute ()
2388
+ Expect (err ).NotTo (HaveOccurred ())
2389
+
2390
+ runAsUser := 202020
2391
+ runAsGroup := 999
2392
+ painterValues := map [string ]interface {}{
2393
+ "enabled" : true ,
2394
+ "runAsUser" : runAsUser ,
2395
+ "podSecurityContext" : map [string ]interface {}{
2396
+ "runAsUser" : runAsUser ,
2397
+ "fsGroup" : runAsGroup ,
2398
+ },
2399
+ }
2400
+
2401
+ helmValues := map [string ]interface {}{"painter" : painterValues }
2402
+
2403
+ renderedManifests := helmTemplate ("./codegen/test/chart" , helmValues )
2404
+
2405
+ var renderedDeployment * appsv1.Deployment
2406
+ decoder := kubeyaml .NewYAMLOrJSONDecoder (bytes .NewBuffer (renderedManifests ), 4096 )
2407
+ for {
2408
+ obj := & unstructured.Unstructured {}
2409
+ err := decoder .Decode (obj )
2410
+ if err != nil {
2411
+ break
2412
+ }
2413
+ if obj .GetName () != "painter" || obj .GetKind () != "Deployment" {
2414
+ continue
2415
+ }
2416
+
2417
+ bytes , err := obj .MarshalJSON ()
2418
+ Expect (err ).NotTo (HaveOccurred ())
2419
+ renderedDeployment = & appsv1.Deployment {}
2420
+ err = json .Unmarshal (bytes , renderedDeployment )
2421
+ Expect (err ).NotTo (HaveOccurred ())
2422
+ }
2423
+
2424
+ Expect (renderedDeployment ).NotTo (BeNil ())
2425
+ renderedRunAsUser := renderedDeployment .Spec .Template .Spec .Containers [0 ].SecurityContext .RunAsUser
2426
+ renderedPodSecurityContext := renderedDeployment .Spec .Template .Spec .SecurityContext
2427
+
2428
+ // When using the global floatingUserId, the container runAsUser and RunAsUser should not be set
2429
+ if floatingUserId {
2430
+ Expect (renderedRunAsUser ).To (BeNil ())
2431
+ Expect (renderedPodSecurityContext ).To (BeNil ())
2432
+ } else {
2433
+ Expect (* renderedRunAsUser ).To (Equal (int64 (runAsUser )))
2434
+ Expect (* renderedPodSecurityContext .RunAsUser ).To (Equal (int64 (runAsUser )))
2435
+ Expect (* renderedPodSecurityContext .FSGroup ).To (Equal (int64 (runAsGroup )))
2436
+ }
2437
+
2438
+ },
2439
+ Entry ("Global floatingUserId is true" , true ),
2440
+ Entry ("Global floatingUserId is false" , false ),
2441
+ )
2442
+
2344
2443
Describe ("rendering template env vars" , func () {
2345
2444
var tmpDir string
2346
2445
0 commit comments