From 43e997cbcf3930e9470b8060d26a964e61371726 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Fri, 12 Jan 2024 14:15:51 +0800 Subject: [PATCH] fix(storage-network): annotated pod in creation loop longhorn-7640 Signed-off-by: Chin-Ya Huang --- controller/instance_manager_controller.go | 4 ++-- controller/setting_controller.go | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/controller/instance_manager_controller.go b/controller/instance_manager_controller.go index 356b3b93dd..dcebbae016 100644 --- a/controller/instance_manager_controller.go +++ b/controller/instance_manager_controller.go @@ -622,8 +622,8 @@ func (imc *InstanceManagerController) isSettingPriorityClassSynced(setting *long func (imc *InstanceManagerController) isSettingStorageNetworkSynced(setting *longhorn.Setting, pod *corev1.Pod) (bool, error) { nadAnnot := string(types.CNIAnnotationNetworks) - - return pod.Annotations[nadAnnot] == setting.Value, nil + nadAnnotValue := types.CreateCniAnnotationFromSetting(setting) + return pod.Annotations[nadAnnot] == nadAnnotValue, nil } func (imc *InstanceManagerController) isSettingDataEngineSynced(settingName types.SettingName, im *longhorn.InstanceManager) (bool, error) { diff --git a/controller/setting_controller.go b/controller/setting_controller.go index 0bb811db02..60a4470238 100644 --- a/controller/setting_controller.go +++ b/controller/setting_controller.go @@ -820,6 +820,8 @@ func (sc *SettingController) updateCNI() error { } nadAnnot := string(types.CNIAnnotationNetworks) + nadAnnotValue := types.CreateCniAnnotationFromSetting(storageNetwork) + imPodList, err := sc.ds.ListInstanceManagerPods() if err != nil { return errors.Wrapf(err, "failed to list instance manager Pods for %v setting update", types.SettingNameStorageNetwork) @@ -832,10 +834,16 @@ func (sc *SettingController) updateCNI() error { pods := append(imPodList, bimPodList...) for _, pod := range pods { - if pod.Annotations[nadAnnot] == storageNetwork.Value { + if pod.Annotations[nadAnnot] == nadAnnotValue { continue } + logrus.WithFields(logrus.Fields{ + "pod": pod.Name, + "oldValue": pod.Annotations[nadAnnot], + "newValue": nadAnnotValue, + }).Infof("Deleting pod to update the %v annotation", nadAnnot) + if err := sc.ds.DeletePod(pod.Name); err != nil { return err }