mirror of https://github.com/k3s-io/k3s
commit
cb89d8028a
|
@ -28,9 +28,6 @@ func DropDisabledFields(pvSpec *api.PersistentVolumeSpec, oldPVSpec *api.Persist
|
|||
if !utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && !volumeModeInUse(oldPVSpec) {
|
||||
pvSpec.VolumeMode = nil
|
||||
}
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PersistentLocalVolumes) && !persistentLocalVolumesInUse(oldPVSpec) {
|
||||
pvSpec.PersistentVolumeSource.Local = nil
|
||||
}
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.CSIPersistentVolume) {
|
||||
// if this is a new PV, or the old PV didn't already have the CSI field, clear it
|
||||
if oldPVSpec == nil || oldPVSpec.PersistentVolumeSource.CSI == nil {
|
||||
|
@ -48,13 +45,3 @@ func volumeModeInUse(oldPVSpec *api.PersistentVolumeSpec) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func persistentLocalVolumesInUse(oldPVSpec *api.PersistentVolumeSpec) bool {
|
||||
if oldPVSpec == nil {
|
||||
return false
|
||||
}
|
||||
if oldPVSpec.PersistentVolumeSource.Local != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package persistentvolume
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
@ -153,99 +152,3 @@ func TestDropDisabledFields(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDropDisabledFieldsPersistentLocalVolume(t *testing.T) {
|
||||
pvWithoutLocalVolume := func() *api.PersistentVolume {
|
||||
return &api.PersistentVolume{
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
Local: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
pvWithLocalVolume := func() *api.PersistentVolume {
|
||||
fsType := "ext4"
|
||||
return &api.PersistentVolume{
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
Local: &api.LocalVolumeSource{
|
||||
Path: "/a/b/c",
|
||||
FSType: &fsType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pvInfo := []struct {
|
||||
description string
|
||||
hasLocalVolume bool
|
||||
pv func() *api.PersistentVolume
|
||||
}{
|
||||
{
|
||||
description: "pv without LocalVolume",
|
||||
hasLocalVolume: false,
|
||||
pv: pvWithoutLocalVolume,
|
||||
},
|
||||
{
|
||||
description: "pv with LocalVolume",
|
||||
hasLocalVolume: true,
|
||||
pv: pvWithLocalVolume,
|
||||
},
|
||||
{
|
||||
description: "is nil",
|
||||
hasLocalVolume: false,
|
||||
pv: func() *api.PersistentVolume { return nil },
|
||||
},
|
||||
}
|
||||
|
||||
for _, enabled := range []bool{true, false} {
|
||||
for _, oldpvInfo := range pvInfo {
|
||||
for _, newpvInfo := range pvInfo {
|
||||
oldpvHasLocalVolume, oldpv := oldpvInfo.hasLocalVolume, oldpvInfo.pv()
|
||||
newpvHasLocalVolume, newpv := newpvInfo.hasLocalVolume, newpvInfo.pv()
|
||||
if newpv == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(fmt.Sprintf("feature enabled=%v, old pvc %v, new pvc %v", enabled, oldpvInfo.description, newpvInfo.description), func(t *testing.T) {
|
||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PersistentLocalVolumes, enabled)()
|
||||
|
||||
var oldpvSpec *api.PersistentVolumeSpec
|
||||
if oldpv != nil {
|
||||
oldpvSpec = &oldpv.Spec
|
||||
}
|
||||
DropDisabledFields(&newpv.Spec, oldpvSpec)
|
||||
|
||||
// old pv should never be changed
|
||||
if !reflect.DeepEqual(oldpv, oldpvInfo.pv()) {
|
||||
t.Errorf("old pv changed: %v", diff.ObjectReflectDiff(oldpv, oldpvInfo.pv()))
|
||||
}
|
||||
|
||||
switch {
|
||||
case enabled || oldpvHasLocalVolume:
|
||||
// new pv should not be changed if the feature is enabled, or if the old pv had LocalVolume source
|
||||
if !reflect.DeepEqual(newpv, newpvInfo.pv()) {
|
||||
t.Errorf("new pv changed: %v", diff.ObjectReflectDiff(newpv, newpvInfo.pv()))
|
||||
}
|
||||
case newpvHasLocalVolume:
|
||||
// new pv should be changed
|
||||
if reflect.DeepEqual(newpv, newpvInfo.pv()) {
|
||||
t.Errorf("new pv was not changed")
|
||||
}
|
||||
// new pv should not have LocalVolume
|
||||
if !reflect.DeepEqual(newpv, pvWithoutLocalVolume()) {
|
||||
t.Errorf("new pv had LocalVolume source: %v", diff.ObjectReflectDiff(newpv, pvWithoutLocalVolume()))
|
||||
}
|
||||
default:
|
||||
// new pv should not need to be changed
|
||||
if !reflect.DeepEqual(newpv, newpvInfo.pv()) {
|
||||
t.Errorf("new pv changed: %v", diff.ObjectReflectDiff(newpv, newpvInfo.pv()))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,8 @@ const (
|
|||
|
||||
// owner: @msau42
|
||||
// alpha: v1.7
|
||||
// beta: v1.10
|
||||
// ga: v1.14
|
||||
//
|
||||
// A new volume type that supports local disks on a node.
|
||||
PersistentLocalVolumes utilfeature.Feature = "PersistentLocalVolumes"
|
||||
|
@ -428,7 +430,7 @@ var defaultKubernetesFeatureGates = map[utilfeature.Feature]utilfeature.FeatureS
|
|||
TaintBasedEvictions: {Default: true, PreRelease: utilfeature.Beta},
|
||||
RotateKubeletServerCertificate: {Default: true, PreRelease: utilfeature.Beta},
|
||||
RotateKubeletClientCertificate: {Default: true, PreRelease: utilfeature.Beta},
|
||||
PersistentLocalVolumes: {Default: true, PreRelease: utilfeature.Beta},
|
||||
PersistentLocalVolumes: {Default: true, PreRelease: utilfeature.GA, LockToDefault: true}, // remove in 1.17
|
||||
LocalStorageCapacityIsolation: {Default: true, PreRelease: utilfeature.Beta},
|
||||
HugePages: {Default: true, PreRelease: utilfeature.GA, LockToDefault: true}, // remove in 1.16
|
||||
Sysctls: {Default: true, PreRelease: utilfeature.Beta},
|
||||
|
|
Loading…
Reference in New Issue