Merge pull request #73818 from gnufied/add-e2e-for-no-expand

add e2e test when expansion is disabled
pull/564/head
Kubernetes Prow Robot 2019-02-13 12:16:09 -08:00 committed by GitHub
commit 812016fa23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 38 deletions

View File

@ -368,7 +368,7 @@ if [[ -n "${GCE_GLBC_IMAGE:-}" ]]; then
fi fi
if [[ -z "${KUBE_ADMISSION_CONTROL:-}" ]]; then 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 if [[ "${ENABLE_POD_SECURITY_POLICY:-}" == "true" ]]; then
ADMISSION_CONTROL="${ADMISSION_CONTROL},PodSecurityPolicy" ADMISSION_CONTROL="${ADMISSION_CONTROL},PodSecurityPolicy"
fi fi

View File

@ -18,6 +18,8 @@ package storage
import ( import (
"fmt" "fmt"
"path"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -27,8 +29,8 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/storage/testsuites"
"k8s.io/kubernetes/test/e2e/storage/utils" "k8s.io/kubernetes/test/e2e/storage/utils"
"path"
) )
var _ = utils.SIGDescribe("Mounted flexvolume expand[Slow]", func() { var _ = utils.SIGDescribe("Mounted flexvolume expand[Slow]", func() {
@ -72,7 +74,14 @@ var _ = utils.SIGDescribe("Mounted flexvolume expand[Slow]", func() {
isNodeLabeled = true 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 { if err != nil {
fmt.Printf("storage class creation error: %v\n", err) fmt.Printf("storage class creation error: %v\n", err)
} }

View File

@ -18,6 +18,8 @@ package storage
import ( import (
"fmt" "fmt"
"path"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -26,21 +28,10 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/storage/testsuites"
"k8s.io/kubernetes/test/e2e/storage/utils" "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 _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:ExpandInUsePersistentVolumes]", func() {
var ( var (
c clientset.Interface c clientset.Interface
@ -82,7 +73,14 @@ var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:Expa
isNodeLabeled = true 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 { if err != nil {
fmt.Printf("storage class creation error: %v\n", err) fmt.Printf("storage class creation error: %v\n", err)
} }

View File

@ -35,7 +35,7 @@ import (
"k8s.io/kubernetes/test/e2e/storage/utils" "k8s.io/kubernetes/test/e2e/storage/utils"
) )
var _ = utils.SIGDescribe("Mounted volume expand[Slow]", func() { var _ = utils.SIGDescribe("Mounted volume expand", func() {
var ( var (
c clientset.Interface c clientset.Interface
ns string ns string
@ -74,10 +74,11 @@ var _ = utils.SIGDescribe("Mounted volume expand[Slow]", func() {
} }
test := testsuites.StorageClassTest{ test := testsuites.StorageClassTest{
Name: "default", Name: "default",
ClaimSize: "2Gi", 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(err).NotTo(HaveOccurred(), "Error creating resizable storage class")
Expect(*resizableSc.AllowVolumeExpansion).To(BeTrue()) Expect(*resizableSc.AllowVolumeExpansion).To(BeTrue())

View File

@ -41,16 +41,17 @@ import (
// StorageClassTest represents parameters to be used by provisioning tests. // StorageClassTest represents parameters to be used by provisioning tests.
// Not all parameters are used by all tests. // Not all parameters are used by all tests.
type StorageClassTest struct { type StorageClassTest struct {
Name string Name string
CloudProviders []string CloudProviders []string
Provisioner string Provisioner string
StorageClassName string StorageClassName string
Parameters map[string]string Parameters map[string]string
DelayBinding bool DelayBinding bool
ClaimSize string ClaimSize string
ExpectedSize string ExpectedSize string
PvCheck func(claim *v1.PersistentVolumeClaim, volume *v1.PersistentVolume) PvCheck func(claim *v1.PersistentVolumeClaim, volume *v1.PersistentVolume)
VolumeMode *v1.PersistentVolumeMode VolumeMode *v1.PersistentVolumeMode
AllowVolumeExpansion bool
} }
type provisioningTestSuite struct { type provisioningTestSuite struct {

View File

@ -40,7 +40,7 @@ const (
totalResizeWaitPeriod = 20 * time.Minute totalResizeWaitPeriod = 20 * time.Minute
) )
var _ = utils.SIGDescribe("Volume expand [Slow]", func() { var _ = utils.SIGDescribe("Volume expand", func() {
var ( var (
c clientset.Interface c clientset.Interface
ns string ns string
@ -56,10 +56,11 @@ var _ = utils.SIGDescribe("Volume expand [Slow]", func() {
ns = f.Namespace.Name ns = f.Namespace.Name
framework.ExpectNoError(framework.WaitForAllNodesSchedulable(c, framework.TestContext.NodeSchedulableTimeout)) framework.ExpectNoError(framework.WaitForAllNodesSchedulable(c, framework.TestContext.NodeSchedulableTimeout))
test := testsuites.StorageClassTest{ test := testsuites.StorageClassTest{
Name: "default", Name: "default",
ClaimSize: "2Gi", 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(err).NotTo(HaveOccurred(), "Error creating resizable storage class")
Expect(resizableSc.AllowVolumeExpansion).NotTo(BeNil()) Expect(resizableSc.AllowVolumeExpansion).NotTo(BeNil())
Expect(*resizableSc.AllowVolumeExpansion).To(BeTrue()) 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)) 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 = &regularSC.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() { It("Verify if editing PVC allows resize", func() {
By("Waiting for pvc to be in bound phase") By("Waiting for pvc to be in bound phase")
pvcClaims := []*v1.PersistentVolumeClaim{pvc} 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) stKlass := newStorageClass(t, ns, suffix)
allowExpansion := true
stKlass.AllowVolumeExpansion = &allowExpansion
var err error var err error
stKlass, err = c.StorageV1().StorageClasses().Create(stKlass) stKlass, err = c.StorageV1().StorageClasses().Create(stKlass)

View File

@ -1063,7 +1063,11 @@ func newStorageClass(t testsuites.StorageClassTest, ns string, suffix string) *s
if t.DelayBinding { if t.DelayBinding {
bindingMode = storage.VolumeBindingWaitForFirstConsumer 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( func getStorageClass(