mirror of https://github.com/k3s-io/k3s
Merge pull request #73818 from gnufied/add-e2e-for-no-expand
add e2e test when expansion is disabledpull/564/head
commit
812016fa23
|
@ -368,7 +368,7 @@ if [[ -n "${GCE_GLBC_IMAGE:-}" ]]; then
|
|||
fi
|
||||
|
||||
if [[ -z "${KUBE_ADMISSION_CONTROL:-}" ]]; then
|
||||
ADMISSION_CONTROL="NamespaceLifecycle,LimitRanger,ServiceAccount,PersistentVolumeLabel,PodPreset,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,Priority,StorageObjectInUseProtection"
|
||||
ADMISSION_CONTROL="NamespaceLifecycle,LimitRanger,ServiceAccount,PersistentVolumeLabel,PodPreset,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,Priority,StorageObjectInUseProtection,PersistentVolumeClaimResize"
|
||||
if [[ "${ENABLE_POD_SECURITY_POLICY:-}" == "true" ]]; then
|
||||
ADMISSION_CONTROL="${ADMISSION_CONTROL},PodSecurityPolicy"
|
||||
fi
|
||||
|
|
|
@ -18,6 +18,8 @@ package storage
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"k8s.io/api/core/v1"
|
||||
|
@ -27,8 +29,8 @@ import (
|
|||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
"k8s.io/kubernetes/test/e2e/storage/testsuites"
|
||||
"k8s.io/kubernetes/test/e2e/storage/utils"
|
||||
"path"
|
||||
)
|
||||
|
||||
var _ = utils.SIGDescribe("Mounted flexvolume expand[Slow]", func() {
|
||||
|
@ -72,7 +74,14 @@ var _ = utils.SIGDescribe("Mounted flexvolume expand[Slow]", func() {
|
|||
isNodeLabeled = true
|
||||
}
|
||||
|
||||
resizableSc, err = createStorageClass(ns, c)
|
||||
test := testsuites.StorageClassTest{
|
||||
Name: "flexvolume-resize",
|
||||
ClaimSize: "2Gi",
|
||||
AllowVolumeExpansion: true,
|
||||
Provisioner: "flex-expand",
|
||||
}
|
||||
|
||||
resizableSc, err = createStorageClass(test, ns, "resizing", c)
|
||||
if err != nil {
|
||||
fmt.Printf("storage class creation error: %v\n", err)
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package storage
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"k8s.io/api/core/v1"
|
||||
|
@ -26,21 +28,10 @@ import (
|
|||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
"k8s.io/kubernetes/test/e2e/storage/testsuites"
|
||||
"k8s.io/kubernetes/test/e2e/storage/utils"
|
||||
"path"
|
||||
)
|
||||
|
||||
func createStorageClass(ns string, c clientset.Interface) (*storage.StorageClass, error) {
|
||||
bindingMode := storage.VolumeBindingImmediate
|
||||
stKlass := getStorageClass("flex-expand", map[string]string{}, &bindingMode, ns, "resizing")
|
||||
allowExpansion := true
|
||||
stKlass.AllowVolumeExpansion = &allowExpansion
|
||||
|
||||
var err error
|
||||
stKlass, err = c.StorageV1().StorageClasses().Create(stKlass)
|
||||
return stKlass, err
|
||||
}
|
||||
|
||||
var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:ExpandInUsePersistentVolumes]", func() {
|
||||
var (
|
||||
c clientset.Interface
|
||||
|
@ -82,7 +73,14 @@ var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:Expa
|
|||
isNodeLabeled = true
|
||||
}
|
||||
|
||||
resizableSc, err = createStorageClass(ns, c)
|
||||
test := testsuites.StorageClassTest{
|
||||
Name: "flexvolume-resize",
|
||||
ClaimSize: "2Gi",
|
||||
AllowVolumeExpansion: true,
|
||||
Provisioner: "flex-expand",
|
||||
}
|
||||
|
||||
resizableSc, err = createStorageClass(test, ns, "resizing", c)
|
||||
if err != nil {
|
||||
fmt.Printf("storage class creation error: %v\n", err)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import (
|
|||
"k8s.io/kubernetes/test/e2e/storage/utils"
|
||||
)
|
||||
|
||||
var _ = utils.SIGDescribe("Mounted volume expand[Slow]", func() {
|
||||
var _ = utils.SIGDescribe("Mounted volume expand", func() {
|
||||
var (
|
||||
c clientset.Interface
|
||||
ns string
|
||||
|
@ -76,8 +76,9 @@ var _ = utils.SIGDescribe("Mounted volume expand[Slow]", func() {
|
|||
test := testsuites.StorageClassTest{
|
||||
Name: "default",
|
||||
ClaimSize: "2Gi",
|
||||
AllowVolumeExpansion: true,
|
||||
}
|
||||
resizableSc, err = createResizableStorageClass(test, ns, "resizing", c)
|
||||
resizableSc, err = createStorageClass(test, ns, "resizing", c)
|
||||
Expect(err).NotTo(HaveOccurred(), "Error creating resizable storage class")
|
||||
Expect(*resizableSc.AllowVolumeExpansion).To(BeTrue())
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ type StorageClassTest struct {
|
|||
ExpectedSize string
|
||||
PvCheck func(claim *v1.PersistentVolumeClaim, volume *v1.PersistentVolume)
|
||||
VolumeMode *v1.PersistentVolumeMode
|
||||
AllowVolumeExpansion bool
|
||||
}
|
||||
|
||||
type provisioningTestSuite struct {
|
||||
|
|
|
@ -40,7 +40,7 @@ const (
|
|||
totalResizeWaitPeriod = 20 * time.Minute
|
||||
)
|
||||
|
||||
var _ = utils.SIGDescribe("Volume expand [Slow]", func() {
|
||||
var _ = utils.SIGDescribe("Volume expand", func() {
|
||||
var (
|
||||
c clientset.Interface
|
||||
ns string
|
||||
|
@ -58,8 +58,9 @@ var _ = utils.SIGDescribe("Volume expand [Slow]", func() {
|
|||
test := testsuites.StorageClassTest{
|
||||
Name: "default",
|
||||
ClaimSize: "2Gi",
|
||||
AllowVolumeExpansion: true,
|
||||
}
|
||||
resizableSc, err = createResizableStorageClass(test, ns, "resizing", c)
|
||||
resizableSc, err = createStorageClass(test, ns, "resizing", c)
|
||||
Expect(err).NotTo(HaveOccurred(), "Error creating resizable storage class")
|
||||
Expect(resizableSc.AllowVolumeExpansion).NotTo(BeNil())
|
||||
Expect(*resizableSc.AllowVolumeExpansion).To(BeTrue())
|
||||
|
@ -75,6 +76,39 @@ var _ = utils.SIGDescribe("Volume expand [Slow]", func() {
|
|||
framework.ExpectNoError(c.StorageV1().StorageClasses().Delete(resizableSc.Name, nil))
|
||||
})
|
||||
|
||||
It("should not allow expansion of pvcs without AllowVolumeExpansion property", func() {
|
||||
test := testsuites.StorageClassTest{
|
||||
Name: "no-expansion",
|
||||
ClaimSize: "2Gi",
|
||||
}
|
||||
regularSC, err := createStorageClass(test, ns, "noexpand", c)
|
||||
Expect(err).NotTo(HaveOccurred(), "Error creating non-expandable storage class")
|
||||
|
||||
defer func() {
|
||||
framework.ExpectNoError(c.StorageV1().StorageClasses().Delete(regularSC.Name, nil))
|
||||
}()
|
||||
Expect(regularSC.AllowVolumeExpansion).To(BeNil())
|
||||
|
||||
noExpandPVC := newClaim(test, ns, "noexpand")
|
||||
noExpandPVC.Spec.StorageClassName = ®ularSC.Name
|
||||
noExpandPVC, err = c.CoreV1().PersistentVolumeClaims(noExpandPVC.Namespace).Create(noExpandPVC)
|
||||
Expect(err).NotTo(HaveOccurred(), "Error creating pvc")
|
||||
|
||||
defer func() {
|
||||
framework.ExpectNoError(framework.DeletePersistentVolumeClaim(c, noExpandPVC.Name, noExpandPVC.Namespace))
|
||||
}()
|
||||
|
||||
pvcClaims := []*v1.PersistentVolumeClaim{noExpandPVC}
|
||||
pvs, err := framework.WaitForPVClaimBoundPhase(c, pvcClaims, framework.ClaimProvisionTimeout)
|
||||
Expect(err).NotTo(HaveOccurred(), "Failed waiting for PVC to be bound %v", err)
|
||||
Expect(len(pvs)).To(Equal(1))
|
||||
|
||||
By("Expanding non-expandable pvc")
|
||||
newSize := resource.MustParse("6Gi")
|
||||
noExpandPVC, err = expandPVCSize(noExpandPVC, newSize, c)
|
||||
Expect(err).To(HaveOccurred(), "While updating non-expandable PVC")
|
||||
})
|
||||
|
||||
It("Verify if editing PVC allows resize", func() {
|
||||
By("Waiting for pvc to be in bound phase")
|
||||
pvcClaims := []*v1.PersistentVolumeClaim{pvc}
|
||||
|
@ -134,10 +168,8 @@ var _ = utils.SIGDescribe("Volume expand [Slow]", func() {
|
|||
})
|
||||
})
|
||||
|
||||
func createResizableStorageClass(t testsuites.StorageClassTest, ns string, suffix string, c clientset.Interface) (*storage.StorageClass, error) {
|
||||
func createStorageClass(t testsuites.StorageClassTest, ns string, suffix string, c clientset.Interface) (*storage.StorageClass, error) {
|
||||
stKlass := newStorageClass(t, ns, suffix)
|
||||
allowExpansion := true
|
||||
stKlass.AllowVolumeExpansion = &allowExpansion
|
||||
|
||||
var err error
|
||||
stKlass, err = c.StorageV1().StorageClasses().Create(stKlass)
|
||||
|
|
|
@ -1063,7 +1063,11 @@ func newStorageClass(t testsuites.StorageClassTest, ns string, suffix string) *s
|
|||
if t.DelayBinding {
|
||||
bindingMode = storage.VolumeBindingWaitForFirstConsumer
|
||||
}
|
||||
return getStorageClass(pluginName, t.Parameters, &bindingMode, ns, suffix)
|
||||
sc := getStorageClass(pluginName, t.Parameters, &bindingMode, ns, suffix)
|
||||
if t.AllowVolumeExpansion {
|
||||
sc.AllowVolumeExpansion = &t.AllowVolumeExpansion
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
func getStorageClass(
|
||||
|
|
Loading…
Reference in New Issue