Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Romani <fromani@redhat.com>
  • Loading branch information
ffromani committed Oct 9, 2024
1 parent 4a50c3a commit 1f25477
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions controllers/numaresourcesoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ func (r *NUMAResourcesOperatorReconciler) Reconcile(ctx context.Context, req ctr
trees[idx].NodeGroup.Config = &conf
}

curStatus := instance.Status.DeepCopy()

result, condition, err := r.reconcileResource(ctx, instance, trees)

ok := updateStatusConditionsIfNeeded(instance, condition, reasonFromError(err), messageFromError(err))
if !ok { // no status update needed
_ = updateStatusConditionsIfNeeded(instance, condition, reasonFromError(err), messageFromError(err))

if !status.IsUpdatedNUMAResourcesOperator(curStatus, &instance.Status) {
return result, err
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
)

// TODO: are we duping these?
Expand All @@ -38,6 +40,15 @@ const (
ConditionTypeInternalError = "Internal Error"
)

func IsUpdatedNUMAResourcesOperator(oldStatus, newStatus *nropv1.NUMAResourcesOperatorStatus) bool {
options := []cmp.Option{
cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime"),
cmpopts.IgnoreFields(metav1.Condition{}, "ObservedGeneration"),
}

return !cmp.Equal(newStatus, oldStatus, options...)
}

// UpdateConditions compute new conditions based on arguments, and then compare with given current conditions.
// Returns the conditions to use, either current or newly computed, and a boolean flag which is `true` if conditions need
// update - so if they are updated since the current conditions.
Expand Down

0 comments on commit 1f25477

Please sign in to comment.