From cca3d557e6ff7f265eca8517d7c4fa719077c8d1 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Mon, 23 Jan 2023 14:35:38 +0100 Subject: [PATCH] Split volume reconstruction refactoring from SELinuxMountReadWriteOncePod Add a new feature gate NewVolumeManagerReconstruction and add the new volume reconstruction done in 1.26 under that feature gate. --- pkg/features/kube_features.go | 9 +++++++++ .../populator/desired_state_of_world_populator.go | 2 +- .../populator/desired_state_of_world_populator_test.go | 3 +-- .../volumemanager/reconciler/reconciler_common.go | 2 +- pkg/kubelet/volumemanager/reconciler/reconciler_new.go | 4 ++-- .../volumemanager/reconciler/reconstruct_new_test.go | 6 +++--- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index a10ff26f792..2ca8fc1e4be 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -562,6 +562,13 @@ const ( // Enables NetworkPolicy status subresource NetworkPolicyStatus featuregate.Feature = "NetworkPolicyStatus" + // owner: @jsafrane + // kep: https://kep.k8s.io/3756 + // alpha: v1.25 (as part of SELinuxMountReadWriteOncePod) + // beta: v1.27 + // Robust VolumeManager reconstruction after kubelet restart. + NewVolumeManagerReconstruction featuregate.Feature = "NewVolumeManagerReconstruction" + // owner: @xing-yang @sonasingh46 // kep: https://kep.k8s.io/2268 // alpha: v1.24 @@ -984,6 +991,8 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS NetworkPolicyStatus: {Default: false, PreRelease: featuregate.Alpha}, + NewVolumeManagerReconstruction: {Default: true, PreRelease: featuregate.Beta}, + NodeOutOfServiceVolumeDetach: {Default: true, PreRelease: featuregate.Beta}, NodeSwap: {Default: false, PreRelease: featuregate.Alpha}, diff --git a/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go b/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go index 52dc35dc9c8..cb820db0fb8 100644 --- a/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go +++ b/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go @@ -323,7 +323,7 @@ func (dswp *desiredStateOfWorldPopulator) processPodVolumes( } else { klog.V(4).InfoS("Added volume to desired state", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name()) } - if !utilfeature.DefaultFeatureGate.Enabled(features.SELinuxMountReadWriteOncePod) { + if !utilfeature.DefaultFeatureGate.Enabled(features.NewVolumeManagerReconstruction) { // sync reconstructed volume. This is necessary only when the old-style reconstruction is still used. // With reconstruct_new.go, AWS.MarkVolumeAsMounted will update the outer spec name of previously // uncertain volumes. diff --git a/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator_test.go b/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator_test.go index 65dcc9d30a2..81eacd1a7f1 100644 --- a/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator_test.go +++ b/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator_test.go @@ -89,8 +89,7 @@ func prepareDswpWithVolume(t *testing.T) (*desiredStateOfWorldPopulator, kubepod func TestFindAndAddNewPods_WithRescontructedVolume(t *testing.T) { // Outer volume spec replacement is needed only when the old volume reconstruction is used - // (i.e. with SELinuxMountReadWriteOncePod disabled) - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SELinuxMountReadWriteOncePod, false)() + defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NewVolumeManagerReconstruction, false)() // create dswp dswp, fakePodManager, _ := prepareDswpWithVolume(t) diff --git a/pkg/kubelet/volumemanager/reconciler/reconciler_common.go b/pkg/kubelet/volumemanager/reconciler/reconciler_common.go index e51ddd85e5f..13726c77202 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconciler_common.go +++ b/pkg/kubelet/volumemanager/reconciler/reconciler_common.go @@ -146,7 +146,7 @@ type reconciler struct { } func (rc *reconciler) Run(stopCh <-chan struct{}) { - if utilfeature.DefaultFeatureGate.Enabled(features.SELinuxMountReadWriteOncePod) { + if utilfeature.DefaultFeatureGate.Enabled(features.NewVolumeManagerReconstruction) { rc.runNew(stopCh) return } diff --git a/pkg/kubelet/volumemanager/reconciler/reconciler_new.go b/pkg/kubelet/volumemanager/reconciler/reconciler_new.go index 0b6603199ef..9e9e19e9cbf 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconciler_new.go +++ b/pkg/kubelet/volumemanager/reconciler/reconciler_new.go @@ -21,9 +21,9 @@ import ( "k8s.io/klog/v2" ) -// TODO: move to reconciler.go and remove old code there when SELinuxMountReadWriteOncePod is GA +// TODO: move to reconciler.go and remove old code there when NewVolumeManagerReconstruction is GA -// TODO: Replace Run() when SELinuxMountReadWriteOncePod is GA +// TODO: Replace Run() when NewVolumeManagerReconstruction is GA func (rc *reconciler) runNew(stopCh <-chan struct{}) { rc.reconstructVolumes() klog.InfoS("Reconciler: start to sync state") diff --git a/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go b/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go index 332c5476a04..7f5f57f8e45 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go +++ b/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go @@ -34,7 +34,7 @@ import ( ) func TestReconstructVolumes(t *testing.T) { - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SELinuxMountReadWriteOncePod, true)() + defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NewVolumeManagerReconstruction, true)() tests := []struct { name string @@ -146,7 +146,7 @@ func TestReconstructVolumes(t *testing.T) { } func TestCleanOrphanVolumes(t *testing.T) { - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SELinuxMountReadWriteOncePod, true)() + defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NewVolumeManagerReconstruction, true)() type podInfo struct { podName string @@ -261,7 +261,7 @@ func TestReconstructVolumesMount(t *testing.T) { // Since the volume is reconstructed, it must be marked as uncertain // even after a final SetUp error, see https://github.com/kubernetes/kubernetes/issues/96635 // and https://github.com/kubernetes/kubernetes/pull/110670. - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SELinuxMountReadWriteOncePod, true)() + defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NewVolumeManagerReconstruction, true)() tests := []struct { name string