@@ -685,18 +685,18 @@ func (c *ConfigMapUnpacker) ensureConfigmap(csRef *corev1.ObjectReference, name
685685 return
686686}
687687
688- func (c * ConfigMapUnpacker ) ensureJob (cmRef * corev1.ObjectReference , bundlePath string , secrets []corev1.LocalObjectReference , timeout time.Duration , unpackRetryInterval time.Duration ) (job * batchv1.Job , err error ) {
688+ func (c * ConfigMapUnpacker ) ensureJob (cmRef * corev1.ObjectReference , bundlePath string , secrets []corev1.LocalObjectReference , timeout time.Duration , unpackRetryInterval time.Duration ) (* batchv1.Job , error ) {
689689 fresh := c .job (cmRef , bundlePath , secrets , timeout )
690690 var jobs , toDelete []* batchv1.Job
691- jobs , err = c .jobLister .Jobs (fresh .GetNamespace ()).List (k8slabels.ValidatedSetSelector {BundleUnpackRefLabel : cmRef .Name })
691+ jobs , err : = c .jobLister .Jobs (fresh .GetNamespace ()).List (k8slabels.ValidatedSetSelector {BundleUnpackRefLabel : cmRef .Name })
692692 if err != nil {
693- return
693+ return nil , err
694694 }
695695
696696 // This is to ensure that we account for any existing unpack jobs that may be missing the label
697697 jobWithoutLabel , err := c .jobLister .Jobs (fresh .GetNamespace ()).Get (cmRef .Name )
698698 if err != nil && ! apierrors .IsNotFound (err ) {
699- return
699+ return nil , err
700700 }
701701 if jobWithoutLabel != nil {
702702 _ , labelExists := jobWithoutLabel .Labels [BundleUnpackRefLabel ]
@@ -706,12 +706,11 @@ func (c *ConfigMapUnpacker) ensureJob(cmRef *corev1.ObjectReference, bundlePath
706706 }
707707
708708 if len (jobs ) == 0 {
709- job , err = c .client .BatchV1 ().Jobs (fresh .GetNamespace ()).Create (context .TODO (), fresh , metav1.CreateOptions {})
710- return
709+ return c .client .BatchV1 ().Jobs (fresh .GetNamespace ()).Create (context .TODO (), fresh , metav1.CreateOptions {})
711710 }
712711
713- maxRetainedJobs := 5 // TODO: make this configurable
714- job , toDelete = sortUnpackJobs (jobs , maxRetainedJobs ) // choose latest or on-failed job attempt
712+ maxRetainedJobs := 5 // TODO: make this configurable
713+ job , toDelete : = sortUnpackJobs (jobs , maxRetainedJobs ) // choose latest or on-failed job attempt
715714
716715 // only check for retries if an unpackRetryInterval is specified
717716 if unpackRetryInterval > 0 {
@@ -720,26 +719,23 @@ func (c *ConfigMapUnpacker) ensureJob(cmRef *corev1.ObjectReference, bundlePath
720719 if cond , failed := getCondition (job , batchv1 .JobFailed ); failed {
721720 if time .Now ().After (cond .LastTransitionTime .Time .Add (unpackRetryInterval )) {
722721 fresh .SetName (names .SimpleNameGenerator .GenerateName (fresh .GetName ()))
723- job , err = c .client .BatchV1 ().Jobs (fresh .GetNamespace ()).Create (context .TODO (), fresh , metav1.CreateOptions {})
722+ return c .client .BatchV1 ().Jobs (fresh .GetNamespace ()).Create (context .TODO (), fresh , metav1.CreateOptions {})
724723 }
725724 }
726725
727726 // cleanup old failed jobs, but don't clean up successful jobs to avoid repeat unpacking
728727 for _ , j := range toDelete {
729728 _ = c .client .BatchV1 ().Jobs (j .GetNamespace ()).Delete (context .TODO (), j .GetName (), metav1.DeleteOptions {})
730729 }
731- return
732730 }
733731 }
734732
735733 if equality .Semantic .DeepDerivative (fresh .GetOwnerReferences (), job .GetOwnerReferences ()) && equality .Semantic .DeepDerivative (fresh .Spec , job .Spec ) {
736- return
734+ return job , nil
737735 }
738736
739737 // TODO: Decide when to fail-out instead of deleting the job
740- err = c .client .BatchV1 ().Jobs (job .GetNamespace ()).Delete (context .TODO (), job .GetName (), metav1.DeleteOptions {})
741- job = nil
742- return
738+ return nil , c .client .BatchV1 ().Jobs (job .GetNamespace ()).Delete (context .TODO (), job .GetName (), metav1.DeleteOptions {})
743739}
744740
745741func (c * ConfigMapUnpacker ) ensureRole (cmRef * corev1.ObjectReference ) (role * rbacv1.Role , err error ) {
0 commit comments