From de0a86e460af2846c21605e839e013b62201c99f Mon Sep 17 00:00:00 2001 From: Sebastian Sch Date: Sun, 23 Jun 2024 14:59:04 +0300 Subject: [PATCH] add sort for the policy on the sriovOperatorConfig controller we need to be consistent with the policy order Signed-off-by: Sebastian Sch --- controllers/sriovnetworknodepolicy_controller.go | 3 +++ controllers/sriovoperatorconfig_controller.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/controllers/sriovnetworknodepolicy_controller.go b/controllers/sriovnetworknodepolicy_controller.go index a275beb5d..e5abc5f08 100644 --- a/controllers/sriovnetworknodepolicy_controller.go +++ b/controllers/sriovnetworknodepolicy_controller.go @@ -121,6 +121,9 @@ func (r *SriovNetworkNodePolicyReconciler) Reconcile(ctx context.Context, req ct } // Sort the policies with priority, higher priority ones is applied later + // We need to use the sort so we always get the policies in the same order + // That is needed so when we create the node Affinity for the sriov-device plugin + // it will remain in the same order and not trigger a pod recreation sort.Sort(sriovnetworkv1.ByPriority(policyList.Items)) // Sync SriovNetworkNodeState objects if err = r.syncAllSriovNetworkNodeStates(ctx, defaultOpConf, policyList, nodeList); err != nil { diff --git a/controllers/sriovoperatorconfig_controller.go b/controllers/sriovoperatorconfig_controller.go index 9e90a5688..5148eed6a 100644 --- a/controllers/sriovoperatorconfig_controller.go +++ b/controllers/sriovoperatorconfig_controller.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "os" + "sort" "strings" appsv1 "k8s.io/api/apps/v1" @@ -107,6 +108,11 @@ func (r *SriovOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl. // Error reading the object - requeue the request. return reconcile.Result{}, err } + // Sort the policies with priority, higher priority ones is applied later + // We need to use the sort so we always get the policies in the same order + // That is needed so when we create the node Affinity for the sriov-device plugin + // it will remain in the same order and not trigger a pod recreation + sort.Sort(sriovnetworkv1.ByPriority(policyList.Items)) // Render and sync webhook objects if err = r.syncWebhookObjs(ctx, defaultConfig); err != nil {