mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Merge pull request #43285 from jsafrane/fix-default-storage-class-test
Automatic merge from submit-queue (batch tested with PRs 42869, 43298, 43285) Fix default storage class tests Name of the default storage class is not "default", it must be discovered dynamically. ```release-note NONE ``` This fixes flake `storageclasses.storage.k8s.io "default" not found` in #43261
This commit is contained in:
commit
66483995b9
@ -303,11 +303,12 @@ var _ = framework.KubeDescribe("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[Slow] [Serial] [Disruptive] [Volume]", func() {
|
||||
framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere")
|
||||
scName := getDefaultStorageClassName(c)
|
||||
|
||||
By("setting the is-default StorageClass annotation to false")
|
||||
verifyDefaultStorageClass(c, true)
|
||||
defer updateDefaultStorageClass(c, "true")
|
||||
updateDefaultStorageClass(c, "false")
|
||||
verifyDefaultStorageClass(c, scName, true)
|
||||
defer updateDefaultStorageClass(c, scName, "true")
|
||||
updateDefaultStorageClass(c, scName, "false")
|
||||
|
||||
By("creating a claim with default storageclass and expecting it to timeout")
|
||||
claim := newClaim(ns)
|
||||
@ -327,11 +328,12 @@ var _ = framework.KubeDescribe("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[Slow] [Serial] [Disruptive] [Volume]", func() {
|
||||
framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke", "vsphere")
|
||||
scName := getDefaultStorageClassName(c)
|
||||
|
||||
By("removing the is-default StorageClass annotation")
|
||||
verifyDefaultStorageClass(c, true)
|
||||
defer updateDefaultStorageClass(c, "true")
|
||||
updateDefaultStorageClass(c, "")
|
||||
verifyDefaultStorageClass(c, scName, true)
|
||||
defer updateDefaultStorageClass(c, scName, "true")
|
||||
updateDefaultStorageClass(c, scName, "")
|
||||
|
||||
By("creating a claim with default storageclass and expecting it to timeout")
|
||||
claim := newClaim(ns)
|
||||
@ -350,14 +352,35 @@ var _ = framework.KubeDescribe("Dynamic provisioning", func() {
|
||||
})
|
||||
})
|
||||
|
||||
func verifyDefaultStorageClass(c clientset.Interface, expectedDefault bool) {
|
||||
sc, err := c.StorageV1().StorageClasses().Get("default", metav1.GetOptions{})
|
||||
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{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(storageutil.IsDefaultAnnotation(sc.ObjectMeta)).To(Equal(expectedDefault))
|
||||
}
|
||||
|
||||
func updateDefaultStorageClass(c clientset.Interface, defaultStr string) {
|
||||
sc, err := c.StorageV1().StorageClasses().Get("default", metav1.GetOptions{})
|
||||
func updateDefaultStorageClass(c clientset.Interface, scName string, defaultStr string) {
|
||||
sc, err := c.StorageV1().StorageClasses().Get(scName, metav1.GetOptions{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
if defaultStr == "" {
|
||||
@ -376,7 +399,7 @@ func updateDefaultStorageClass(c clientset.Interface, defaultStr string) {
|
||||
if defaultStr == "true" {
|
||||
expectedDefault = true
|
||||
}
|
||||
verifyDefaultStorageClass(c, expectedDefault)
|
||||
verifyDefaultStorageClass(c, scName, expectedDefault)
|
||||
}
|
||||
|
||||
func newClaim(ns string) *v1.PersistentVolumeClaim {
|
||||
|
Loading…
Reference in New Issue
Block a user