From 189f19a6985c577cff3abbae75a94687deb9d4e0 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Mon, 6 Jun 2022 17:29:45 +0200 Subject: [PATCH] Update generation when SELinuxMount is changed --- pkg/registry/storage/csidriver/strategy.go | 12 +++++++----- pkg/registry/storage/csidriver/strategy_test.go | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/registry/storage/csidriver/strategy.go b/pkg/registry/storage/csidriver/strategy.go index d266dfa0431..2eb87e568a3 100644 --- a/pkg/registry/storage/csidriver/strategy.go +++ b/pkg/registry/storage/csidriver/strategy.go @@ -86,15 +86,17 @@ func (csiDriverStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime. newCSIDriver.Spec.VolumeLifecycleModes = nil } - // Any changes to the mutable fields increment the generation number. - if !apiequality.Semantic.DeepEqual(oldCSIDriver.Spec.TokenRequests, newCSIDriver.Spec.TokenRequests) || !apiequality.Semantic.DeepEqual(oldCSIDriver.Spec.RequiresRepublish, newCSIDriver.Spec.RequiresRepublish) { - newCSIDriver.Generation = oldCSIDriver.Generation + 1 - } - if oldCSIDriver.Spec.SELinuxMount == nil && !utilfeature.DefaultFeatureGate.Enabled(features.SELinuxMountReadWriteOncePod) { newCSIDriver.Spec.SELinuxMount = nil } + + // Any changes to the mutable fields increment the generation number. + if !apiequality.Semantic.DeepEqual(oldCSIDriver.Spec.TokenRequests, newCSIDriver.Spec.TokenRequests) || + !apiequality.Semantic.DeepEqual(oldCSIDriver.Spec.RequiresRepublish, newCSIDriver.Spec.RequiresRepublish) || + !apiequality.Semantic.DeepEqual(oldCSIDriver.Spec.SELinuxMount, newCSIDriver.Spec.SELinuxMount) { + newCSIDriver.Generation = oldCSIDriver.Generation + 1 + } } func (csiDriverStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { diff --git a/pkg/registry/storage/csidriver/strategy_test.go b/pkg/registry/storage/csidriver/strategy_test.go index e0172823188..7f7829d4ce6 100644 --- a/pkg/registry/storage/csidriver/strategy_test.go +++ b/pkg/registry/storage/csidriver/strategy_test.go @@ -287,6 +287,7 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) { old: driverWithNothing, update: driverWithSELinuxMountEnabled, wantSELinuxMount: &enabled, + wantGeneration: 1, }, { name: "SELinux mount support feature enabled, before: off, update: on", @@ -294,6 +295,7 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) { old: driverWithSELinuxMountDisabled, update: driverWithSELinuxMountEnabled, wantSELinuxMount: &enabled, + wantGeneration: 1, }, { name: "SELinux mount support feature enabled, before: on, update: off", @@ -301,6 +303,7 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) { old: driverWithSELinuxMountEnabled, update: driverWithSELinuxMountDisabled, wantSELinuxMount: &disabled, + wantGeneration: 1, }, { name: "SELinux mount support feature disabled, before: nil, update: on", @@ -308,6 +311,7 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) { old: driverWithNothing, update: driverWithSELinuxMountEnabled, wantSELinuxMount: nil, + wantGeneration: 0, }, { name: "SELinux mount support feature disabled, before: off, update: on", @@ -315,6 +319,7 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) { old: driverWithSELinuxMountDisabled, update: driverWithSELinuxMountEnabled, wantSELinuxMount: &enabled, + wantGeneration: 1, }, { name: "SELinux mount support feature enabled, before: on, update: off", @@ -322,6 +327,7 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) { old: driverWithSELinuxMountEnabled, update: driverWithSELinuxMountDisabled, wantSELinuxMount: &disabled, + wantGeneration: 1, }, } @@ -337,7 +343,7 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) { require.Equal(t, test.wantModes, csiDriver.Spec.VolumeLifecycleModes) require.Equal(t, test.wantTokenRequests, csiDriver.Spec.TokenRequests) require.Equal(t, test.wantRequiresRepublish, csiDriver.Spec.RequiresRepublish) - require.Equal(t, test.wantSELinuxMount, csiDriver.Spec.SELinuxMounted) + require.Equal(t, test.wantSELinuxMount, csiDriver.Spec.SELinuxMount) }) } }