Skip to content

Commit b1b7b22

Browse files
committed
Fix an issue in the ComplianceScan controller
We were doing two updates without re‐fetching. This fixs it.
1 parent 3065c09 commit b1b7b22

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pkg/controller/compliancescan/compliancescan_controller.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func (r *ReconcileComplianceScan) phaseAggregatingHandler(h scanTypeHandler, log
606606
logger.Info("Creating an aggregator pod for scan")
607607
aggregator := r.newAggregatorPod(instance, logger)
608608
if priorityClassExist, why := utils.ValidatePriorityClassExist(aggregator.Spec.PriorityClassName, r.Client); !priorityClassExist {
609-
log.Info(why, "aggregator", aggregator.Name)
609+
logger.Info(why, "aggregator", aggregator.Name)
610610
r.Recorder.Eventf(aggregator, corev1.EventTypeWarning, "PriorityClass", why+" aggregator:"+aggregator.Name)
611611
aggregator.Spec.PriorityClassName = ""
612612
}
@@ -658,19 +658,21 @@ func (r *ReconcileComplianceScan) phaseAggregatingHandler(h scanTypeHandler, log
658658
return reconcile.Result{}, err
659659
}
660660

661-
instanceCopy := instance.DeepCopy()
662-
663-
if instanceCopy.Annotations == nil {
664-
instanceCopy.Annotations = make(map[string]string)
661+
// check if instance has any annotation before checking for check count
662+
// to avoid nil pointer exception in case of missing annotation
663+
if instance.Annotations == nil {
664+
instance.Annotations = make(map[string]string)
665665
}
666-
667-
// adding check count annotation
668-
instanceCopy.Annotations[compv1alpha1.ComplianceCheckCountAnnotation] = strconv.Itoa(checkCount)
669-
670-
if err := r.Client.Update(context.TODO(), instanceCopy); err != nil {
671-
logger.Error(err, "Cannot update the scan with the check count")
672-
return reconcile.Result{}, err
666+
if _, ok := instance.Annotations[compv1alpha1.ComplianceCheckCountAnnotation]; !ok {
667+
instanceCopy := instance.DeepCopy()
668+
instanceCopy.Annotations[compv1alpha1.ComplianceCheckCountAnnotation] = strconv.Itoa(checkCount)
669+
if err := r.Client.Update(context.TODO(), instanceCopy); err != nil {
670+
logger.Error(err, "Cannot update the scan with the check count")
671+
return reconcile.Result{}, err
672+
}
673+
return reconcile.Result{Requeue: true}, nil
673674
}
675+
674676
instance.Status.Phase = compv1alpha1.PhaseDone
675677
instance.Status.EndTimestamp = &metav1.Time{Time: time.Now()}
676678
instance.Status.SetConditionReady()

0 commit comments

Comments
 (0)