@@ -685,18 +685,18 @@ func (c *ConfigMapUnpacker) ensureConfigmap(csRef *corev1.ObjectReference, name
685
685
return
686
686
}
687
687
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 ) {
689
689
fresh := c .job (cmRef , bundlePath , secrets , timeout )
690
690
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 })
692
692
if err != nil {
693
- return
693
+ return nil , err
694
694
}
695
695
696
696
// This is to ensure that we account for any existing unpack jobs that may be missing the label
697
697
jobWithoutLabel , err := c .jobLister .Jobs (fresh .GetNamespace ()).Get (cmRef .Name )
698
698
if err != nil && ! apierrors .IsNotFound (err ) {
699
- return
699
+ return nil , err
700
700
}
701
701
if jobWithoutLabel != nil {
702
702
_ , labelExists := jobWithoutLabel .Labels [BundleUnpackRefLabel ]
@@ -706,12 +706,11 @@ func (c *ConfigMapUnpacker) ensureJob(cmRef *corev1.ObjectReference, bundlePath
706
706
}
707
707
708
708
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 {})
711
710
}
712
711
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
715
714
716
715
// only check for retries if an unpackRetryInterval is specified
717
716
if unpackRetryInterval > 0 {
@@ -720,26 +719,23 @@ func (c *ConfigMapUnpacker) ensureJob(cmRef *corev1.ObjectReference, bundlePath
720
719
if cond , failed := getCondition (job , batchv1 .JobFailed ); failed {
721
720
if time .Now ().After (cond .LastTransitionTime .Time .Add (unpackRetryInterval )) {
722
721
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 {})
724
723
}
725
724
}
726
725
727
726
// cleanup old failed jobs, but don't clean up successful jobs to avoid repeat unpacking
728
727
for _ , j := range toDelete {
729
728
_ = c .client .BatchV1 ().Jobs (j .GetNamespace ()).Delete (context .TODO (), j .GetName (), metav1.DeleteOptions {})
730
729
}
731
- return
732
730
}
733
731
}
734
732
735
733
if equality .Semantic .DeepDerivative (fresh .GetOwnerReferences (), job .GetOwnerReferences ()) && equality .Semantic .DeepDerivative (fresh .Spec , job .Spec ) {
736
- return
734
+ return job , nil
737
735
}
738
736
739
737
// 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 {})
743
739
}
744
740
745
741
func (c * ConfigMapUnpacker ) ensureRole (cmRef * corev1.ObjectReference ) (role * rbacv1.Role , err error ) {
0 commit comments