Add CSIDriverSpec.SELinuxMount
The new field tells Kubernetes if the CSI driver supports mounting of volumes with -o context=XYZ or not.
This commit is contained in:
@@ -50,6 +50,9 @@ func (csiDriverStrategy) PrepareForCreate(ctx context.Context, obj runtime.Objec
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.CSIInlineVolume) {
|
||||
csiDriver.Spec.VolumeLifecycleModes = nil
|
||||
}
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.SELinuxMountReadWriteOncePod) {
|
||||
csiDriver.Spec.SELinuxMount = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (csiDriverStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
|
||||
@@ -87,6 +90,11 @@ func (csiDriverStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
func (csiDriverStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
|
||||
|
@@ -211,18 +211,36 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) {
|
||||
RequiresRepublish: &enabled,
|
||||
},
|
||||
}
|
||||
driverWithSELinuxMountEnabled := &storage.CSIDriver{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
SELinuxMount: &enabled,
|
||||
},
|
||||
}
|
||||
driverWithSELinuxMountDisabled := &storage.CSIDriver{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
SELinuxMount: &disabled,
|
||||
},
|
||||
}
|
||||
|
||||
resultPersistent := []storage.VolumeLifecycleMode{storage.VolumeLifecyclePersistent}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
old, update *storage.CSIDriver
|
||||
csiInlineVolumeEnabled bool
|
||||
wantCapacity *bool
|
||||
wantModes []storage.VolumeLifecycleMode
|
||||
wantTokenRequests []storage.TokenRequest
|
||||
wantRequiresRepublish *bool
|
||||
wantGeneration int64
|
||||
name string
|
||||
old, update *storage.CSIDriver
|
||||
csiInlineVolumeEnabled bool
|
||||
seLinuxMountReadWriteOncePodEnabled bool
|
||||
wantCapacity *bool
|
||||
wantModes []storage.VolumeLifecycleMode
|
||||
wantTokenRequests []storage.TokenRequest
|
||||
wantRequiresRepublish *bool
|
||||
wantGeneration int64
|
||||
wantSELinuxMount *bool
|
||||
}{
|
||||
{
|
||||
name: "capacity feature enabled, before: none, update: enabled",
|
||||
@@ -237,20 +255,20 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) {
|
||||
wantCapacity: &disabled,
|
||||
},
|
||||
{
|
||||
name: "inline feature enabled, before: none, update: persitent",
|
||||
name: "inline feature enabled, before: none, update: persistent",
|
||||
csiInlineVolumeEnabled: true,
|
||||
old: driverWithNothing,
|
||||
update: driverWithPersistent,
|
||||
wantModes: resultPersistent,
|
||||
},
|
||||
{
|
||||
name: "inline feature disabled, before: none, update: persitent",
|
||||
name: "inline feature disabled, before: none, update: persistent",
|
||||
old: driverWithNothing,
|
||||
update: driverWithPersistent,
|
||||
wantModes: nil,
|
||||
},
|
||||
{
|
||||
name: "inline feature disabled, before: ephemeral, update: persitent",
|
||||
name: "inline feature disabled, before: ephemeral, update: persistent",
|
||||
old: driverWithEphemeral,
|
||||
update: driverWithPersistent,
|
||||
wantModes: resultPersistent,
|
||||
@@ -263,11 +281,54 @@ func TestCSIDriverPrepareForUpdate(t *testing.T) {
|
||||
wantRequiresRepublish: &enabled,
|
||||
wantGeneration: 1,
|
||||
},
|
||||
{
|
||||
name: "SELinux mount support feature enabled, before: nil, update: on",
|
||||
seLinuxMountReadWriteOncePodEnabled: true,
|
||||
old: driverWithNothing,
|
||||
update: driverWithSELinuxMountEnabled,
|
||||
wantSELinuxMount: &enabled,
|
||||
},
|
||||
{
|
||||
name: "SELinux mount support feature enabled, before: off, update: on",
|
||||
seLinuxMountReadWriteOncePodEnabled: true,
|
||||
old: driverWithSELinuxMountDisabled,
|
||||
update: driverWithSELinuxMountEnabled,
|
||||
wantSELinuxMount: &enabled,
|
||||
},
|
||||
{
|
||||
name: "SELinux mount support feature enabled, before: on, update: off",
|
||||
seLinuxMountReadWriteOncePodEnabled: true,
|
||||
old: driverWithSELinuxMountEnabled,
|
||||
update: driverWithSELinuxMountDisabled,
|
||||
wantSELinuxMount: &disabled,
|
||||
},
|
||||
{
|
||||
name: "SELinux mount support feature disabled, before: nil, update: on",
|
||||
seLinuxMountReadWriteOncePodEnabled: false,
|
||||
old: driverWithNothing,
|
||||
update: driverWithSELinuxMountEnabled,
|
||||
wantSELinuxMount: nil,
|
||||
},
|
||||
{
|
||||
name: "SELinux mount support feature disabled, before: off, update: on",
|
||||
seLinuxMountReadWriteOncePodEnabled: false,
|
||||
old: driverWithSELinuxMountDisabled,
|
||||
update: driverWithSELinuxMountEnabled,
|
||||
wantSELinuxMount: &enabled,
|
||||
},
|
||||
{
|
||||
name: "SELinux mount support feature enabled, before: on, update: off",
|
||||
seLinuxMountReadWriteOncePodEnabled: false,
|
||||
old: driverWithSELinuxMountEnabled,
|
||||
update: driverWithSELinuxMountDisabled,
|
||||
wantSELinuxMount: &disabled,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIInlineVolume, test.csiInlineVolumeEnabled)()
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SELinuxMountReadWriteOncePod, test.seLinuxMountReadWriteOncePodEnabled)()
|
||||
|
||||
csiDriver := test.update.DeepCopy()
|
||||
Strategy.PrepareForUpdate(ctx, csiDriver, test.old)
|
||||
@@ -276,9 +337,9 @@ 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)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCSIDriverValidation(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user