@@ -243,7 +243,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_CreateCronJobs() {
243243 cj := & batchv1.CronJob {ObjectMeta : metav1.ObjectMeta {Name : CronJobName (s .auditConfig .Name , n .Name ), Namespace : s .auditConfig .Namespace }}
244244 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (cj ), cj ))
245245
246- cjExpected := CronJob (image , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
246+ cjExpected := CronJob (image , constants . BusyBoxImage , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
247247 // Make sure the env vars for both are sorted
248248 utils .SortEnvVars (cjExpected .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
249249 utils .SortEnvVars (cj .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
@@ -255,6 +255,40 @@ func (s *DeploymentHandlerSuite) TestReconcile_CreateCronJobs() {
255255 s .Error (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (gcCj ), gcCj ))
256256}
257257
258+ func (s * DeploymentHandlerSuite ) TestReconcile_CronJobUsesResolvedRenderImage () {
259+ s .seedNodes ()
260+ d := s .createDeploymentHandler ()
261+ d .MondooOperatorConfig = & v1alpha2.MondooOperatorConfig {Spec : v1alpha2.MondooOperatorConfigSpec {
262+ SkipContainerResolution : true ,
263+ }}
264+ d .ContainerImageResolver = & fakeMondoo.ContainerImageResolverMock {
265+ CnspecImageFunc : func (userImage , userTag , userDigest string , skipResolveImage bool ) (string , error ) {
266+ return "registry.example.com/cnspec:13-rootless" , nil
267+ },
268+ ContainerImageFunc : func (ctx context.Context , image string , skipResolveImage bool ) (string , error ) {
269+ s .Equal (constants .BusyBoxImage , image )
270+ s .True (skipResolveImage )
271+ return "registry.example.com/dockerhub/library/busybox:1.36" , nil
272+ },
273+ }
274+
275+ mondooAuditConfig := & s .auditConfig
276+ s .NoError (d .KubeClient .Create (s .ctx , mondooAuditConfig ))
277+
278+ result , err := d .Reconcile (s .ctx )
279+ s .NoError (err )
280+ s .True (result .IsZero ())
281+
282+ nodes := & corev1.NodeList {}
283+ s .NoError (d .KubeClient .List (s .ctx , nodes ))
284+ for _ , n := range nodes .Items {
285+ cj := & batchv1.CronJob {ObjectMeta : metav1.ObjectMeta {Name : CronJobName (s .auditConfig .Name , n .Name ), Namespace : s .auditConfig .Namespace }}
286+ s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (cj ), cj ))
287+ s .Len (cj .Spec .JobTemplate .Spec .Template .Spec .InitContainers , 1 )
288+ s .Equal ("registry.example.com/dockerhub/library/busybox:1.36" , cj .Spec .JobTemplate .Spec .Template .Spec .InitContainers [0 ].Image )
289+ }
290+ }
291+
258292func (s * DeploymentHandlerSuite ) TestReconcile_CreateCronJobs_CustomEnvVars () {
259293 s .seedNodes ()
260294 d := s .createDeploymentHandler ()
@@ -277,7 +311,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_CreateCronJobs_CustomEnvVars() {
277311 cj := & batchv1.CronJob {ObjectMeta : metav1.ObjectMeta {Name : CronJobName (s .auditConfig .Name , n .Name ), Namespace : s .auditConfig .Namespace }}
278312 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (cj ), cj ))
279313
280- cjExpected := CronJob (image , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
314+ cjExpected := CronJob (image , constants . BusyBoxImage , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
281315 // Make sure the env vars for both are sorted
282316 utils .SortEnvVars (cjExpected .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
283317 utils .SortEnvVars (cj .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
@@ -310,7 +344,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_CreateCronJobs_Switch() {
310344 cj := & batchv1.CronJob {ObjectMeta : metav1.ObjectMeta {Name : CronJobName (s .auditConfig .Name , n .Name ), Namespace : s .auditConfig .Namespace }}
311345 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (cj ), cj ))
312346
313- cjExpected := CronJob (image , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
347+ cjExpected := CronJob (image , constants . BusyBoxImage , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
314348 // Make sure the env vars for both are sorted
315349 utils .SortEnvVars (cjExpected .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
316350 utils .SortEnvVars (cj .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
@@ -350,7 +384,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_UpdateCronJobs() {
350384 s .NoError (err )
351385
352386 // Make sure a cron job exists for one of the nodes
353- cj := CronJob (image , nodes .Items [1 ], & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
387+ cj := CronJob (image , constants . BusyBoxImage , nodes .Items [1 ], & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
354388 cj .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Command = []string {"test-command" }
355389 s .NoError (d .KubeClient .Create (s .ctx , cj ))
356390
@@ -362,7 +396,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_UpdateCronJobs() {
362396 cj := & batchv1.CronJob {ObjectMeta : metav1.ObjectMeta {Name : CronJobName (s .auditConfig .Name , n .Name ), Namespace : s .auditConfig .Namespace }}
363397 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (cj ), cj ))
364398
365- cjExpected := CronJob (image , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
399+ cjExpected := CronJob (image , constants . BusyBoxImage , n , & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
366400 // Make sure the env vars for both are sorted
367401 utils .SortEnvVars (cjExpected .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
368402 utils .SortEnvVars (cj .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
@@ -408,7 +442,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_CleanCronJobsForDeletedNodes() {
408442 cj := & batchv1.CronJob {ObjectMeta : metav1.ObjectMeta {Name : CronJobName (s .auditConfig .Name , nodes .Items [0 ].Name ), Namespace : s .auditConfig .Namespace }}
409443 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (cj ), cj ))
410444
411- cjExpected := CronJob (image , nodes .Items [0 ], & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
445+ cjExpected := CronJob (image , constants . BusyBoxImage , nodes .Items [0 ], & s .auditConfig , false , v1alpha2.MondooOperatorConfig {})
412446 // Make sure the env vars for both are sorted
413447 utils .SortEnvVars (cjExpected .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
414448 utils .SortEnvVars (cj .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env )
@@ -436,7 +470,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_CreateDaemonSets() {
436470 ds := & appsv1.DaemonSet {ObjectMeta : metav1.ObjectMeta {Name : DaemonSetName (s .auditConfig .Name ), Namespace : s .auditConfig .Namespace }}
437471 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (ds ), ds ))
438472
439- dsExpected := DaemonSet (s .auditConfig , false , image , v1alpha2.MondooOperatorConfig {},
473+ dsExpected := DaemonSet (s .auditConfig , false , image , constants . BusyBoxImage , v1alpha2.MondooOperatorConfig {},
440474 []corev1.Toleration {{Key : "node-role.kubernetes.io/master" , Value : "true" , Effect : corev1 .TaintEffectNoExecute }})
441475 // Make sure the env vars for both are sorted
442476 utils .SortEnvVars (dsExpected .Spec .Template .Spec .Containers [0 ].Env )
@@ -469,7 +503,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_CreateDaemonSets_Switch() {
469503 ds := & appsv1.DaemonSet {ObjectMeta : metav1.ObjectMeta {Name : DaemonSetName (s .auditConfig .Name ), Namespace : s .auditConfig .Namespace }}
470504 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (ds ), ds ))
471505
472- dsExpected := DaemonSet (s .auditConfig , false , image , v1alpha2.MondooOperatorConfig {},
506+ dsExpected := DaemonSet (s .auditConfig , false , image , constants . BusyBoxImage , v1alpha2.MondooOperatorConfig {},
473507 []corev1.Toleration {{Key : "node-role.kubernetes.io/master" , Value : "true" , Effect : corev1 .TaintEffectNoExecute }})
474508 s .Equal (dsExpected .Spec , ds .Spec )
475509
@@ -507,7 +541,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_UpdateDaemonSets() {
507541 s .NoError (err )
508542
509543 // Make sure a daemonset exists
510- ds := DaemonSet (s .auditConfig , false , image , v1alpha2.MondooOperatorConfig {}, nil )
544+ ds := DaemonSet (s .auditConfig , false , image , constants . BusyBoxImage , v1alpha2.MondooOperatorConfig {}, nil )
511545 ds .Spec .Template .Spec .Containers [0 ].Command = []string {"test-command" }
512546 s .NoError (d .KubeClient .Create (s .ctx , ds ))
513547
@@ -518,7 +552,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_UpdateDaemonSets() {
518552 ds = & appsv1.DaemonSet {ObjectMeta : metav1.ObjectMeta {Name : DaemonSetName (s .auditConfig .Name ), Namespace : s .auditConfig .Namespace }}
519553 s .NoError (d .KubeClient .Get (s .ctx , client .ObjectKeyFromObject (ds ), ds ))
520554
521- depExpected := DaemonSet (s .auditConfig , false , image , v1alpha2.MondooOperatorConfig {},
555+ depExpected := DaemonSet (s .auditConfig , false , image , constants . BusyBoxImage , v1alpha2.MondooOperatorConfig {},
522556 []corev1.Toleration {{Key : "node-role.kubernetes.io/master" , Value : "true" , Effect : corev1 .TaintEffectNoExecute }})
523557 s .Equal (depExpected .Spec , ds .Spec )
524558}
0 commit comments