Skip to content

Commit bf5a14d

Browse files
committed
crc & kcc: Before deleting a degraded MC, ensure that the annotations
have not been updated since the last check
1 parent 67d8fd6 commit bf5a14d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pkg/controller/container-runtime-config/container_runtime_config_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,13 @@ func (ctrl *Controller) cleanUpDuplicatedMC() error {
779779
if !strings.Contains(mc.Name, generatedCtrCfg) {
780780
continue
781781
}
782+
// Recheck to ensure nothing changed in between
783+
mcToBeDeleted, err := ctrl.client.MachineconfigurationV1().MachineConfigs().Get(context.TODO(), mc.Name, metav1.GetOptions{})
784+
if err != nil {
785+
return err
786+
}
782787
// delete the containerruntime mc if its degraded
783-
if mc.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] != version.Hash {
788+
if mcToBeDeleted.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] != version.Hash {
784789
if err := ctrl.client.MachineconfigurationV1().MachineConfigs().Delete(context.TODO(), mc.Name, metav1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) {
785790
return fmt.Errorf("error deleting degraded containerruntime machine config %s: %w", mc.Name, err)
786791
}

pkg/controller/kubelet-config/kubelet_config_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,13 @@ func (ctrl *Controller) cleanUpDuplicatedMC(prefix string) error {
751751
if !strings.HasPrefix(mc.Name, prefix) {
752752
continue
753753
}
754+
// Recheck to ensure nothing changed in between
755+
mcToBeDeleted, err := ctrl.client.MachineconfigurationV1().MachineConfigs().Get(context.TODO(), mc.Name, metav1.GetOptions{})
756+
if err != nil {
757+
return err
758+
}
754759
// delete the mc if its degraded
755-
if mc.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] != version.Hash {
760+
if mcToBeDeleted.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] != version.Hash {
756761
if err := ctrl.client.MachineconfigurationV1().MachineConfigs().Delete(context.TODO(), mc.Name, metav1.DeleteOptions{}); err != nil && !macherrors.IsNotFound(err) {
757762
return fmt.Errorf("error deleting degraded kubelet machine config %s: %w", mc.Name, err)
758763
}

0 commit comments

Comments
 (0)