Skip to content

Commit

Permalink
Fix an issue in the ComplianceScan controller
Browse files Browse the repository at this point in the history
We were doing two updates without re‐fetching. This fixs it.
  • Loading branch information
Vincent056 committed Feb 19, 2025
1 parent 3065c09 commit b1b7b22
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/controller/compliancescan/compliancescan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func (r *ReconcileComplianceScan) phaseAggregatingHandler(h scanTypeHandler, log
logger.Info("Creating an aggregator pod for scan")
aggregator := r.newAggregatorPod(instance, logger)
if priorityClassExist, why := utils.ValidatePriorityClassExist(aggregator.Spec.PriorityClassName, r.Client); !priorityClassExist {
log.Info(why, "aggregator", aggregator.Name)
logger.Info(why, "aggregator", aggregator.Name)
r.Recorder.Eventf(aggregator, corev1.EventTypeWarning, "PriorityClass", why+" aggregator:"+aggregator.Name)
aggregator.Spec.PriorityClassName = ""
}
Expand Down Expand Up @@ -658,19 +658,21 @@ func (r *ReconcileComplianceScan) phaseAggregatingHandler(h scanTypeHandler, log
return reconcile.Result{}, err
}

instanceCopy := instance.DeepCopy()

if instanceCopy.Annotations == nil {
instanceCopy.Annotations = make(map[string]string)
// check if instance has any annotation before checking for check count
// to avoid nil pointer exception in case of missing annotation
if instance.Annotations == nil {
instance.Annotations = make(map[string]string)
}

// adding check count annotation
instanceCopy.Annotations[compv1alpha1.ComplianceCheckCountAnnotation] = strconv.Itoa(checkCount)

if err := r.Client.Update(context.TODO(), instanceCopy); err != nil {
logger.Error(err, "Cannot update the scan with the check count")
return reconcile.Result{}, err
if _, ok := instance.Annotations[compv1alpha1.ComplianceCheckCountAnnotation]; !ok {
instanceCopy := instance.DeepCopy()
instanceCopy.Annotations[compv1alpha1.ComplianceCheckCountAnnotation] = strconv.Itoa(checkCount)
if err := r.Client.Update(context.TODO(), instanceCopy); err != nil {
logger.Error(err, "Cannot update the scan with the check count")
return reconcile.Result{}, err
}
return reconcile.Result{Requeue: true}, nil
}

instance.Status.Phase = compv1alpha1.PhaseDone
instance.Status.EndTimestamp = &metav1.Time{Time: time.Now()}
instance.Status.SetConditionReady()
Expand Down

0 comments on commit b1b7b22

Please sign in to comment.