func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error) { // TODO: replace with a real attribute after beta className, found := pv.Annotations["volume.beta.kubernetes.io/storage-class"] if !found { return nil, fmt.Errorf("Volume has no class annotation") } class, err := kubeClient.Storage().StorageClasses().Get(className) if err != nil { return nil, err } return class, nil }
// DoTestStorageClasses tests storage classes for one api version. func DoTestStorageClasses(t *testing.T, client clientset.Interface, ns *v1.Namespace) { // Make a storage class object. s := storage.StorageClass{ TypeMeta: metav1.TypeMeta{ Kind: "StorageClass", }, ObjectMeta: v1.ObjectMeta{ Name: "gold", }, Provisioner: provisionerPluginName, } if _, err := client.Storage().StorageClasses().Create(&s); err != nil { t.Errorf("unable to create test storage class: %v", err) } defer deleteStorageClassOrErrorf(t, client, s.Namespace, s.Name) // Template for pvcs that specify a storage class pvc := &v1.PersistentVolumeClaim{ ObjectMeta: v1.ObjectMeta{ Name: "XXX", Namespace: ns.Name, Annotations: map[string]string{ storageutil.StorageClassAnnotation: "gold", }, }, Spec: v1.PersistentVolumeClaimSpec{ Resources: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceName(v1.ResourceStorage): resource.MustParse("1G")}}, AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}, }, } pvc.ObjectMeta.Name = "uses-storageclass" if _, err := client.Core().PersistentVolumeClaims(ns.Name).Create(pvc); err != nil { t.Errorf("Failed to create pvc: %v", err) } defer deletePersistentVolumeClaimOrErrorf(t, client, ns.Name, pvc.Name) }
func deleteStorageClassOrErrorf(t *testing.T, c clientset.Interface, ns, name string) { if err := c.Storage().StorageClasses().Delete(name, nil); err != nil { t.Errorf("unable to delete storage class %v: %v", name, err) } }
// filled in BeforeEach var c clientset.Interface var ns string BeforeEach(func() { c = f.ClientSet ns = f.Namespace.Name }) framework.KubeDescribe("DynamicProvisioner", func() { It("should create and delete persistent volumes [Slow]", func() { framework.SkipUnlessProviderIs("openstack", "gce", "aws", "gke") By("creating a StorageClass") class := newStorageClass() _, err := c.Storage().StorageClasses().Create(class) defer c.Storage().StorageClasses().Delete(class.Name, nil) Expect(err).NotTo(HaveOccurred()) By("creating a claim with a dynamic provisioning annotation") claim := newClaim(ns, false) defer func() { c.Core().PersistentVolumeClaims(ns).Delete(claim.Name, nil) }() claim, err = c.Core().PersistentVolumeClaims(ns).Create(claim) Expect(err).NotTo(HaveOccurred()) testDynamicProvisioning(c, claim) }) })