Skip to content

Commit

Permalink
Merge pull request kubernetes#76625 from gnufied/skip-if-no-default-sc
Browse files Browse the repository at this point in the history
Skip storage tests that depend on default SC - if no default SC is found
  • Loading branch information
k8s-ci-robot authored Apr 22, 2019
2 parents aa11d0e + 6fee8a7 commit dc08b6b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 29 deletions.
4 changes: 4 additions & 0 deletions test/e2e/apps/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var _ = SIGDescribe("StatefulSet", func() {
// StorageClass and a dynamic provisioner.
ginkgo.It("should provide basic identity", func() {
ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
framework.SkipIfNoDefaultStorageClass(c)
*(ss.Spec.Replicas) = 3
sst := framework.NewStatefulSetTester(c)
sst.PauseNewPods(ss)
Expand Down Expand Up @@ -133,6 +134,7 @@ var _ = SIGDescribe("StatefulSet", func() {
// StorageClass and a dynamic provisioner.
ginkgo.It("should adopt matching orphans and release non-matching pods", func() {
ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
framework.SkipIfNoDefaultStorageClass(c)
*(ss.Spec.Replicas) = 1
sst := framework.NewStatefulSetTester(c)
sst.PauseNewPods(ss)
Expand Down Expand Up @@ -218,6 +220,7 @@ var _ = SIGDescribe("StatefulSet", func() {
// StorageClass and a dynamic provisioner.
ginkgo.It("should not deadlock when a pod's predecessor fails", func() {
ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
framework.SkipIfNoDefaultStorageClass(c)
*(ss.Spec.Replicas) = 2
sst := framework.NewStatefulSetTester(c)
sst.PauseNewPods(ss)
Expand Down Expand Up @@ -254,6 +257,7 @@ var _ = SIGDescribe("StatefulSet", func() {
// StorageClass and a dynamic provisioner.
ginkgo.It("should perform rolling updates and roll backs of template modifications with PVCs", func() {
ginkgo.By("Creating a new StatefulSet with PVCs")
framework.SkipIfNoDefaultStorageClass(c)
*(ss.Spec.Replicas) = 3
rollbackTest(c, ns, ss)
})
Expand Down
1 change: 1 addition & 0 deletions test/e2e/framework/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ go_library(
"//pkg/apis/batch:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/extensions:go_default_library",
"//pkg/apis/storage/v1/util:go_default_library",
"//pkg/client/conditions:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/controller/deployment/util:go_default_library",
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/framework/pv_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/uuid"
clientset "k8s.io/client-go/kubernetes"
storageutil "k8s.io/kubernetes/pkg/apis/storage/v1/util"
"k8s.io/kubernetes/pkg/volume/util"
imageutils "k8s.io/kubernetes/test/utils/image"
)
Expand Down Expand Up @@ -1021,3 +1022,33 @@ func GetBoundPV(client clientset.Interface, pvc *v1.PersistentVolumeClaim) (*v1.
pv, err := client.CoreV1().PersistentVolumes().Get(claim.Spec.VolumeName, metav1.GetOptions{})
return pv, err
}

// GetDefaultStorageClassName returns default storageClass or return error
func GetDefaultStorageClassName(c clientset.Interface) (string, error) {
list, err := c.StorageV1().StorageClasses().List(metav1.ListOptions{})
if err != nil {
return "", fmt.Errorf("Error listing storage classes: %v", err)
}
var scName string
for _, sc := range list.Items {
if storageutil.IsDefaultAnnotation(sc.ObjectMeta) {
if len(scName) != 0 {
return "", fmt.Errorf("Multiple default storage classes found: %q and %q", scName, sc.Name)
}
scName = sc.Name
}
}
if len(scName) == 0 {
return "", fmt.Errorf("No default storage class found")
}
Logf("Default storage class: %q", scName)
return scName, nil
}

// SkipIfNoDefaultStorageClass skips tests if no default SC can be found.
func SkipIfNoDefaultStorageClass(c clientset.Interface) {
_, err := GetDefaultStorageClassName(c)
if err != nil {
Skipf("error finding default storageClass : %v", err)
}
}
3 changes: 1 addition & 2 deletions test/e2e/storage/pvc_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ var _ = utils.SIGDescribe("PVC Protection", func() {

By("Creating a PVC")
suffix := "pvc-protection"
defaultSC := getDefaultStorageClassName(client)
framework.SkipIfNoDefaultStorageClass(client)
testStorageClass := testsuites.StorageClassTest{
ClaimSize: "1Gi",
}
pvc = newClaim(testStorageClass, nameSpace, suffix)
pvc.Spec.StorageClassName = &defaultSC
pvc, err = client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(pvc)
framework.ExpectNoError(err, "Error creating PVC")
pvcCreatedAndNotDeleted = true
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/storage/volume_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
BeforeEach(func() {
c = f.ClientSet
ns = f.Namespace.Name
var err error
framework.SkipUnlessProviderIs("gce", "gke", "aws")
defaultScName = getDefaultStorageClassName(c)
verifyDefaultStorageClass(c, defaultScName, true)

defaultScName, err = framework.GetDefaultStorageClassName(c)
if err != nil {
framework.Failf(err.Error())
}
test := testsuites.StorageClassTest{
Name: "default",
ClaimSize: "2Gi",
}

pvc = newClaim(test, ns, "default")
var err error

metricsGrabber, err = metrics.NewMetricsGrabber(c, nil, true, false, true, false, false)

if err != nil {
Expand Down
31 changes: 8 additions & 23 deletions test/e2e/storage/volume_provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,10 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() {
// Modifying the default storage class can be disruptive to other tests that depend on it
It("should be disabled by changing the default annotation [Serial] [Disruptive]", func() {
framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere", "azure")
scName := getDefaultStorageClassName(c)
scName, scErr := framework.GetDefaultStorageClassName(c)
if scErr != nil {
framework.Failf(scErr.Error())
}
test := testsuites.StorageClassTest{
Name: "default",
ClaimSize: "2Gi",
Expand Down Expand Up @@ -806,7 +809,10 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() {
// Modifying the default storage class can be disruptive to other tests that depend on it
It("should be disabled by removing the default annotation [Serial] [Disruptive]", func() {
framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere", "azure")
scName := getDefaultStorageClassName(c)
scName, scErr := framework.GetDefaultStorageClassName(c)
if scErr != nil {
framework.Failf(scErr.Error())
}
test := testsuites.StorageClassTest{
Name: "default",
ClaimSize: "2Gi",
Expand Down Expand Up @@ -975,27 +981,6 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() {
})
})

func getDefaultStorageClassName(c clientset.Interface) string {
list, err := c.StorageV1().StorageClasses().List(metav1.ListOptions{})
if err != nil {
framework.Failf("Error listing storage classes: %v", err)
}
var scName string
for _, sc := range list.Items {
if storageutil.IsDefaultAnnotation(sc.ObjectMeta) {
if len(scName) != 0 {
framework.Failf("Multiple default storage classes found: %q and %q", scName, sc.Name)
}
scName = sc.Name
}
}
if len(scName) == 0 {
framework.Failf("No default storage class found")
}
framework.Logf("Default storage class: %q", scName)
return scName
}

func verifyDefaultStorageClass(c clientset.Interface, scName string, expectedDefault bool) {
sc, err := c.StorageV1().StorageClasses().Get(scName, metav1.GetOptions{})
framework.ExpectNoError(err)
Expand Down

0 comments on commit dc08b6b

Please sign in to comment.