func newClaim(ns string, alpha bool) *v1.PersistentVolumeClaim { claim := v1.PersistentVolumeClaim{ ObjectMeta: v1.ObjectMeta{ GenerateName: "pvc-", Namespace: ns, }, Spec: v1.PersistentVolumeClaimSpec{ AccessModes: []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, }, Resources: v1.ResourceRequirements{ Requests: v1.ResourceList{ v1.ResourceName(v1.ResourceStorage): resource.MustParse(requestedSize), }, }, }, } if alpha { claim.Annotations = map[string]string{ storageutil.AlphaStorageClassAnnotation: "", } } else { claim.Annotations = map[string]string{ storageutil.StorageClassAnnotation: "fast", } } return &claim }
// newClaim returns a new claim with given attributes func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.PersistentVolumeClaimPhase, annotations ...string) *v1.PersistentVolumeClaim { claim := v1.PersistentVolumeClaim{ ObjectMeta: v1.ObjectMeta{ Name: name, Namespace: testNamespace, UID: types.UID(claimUID), ResourceVersion: "1", }, Spec: v1.PersistentVolumeClaimSpec{ AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce, v1.ReadOnlyMany}, Resources: v1.ResourceRequirements{ Requests: v1.ResourceList{ v1.ResourceName(v1.ResourceStorage): resource.MustParse(capacity), }, }, VolumeName: boundToVolume, }, Status: v1.PersistentVolumeClaimStatus{ Phase: phase, }, } // Make sure v1.GetReference(claim) works claim.ObjectMeta.SelfLink = testapi.Default.SelfLink("pvc", name) if len(annotations) > 0 { claim.Annotations = make(map[string]string) for _, a := range annotations { switch a { case storageutil.StorageClassAnnotation: claim.Annotations[a] = "gold" case annStorageProvisioner: claim.Annotations[a] = mockPluginName default: claim.Annotations[a] = "yes" } } } // Bound claims must have proper Status. if phase == v1.ClaimBound { claim.Status.AccessModes = claim.Spec.AccessModes // For most of the tests it's enough to copy claim's requested capacity, // individual tests can adjust it using withExpectedCapacity() claim.Status.Capacity = claim.Spec.Resources.Requests } return &claim }