@@ -509,13 +509,82 @@ var _ = Describe("Manager", Ordered, func() {
509509 }
510510 return names [0 ], true
511511 }
512+ // Get a list of Pod names spwned from a batch Job.
513+ listBatchJobPods := func (batchJobName string ) ([]string , error ) {
514+ output , err := utils .Run (
515+ utils .KubectlCmd (
516+ "-n" , namespace , "get" , "pod" ,
517+ "-o" , "jsonpath={.items[*].metadata.name}" ,
518+ "-l" , "job-name=" + batchJobName ,
519+ ),
520+ )
521+ if err != nil {
522+ return nil , err
523+ }
524+ return strings .Split (output , " " ), nil
525+ }
526+ // Verify that the batch Job created only one Pod.
527+ // If so, return the name the Pod.
528+ ensureOnlyOneBatchJobManagedPodCreated := func (batchJobName string ) (string , bool ) {
529+ By (fmt .Sprintf ("making ensure the batch Job %s created only one Pod" , batchJobName ))
530+ names , err := listBatchJobPods (batchJobName )
531+ if ! Expect (err ).To (Succeed ()) {
532+ return "" , false
533+ }
534+ if ! Expect (names ).Should (HaveLen (1 )) {
535+ return "" , false
536+ }
537+ return names [0 ], true
538+ }
512539
513540 It ("should reconcile resources successfully" , func () {
514541 type testCase struct {
515542 manifest string // directory in test/manifests/.
516543 additionalAssertion func (* testCase ) // additional assertion; does nothing if nil.
517544 }
518545 testCases := []testCase {
546+ {
547+ manifest : "pod-metadata" ,
548+ additionalAssertion : func (tc * testCase ) {
549+ name , ok := ensureOnlyOneBatchJobCreated ("job-" + tc .manifest )
550+ if ! ok {
551+ return
552+ }
553+ output , err := utils .Run (utils .KubectlCmd ("-n" , namespace ,
554+ "get" , "job" , name , "-o" , "jsonpath={.spec.template.spec.containers[0].command}" ,
555+ ))
556+ if ! Expect (err ).To (Succeed ()) {
557+ return
558+ }
559+ Expect (output ).To (Equal (`["perl","-Mbignum=bpi","-wle","print bpi(100)"]` ))
560+
561+ pod , ok := ensureOnlyOneBatchJobManagedPodCreated (name )
562+ if ! ok {
563+ return
564+ }
565+ for _ , check := range []struct {
566+ path string
567+ want string
568+ }{
569+ {
570+ path : `{.metadata.labels.app}` ,
571+ want : "pod-metadata" ,
572+ },
573+ {
574+ path : `{.metadata.annotations.desc}` ,
575+ want : "add pod-metadata" ,
576+ },
577+ } {
578+ output , err := utils .Run (utils .KubectlCmd ("-n" , namespace ,
579+ "get" , "pod" , pod , "-o" , "jsonpath=" + check .path ,
580+ ))
581+ if ! Expect (err ).To (Succeed ()) {
582+ return
583+ }
584+ Expect (output ).To (Equal (check .want ))
585+ }
586+ },
587+ },
519588 {
520589 manifest : "sample" ,
521590 additionalAssertion : func (tc * testCase ) {
0 commit comments