Skip to content

Commit

Permalink
Some minor fixes
Browse files Browse the repository at this point in the history
- Add comment to predicate function.
- chenge the order of an if case.
  • Loading branch information
Andreagit97 committed Jun 4, 2021
1 parent 38b5ba1 commit 1f2afd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -18,10 +18,11 @@ func addLiqoSchedulingLabel(ctx context.Context, c client.Client, namespaceName
return err
}

if namespace.Labels == nil {
namespace.Labels = map[string]string{}
}

if value, ok := namespace.Labels[liqoconst.SchedulingLiqoLabel]; !ok || value != liqoconst.SchedulingLiqoLabelValue {
if namespace.Labels == nil {
namespace.Labels = map[string]string{}
}
namespace.Labels[liqoconst.SchedulingLiqoLabel] = liqoconst.SchedulingLiqoLabelValue
if err := c.Update(ctx, namespace); err != nil {
klog.Errorf(" %s --> Unable to add liqo scheduling label to the namespace '%s'", err, namespace.GetName())
Expand Down
Expand Up @@ -108,11 +108,15 @@ func (r *NamespaceOffloadingReconciler) Reconcile(ctx context.Context, req ctrl.
}

// Todo: how to awake this controller for every NamespaceOffloading when a new NamespaceMap is created (or recreated).
// The name of all NamespaceOffloading resources must be always equal to "offloading", resources with a different
// name are not considered.
// At the moment the content of NamespaceOffloading.Spec is assumed to be immutable so we have to monitor only the deletion
// phase and not all updates.
func namespaceOffloadingPredicate() predicate.Predicate {
return predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
if !(e.ObjectNew.GetDeletionTimestamp().IsZero()) && ctrlutils.ContainsFinalizer(e.ObjectNew,
namespaceOffloadingControllerFinalizer) {
namespaceOffloadingControllerFinalizer) && e.ObjectNew.GetName() == liqoconst.DefaultNamespaceOffloadingName {
return true
}
return false
Expand Down

0 comments on commit 1f2afd9

Please sign in to comment.