diff --git a/pkg/api/helpers.go b/pkg/api/helpers.go index 970792fc74d..4ada0ba3743 100644 --- a/pkg/api/helpers.go +++ b/pkg/api/helpers.go @@ -557,3 +557,42 @@ func PodAnnotationsFromSysctls(sysctls []Sysctl) string { } return strings.Join(kvs, ",") } + +// GetPersistentVolumeClass returns StorageClassName. +func GetPersistentVolumeClass(volume *PersistentVolume) string { + // Use beta annotation first + if class, found := volume.Annotations[BetaStorageClassAnnotation]; found { + return class + } + + return volume.Spec.StorageClassName +} + +// GetPersistentVolumeClaimClass returns StorageClassName. If no storage class was +// requested, it returns "". +func GetPersistentVolumeClaimClass(claim *PersistentVolumeClaim) string { + // Use beta annotation first + if class, found := claim.Annotations[BetaStorageClassAnnotation]; found { + return class + } + + if claim.Spec.StorageClassName != nil { + return *claim.Spec.StorageClassName + } + + return "" +} + +// PersistentVolumeClaimHasClass returns true if given claim has set StorageClassName field. +func PersistentVolumeClaimHasClass(claim *PersistentVolumeClaim) bool { + // Use beta annotation first + if _, found := claim.Annotations[BetaStorageClassAnnotation]; found { + return true + } + + if claim.Spec.StorageClassName != nil { + return true + } + + return false +} diff --git a/pkg/api/types.go b/pkg/api/types.go index 1fa4558be44..1b910e3e4ac 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -375,6 +375,12 @@ type PersistentVolumeClaimVolumeSource struct { ReadOnly bool } +const ( + // BetaStorageClassAnnotation represents the beta/previous StorageClass annotation. + // It's currently still used and will be held for backwards compatibility + BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" +) + // +genclient=true // +nonNamespaced=true diff --git a/pkg/api/v1/helpers.go b/pkg/api/v1/helpers.go index b6443011628..83495de0b4d 100644 --- a/pkg/api/v1/helpers.go +++ b/pkg/api/v1/helpers.go @@ -591,3 +591,42 @@ func GetAffinityFromPodAnnotations(annotations map[string]string) (*Affinity, er } return nil, nil } + +// GetPersistentVolumeClass returns StorageClassName. +func GetPersistentVolumeClass(volume *PersistentVolume) string { + // Use beta annotation first + if class, found := volume.Annotations[BetaStorageClassAnnotation]; found { + return class + } + + return volume.Spec.StorageClassName +} + +// GetPersistentVolumeClaimClass returns StorageClassName. If no storage class was +// requested, it returns "". +func GetPersistentVolumeClaimClass(claim *PersistentVolumeClaim) string { + // Use beta annotation first + if class, found := claim.Annotations[BetaStorageClassAnnotation]; found { + return class + } + + if claim.Spec.StorageClassName != nil { + return *claim.Spec.StorageClassName + } + + return "" +} + +// PersistentVolumeClaimHasClass returns true if given claim has set StorageClassName field. +func PersistentVolumeClaimHasClass(claim *PersistentVolumeClaim) bool { + // Use beta annotation first + if _, found := claim.Annotations[BetaStorageClassAnnotation]; found { + return true + } + + if claim.Spec.StorageClassName != nil { + return true + } + + return false +} diff --git a/pkg/api/v1/types.go b/pkg/api/v1/types.go index 64842ed6cd5..2efa564d7ce 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -421,6 +421,17 @@ type PersistentVolumeSource struct { PortworxVolume *PortworxVolumeSource `json:"portworxVolume,omitempty" protobuf:"bytes,18,opt,name=portworxVolume"` } +const ( + // AlphaStorageClassAnnotation represents the previous alpha storage class + // annotation. It's currently still used and will be held for backwards + // compatibility + AlphaStorageClassAnnotation = "volume.alpha.kubernetes.io/storage-class" + + // BetaStorageClassAnnotation represents the beta/previous StorageClass annotation. + // It's currently still used and will be held for backwards compatibility + BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" +) + // +genclient=true // +nonNamespaced=true diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 6a525d8b22d..324c6047465 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -44,7 +44,6 @@ import ( utilpod "k8s.io/kubernetes/pkg/api/pod" apiservice "k8s.io/kubernetes/pkg/api/service" "k8s.io/kubernetes/pkg/api/v1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/util" "k8s.io/kubernetes/pkg/capabilities" "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/security/apparmor" @@ -1267,7 +1266,8 @@ func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *api.PersistentVolumeCla } // storageclass annotation should be immutable after creation - allErrs = append(allErrs, ValidateImmutableAnnotation(newPvc.ObjectMeta.Annotations[storageutil.StorageClassAnnotation], oldPvc.ObjectMeta.Annotations[storageutil.StorageClassAnnotation], storageutil.StorageClassAnnotation, field.NewPath("metadata"))...) + // TODO: remove Beta when no longer needed + allErrs = append(allErrs, ValidateImmutableAnnotation(newPvc.ObjectMeta.Annotations[v1.BetaStorageClassAnnotation], oldPvc.ObjectMeta.Annotations[v1.BetaStorageClassAnnotation], v1.BetaStorageClassAnnotation, field.NewPath("metadata"))...) newPvc.Status = oldPvc.Status return allErrs diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index c96c0349f76..df78584d311 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -28,7 +28,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/service" - storageutil "k8s.io/kubernetes/pkg/apis/storage/util" + "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/capabilities" "k8s.io/kubernetes/pkg/security/apparmor" "k8s.io/kubernetes/pkg/volume" @@ -253,7 +253,7 @@ func testVolumeClaim(name string, namespace string, spec api.PersistentVolumeCla func testVolumeClaimStorageClass(name string, namespace string, annval string, spec api.PersistentVolumeClaimSpec) *api.PersistentVolumeClaim { annotations := map[string]string{ - storageutil.StorageClassAnnotation: annval, + v1.BetaStorageClassAnnotation: annval, } return &api.PersistentVolumeClaim{ diff --git a/pkg/apis/storage/util/helpers.go b/pkg/apis/storage/util/helpers.go index 8df24acbf0a..75caea068c3 100644 --- a/pkg/apis/storage/util/helpers.go +++ b/pkg/apis/storage/util/helpers.go @@ -16,10 +16,7 @@ limitations under the License. package util -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/api" -) +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // IsDefaultStorageClassAnnotation represents a StorageClass annotation that // marks a class as the default StorageClass @@ -27,87 +24,6 @@ import ( const IsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class" const BetaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class" -// AlphaStorageClassAnnotation represents the previous alpha storage class -// annotation. it's no longer used and held here for posterity. -const AlphaStorageClassAnnotation = "volume.alpha.kubernetes.io/storage-class" - -// BetaStorageClassAnnotation represents the beta/previous StorageClass annotation. -// It's currently still used and will be held for backwards compatibility -const BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" - -// StorageClassAnnotation represents the storage class associated with a resource. -// It currently matches the Beta value and can change when official is set. -// - in PersistentVolumeClaim it represents required class to match. -// Only PersistentVolumes with the same class (i.e. annotation with the same -// value) can be bound to the claim. In case no such volume exists, the -// controller will provision a new one using StorageClass instance with -// the same name as the annotation value. -// - in PersistentVolume it represents storage class to which the persistent -// volume belongs. -//TODO: Update this to final annotation value as it matches BetaStorageClassAnnotation for now -const StorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" - -// GetVolumeStorageClass returns value of StorageClassAnnotation or empty string in case -// the annotation does not exist. -// TODO: change to PersistentVolume.Spec.Class value when this attribute is -// introduced. -func GetVolumeStorageClass(volume *api.PersistentVolume) string { - if class, found := volume.Annotations[StorageClassAnnotation]; found { - return class - } - - // 'nil' is interpreted as "", i.e. the volume does not belong to any class. - return "" -} - -// GetClaimStorageClass returns name of class that is requested by given claim. -// Request for `nil` class is interpreted as request for class "", -// i.e. for a classless PV. -// TODO: change to PersistentVolumeClaim.Spec.Class value when this -// attribute is introduced. -func GetClaimStorageClass(claim *api.PersistentVolumeClaim) string { - if class, found := claim.Annotations[StorageClassAnnotation]; found { - return class - } - - return "" -} - -// GetStorageClassAnnotation returns the StorageClass value -// if the annotation is set, empty string if not -// TODO: remove Alpha and Beta when no longer used or needed -func GetStorageClassAnnotation(obj metav1.ObjectMeta) string { - if class, ok := obj.Annotations[StorageClassAnnotation]; ok { - return class - } - if class, ok := obj.Annotations[BetaStorageClassAnnotation]; ok { - return class - } - if class, ok := obj.Annotations[AlphaStorageClassAnnotation]; ok { - return class - } - - return "" -} - -// HasStorageClassAnnotation returns a boolean -// if the annotation is set -// TODO: remove Alpha and Beta when no longer used or needed -func HasStorageClassAnnotation(obj metav1.ObjectMeta) bool { - if _, found := obj.Annotations[StorageClassAnnotation]; found { - return found - } - if _, found := obj.Annotations[BetaStorageClassAnnotation]; found { - return found - } - if _, found := obj.Annotations[AlphaStorageClassAnnotation]; found { - return found - } - - return false - -} - // IsDefaultAnnotationText returns a pretty Yes/No String if // the annotation is set // TODO: remove Beta when no longer needed diff --git a/pkg/apis/storage/v1/util/helpers.go b/pkg/apis/storage/v1/util/helpers.go index 39c4f6f3ed5..75caea068c3 100644 --- a/pkg/apis/storage/v1/util/helpers.go +++ b/pkg/apis/storage/v1/util/helpers.go @@ -16,10 +16,7 @@ limitations under the License. package util -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/api/v1" -) +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // IsDefaultStorageClassAnnotation represents a StorageClass annotation that // marks a class as the default StorageClass @@ -27,87 +24,6 @@ import ( const IsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class" const BetaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class" -// AlphaStorageClassAnnotation represents the previous alpha storage class -// annotation. it's no longer used and held here for posterity. -const AlphaStorageClassAnnotation = "volume.alpha.kubernetes.io/storage-class" - -// BetaStorageClassAnnotation represents the beta/previous StorageClass annotation. -// It's currently still used and will be held for backwards compatibility -const BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" - -// StorageClassAnnotation represents the storage class associated with a resource. -// It currently matches the Beta value and can change when official is set. -// - in PersistentVolumeClaim it represents required class to match. -// Only PersistentVolumes with the same class (i.e. annotation with the same -// value) can be bound to the claim. In case no such volume exists, the -// controller will provision a new one using StorageClass instance with -// the same name as the annotation value. -// - in PersistentVolume it represents storage class to which the persistent -// volume belongs. -//TODO: Update this to final annotation value as it matches BetaStorageClassAnnotation for now -const StorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" - -// GetVolumeStorageClass returns value of StorageClassAnnotation or empty string in case -// the annotation does not exist. -// TODO: change to PersistentVolume.Spec.Class value when this attribute is -// introduced. -func GetVolumeStorageClass(volume *v1.PersistentVolume) string { - if class, found := volume.Annotations[StorageClassAnnotation]; found { - return class - } - - // 'nil' is interpreted as "", i.e. the volume does not belong to any class. - return "" -} - -// GetClaimStorageClass returns name of class that is requested by given claim. -// Request for `nil` class is interpreted as request for class "", -// i.e. for a classless PV. -// TODO: change to PersistentVolumeClaim.Spec.Class value when this -// attribute is introduced. -func GetClaimStorageClass(claim *v1.PersistentVolumeClaim) string { - if class, found := claim.Annotations[StorageClassAnnotation]; found { - return class - } - - return "" -} - -// GetStorageClassAnnotation returns the StorageClass value -// if the annotation is set, empty string if not -// TODO: remove Alpha and Beta when no longer used or needed -func GetStorageClassAnnotation(obj metav1.ObjectMeta) string { - if class, ok := obj.Annotations[StorageClassAnnotation]; ok { - return class - } - if class, ok := obj.Annotations[BetaStorageClassAnnotation]; ok { - return class - } - if class, ok := obj.Annotations[AlphaStorageClassAnnotation]; ok { - return class - } - - return "" -} - -// HasStorageClassAnnotation returns a boolean -// if the annotation is set -// TODO: remove Alpha and Beta when no longer used or needed -func HasStorageClassAnnotation(obj metav1.ObjectMeta) bool { - if _, found := obj.Annotations[StorageClassAnnotation]; found { - return found - } - if _, found := obj.Annotations[BetaStorageClassAnnotation]; found { - return found - } - if _, found := obj.Annotations[AlphaStorageClassAnnotation]; found { - return found - } - - return false - -} - // IsDefaultAnnotationText returns a pretty Yes/No String if // the annotation is set // TODO: remove Beta when no longer needed diff --git a/pkg/apis/storage/v1beta1/util/helpers.go b/pkg/apis/storage/v1beta1/util/helpers.go index 39c4f6f3ed5..75caea068c3 100644 --- a/pkg/apis/storage/v1beta1/util/helpers.go +++ b/pkg/apis/storage/v1beta1/util/helpers.go @@ -16,10 +16,7 @@ limitations under the License. package util -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/api/v1" -) +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // IsDefaultStorageClassAnnotation represents a StorageClass annotation that // marks a class as the default StorageClass @@ -27,87 +24,6 @@ import ( const IsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class" const BetaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class" -// AlphaStorageClassAnnotation represents the previous alpha storage class -// annotation. it's no longer used and held here for posterity. -const AlphaStorageClassAnnotation = "volume.alpha.kubernetes.io/storage-class" - -// BetaStorageClassAnnotation represents the beta/previous StorageClass annotation. -// It's currently still used and will be held for backwards compatibility -const BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" - -// StorageClassAnnotation represents the storage class associated with a resource. -// It currently matches the Beta value and can change when official is set. -// - in PersistentVolumeClaim it represents required class to match. -// Only PersistentVolumes with the same class (i.e. annotation with the same -// value) can be bound to the claim. In case no such volume exists, the -// controller will provision a new one using StorageClass instance with -// the same name as the annotation value. -// - in PersistentVolume it represents storage class to which the persistent -// volume belongs. -//TODO: Update this to final annotation value as it matches BetaStorageClassAnnotation for now -const StorageClassAnnotation = "volume.beta.kubernetes.io/storage-class" - -// GetVolumeStorageClass returns value of StorageClassAnnotation or empty string in case -// the annotation does not exist. -// TODO: change to PersistentVolume.Spec.Class value when this attribute is -// introduced. -func GetVolumeStorageClass(volume *v1.PersistentVolume) string { - if class, found := volume.Annotations[StorageClassAnnotation]; found { - return class - } - - // 'nil' is interpreted as "", i.e. the volume does not belong to any class. - return "" -} - -// GetClaimStorageClass returns name of class that is requested by given claim. -// Request for `nil` class is interpreted as request for class "", -// i.e. for a classless PV. -// TODO: change to PersistentVolumeClaim.Spec.Class value when this -// attribute is introduced. -func GetClaimStorageClass(claim *v1.PersistentVolumeClaim) string { - if class, found := claim.Annotations[StorageClassAnnotation]; found { - return class - } - - return "" -} - -// GetStorageClassAnnotation returns the StorageClass value -// if the annotation is set, empty string if not -// TODO: remove Alpha and Beta when no longer used or needed -func GetStorageClassAnnotation(obj metav1.ObjectMeta) string { - if class, ok := obj.Annotations[StorageClassAnnotation]; ok { - return class - } - if class, ok := obj.Annotations[BetaStorageClassAnnotation]; ok { - return class - } - if class, ok := obj.Annotations[AlphaStorageClassAnnotation]; ok { - return class - } - - return "" -} - -// HasStorageClassAnnotation returns a boolean -// if the annotation is set -// TODO: remove Alpha and Beta when no longer used or needed -func HasStorageClassAnnotation(obj metav1.ObjectMeta) bool { - if _, found := obj.Annotations[StorageClassAnnotation]; found { - return found - } - if _, found := obj.Annotations[BetaStorageClassAnnotation]; found { - return found - } - if _, found := obj.Annotations[AlphaStorageClassAnnotation]; found { - return found - } - - return false - -} - // IsDefaultAnnotationText returns a pretty Yes/No String if // the annotation is set // TODO: remove Beta when no longer needed diff --git a/pkg/controller/volume/persistentvolume/binder_test.go b/pkg/controller/volume/persistentvolume/binder_test.go index b232b3d903c..63e2852fed1 100644 --- a/pkg/controller/volume/persistentvolume/binder_test.go +++ b/pkg/controller/volume/persistentvolume/binder_test.go @@ -21,7 +21,6 @@ import ( "k8s.io/kubernetes/pkg/api/v1" storage "k8s.io/kubernetes/pkg/apis/storage/v1beta1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" ) // Test single call to syncClaim and syncVolume methods. @@ -435,14 +434,14 @@ func TestSync(t *testing.T) { "13-1 - binding to class", []*v1.PersistentVolume{ newVolume("volume13-1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-1-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, storageutil.StorageClassAnnotation), + newVolume("volume13-1-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), }, []*v1.PersistentVolume{ newVolume("volume13-1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-1-2", "10Gi", "uid13-1", "claim13-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, storageutil.StorageClassAnnotation), + newVolume("volume13-1-2", "10Gi", "uid13-1", "claim13-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, v1.BetaStorageClassAnnotation), }, - newClaimArray("claim13-1", "uid13-1", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - withExpectedCapacity("10Gi", newClaimArray("claim13-1", "uid13-1", "1Gi", "volume13-1-2", v1.ClaimBound, annBoundByController, storageutil.StorageClassAnnotation, annBindCompleted)), + newClaimArray("claim13-1", "uid13-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + withExpectedCapacity("10Gi", newClaimArray("claim13-1", "uid13-1", "1Gi", "volume13-1-2", v1.ClaimBound, annBoundByController, v1.BetaStorageClassAnnotation, annBindCompleted)), noevents, noerrors, testSyncClaim, }, { @@ -450,11 +449,11 @@ func TestSync(t *testing.T) { // smaller PV with a class available "13-2 - binding without a class", []*v1.PersistentVolume{ - newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, storageutil.StorageClassAnnotation), + newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), newVolume("volume13-2-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), }, []*v1.PersistentVolume{ - newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, storageutil.StorageClassAnnotation), + newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), newVolume("volume13-2-2", "10Gi", "uid13-2", "claim13-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), }, newClaimArray("claim13-2", "uid13-2", "1Gi", "", v1.ClaimPending), @@ -467,14 +466,14 @@ func TestSync(t *testing.T) { "13-3 - binding to specific a class", volumeWithClass("silver", []*v1.PersistentVolume{ newVolume("volume13-3-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-3-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, storageutil.StorageClassAnnotation), + newVolume("volume13-3-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), }), volumeWithClass("silver", []*v1.PersistentVolume{ newVolume("volume13-3-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-3-2", "10Gi", "uid13-3", "claim13-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, storageutil.StorageClassAnnotation), + newVolume("volume13-3-2", "10Gi", "uid13-3", "claim13-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, v1.BetaStorageClassAnnotation), }), - newClaimArray("claim13-3", "uid13-3", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - withExpectedCapacity("10Gi", newClaimArray("claim13-3", "uid13-3", "1Gi", "volume13-3-2", v1.ClaimBound, annBoundByController, annBindCompleted, storageutil.StorageClassAnnotation)), + newClaimArray("claim13-3", "uid13-3", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + withExpectedCapacity("10Gi", newClaimArray("claim13-3", "uid13-3", "1Gi", "volume13-3-2", v1.ClaimBound, annBoundByController, annBindCompleted, v1.BetaStorageClassAnnotation)), noevents, noerrors, testSyncClaim, }, { diff --git a/pkg/controller/volume/persistentvolume/framework_test.go b/pkg/controller/volume/persistentvolume/framework_test.go index b50666e523c..6903bd7516a 100644 --- a/pkg/controller/volume/persistentvolume/framework_test.go +++ b/pkg/controller/volume/persistentvolume/framework_test.go @@ -43,7 +43,6 @@ import ( "k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/v1" storage "k8s.io/kubernetes/pkg/apis/storage/v1beta1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/fake" informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions" @@ -658,7 +657,7 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v switch a { case annDynamicallyProvisioned: volume.Annotations[a] = mockPluginName - case storageutil.StorageClassAnnotation: + case v1.BetaStorageClassAnnotation: volume.Annotations[a] = "gold" default: volume.Annotations[a] = "yes" @@ -711,9 +710,9 @@ func withMessage(message string, volumes []*v1.PersistentVolume) []*v1.Persisten // Meant to be used to compose claims specified inline in a test. func volumeWithClass(className string, volumes []*v1.PersistentVolume) []*v1.PersistentVolume { if volumes[0].Annotations == nil { - volumes[0].Annotations = map[string]string{storageutil.StorageClassAnnotation: className} + volumes[0].Annotations = map[string]string{v1.BetaStorageClassAnnotation: className} } else { - volumes[0].Annotations[storageutil.StorageClassAnnotation] = className + volumes[0].Annotations[v1.BetaStorageClassAnnotation] = className } return volumes } @@ -755,7 +754,7 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten claim.Annotations = make(map[string]string) for _, a := range annotations { switch a { - case storageutil.StorageClassAnnotation: + case v1.BetaStorageClassAnnotation: claim.Annotations[a] = "gold" case annStorageProvisioner: claim.Annotations[a] = mockPluginName @@ -788,9 +787,9 @@ func newClaimArray(name, claimUID, capacity, boundToVolume string, phase v1.Pers // Meant to be used to compose claims specified inline in a test. func claimWithClass(className string, claims []*v1.PersistentVolumeClaim) []*v1.PersistentVolumeClaim { if claims[0].Annotations == nil { - claims[0].Annotations = map[string]string{storageutil.StorageClassAnnotation: className} + claims[0].Annotations = map[string]string{v1.BetaStorageClassAnnotation: className} } else { - claims[0].Annotations[storageutil.StorageClassAnnotation] = className + claims[0].Annotations[v1.BetaStorageClassAnnotation] = className } return claims } diff --git a/pkg/controller/volume/persistentvolume/index.go b/pkg/controller/volume/persistentvolume/index.go index 059e33d927c..3d4f5c0b4f2 100644 --- a/pkg/controller/volume/persistentvolume/index.go +++ b/pkg/controller/volume/persistentvolume/index.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" "k8s.io/kubernetes/pkg/api/v1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" ) // persistentVolumeOrderedIndex is a cache.Store that keeps persistent volumes @@ -93,7 +92,7 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol var smallestVolumeSize int64 requestedQty := claim.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)] requestedSize := requestedQty.Value() - requestedClass := storageutil.GetClaimStorageClass(claim) + requestedClass := v1.GetPersistentVolumeClaimClass(claim) var selector labels.Selector if claim.Spec.Selector != nil { @@ -134,7 +133,7 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol // with existing PVs, findByClaim must find only PVs that are // pre-bound to the claim (by dynamic provisioning). TODO: remove in // 1.5 - if metav1.HasAnnotation(claim.ObjectMeta, storageutil.AlphaStorageClassAnnotation) { + if metav1.HasAnnotation(claim.ObjectMeta, v1.AlphaStorageClassAnnotation) { continue } @@ -147,7 +146,7 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol } else if selector != nil && !selector.Matches(labels.Set(volume.Labels)) { continue } - if storageutil.GetVolumeStorageClass(volume) != requestedClass { + if v1.GetPersistentVolumeClass(volume) != requestedClass { continue } diff --git a/pkg/controller/volume/persistentvolume/index_test.go b/pkg/controller/volume/persistentvolume/index_test.go index b0e87e795b5..995bd05003b 100644 --- a/pkg/controller/volume/persistentvolume/index_test.go +++ b/pkg/controller/volume/persistentvolume/index_test.go @@ -25,7 +25,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/v1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" ) func makePVC(size string, modfn func(*v1.PersistentVolumeClaim)) *v1.PersistentVolumeClaim { @@ -113,7 +112,7 @@ func TestMatchVolume(t *testing.T) { expectedMatch: "gce-pd-silver1", claim: makePVC("1G", func(pvc *v1.PersistentVolumeClaim) { pvc.ObjectMeta.Annotations = map[string]string{ - storageutil.StorageClassAnnotation: "silver", + v1.BetaStorageClassAnnotation: "silver", } pvc.Spec.Selector = &metav1.LabelSelector{ MatchLabels: map[string]string{ @@ -127,7 +126,7 @@ func TestMatchVolume(t *testing.T) { expectedMatch: "gce-pd-silver2", claim: makePVC("1G", func(pvc *v1.PersistentVolumeClaim) { pvc.ObjectMeta.Annotations = map[string]string{ - storageutil.StorageClassAnnotation: "silver", + v1.BetaStorageClassAnnotation: "silver", } pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce} }), @@ -543,7 +542,7 @@ func createTestVolumes() []*v1.PersistentVolume { "should-exist": "true", }, Annotations: map[string]string{ - storageutil.StorageClassAnnotation: "silver", + v1.BetaStorageClassAnnotation: "silver", }, }, Spec: v1.PersistentVolumeSpec{ @@ -563,7 +562,7 @@ func createTestVolumes() []*v1.PersistentVolume { UID: "gce-pd-silver2", Name: "gce0024", Annotations: map[string]string{ - storageutil.StorageClassAnnotation: "silver", + v1.BetaStorageClassAnnotation: "silver", }, }, Spec: v1.PersistentVolumeSpec{ @@ -583,7 +582,7 @@ func createTestVolumes() []*v1.PersistentVolume { UID: "gce-pd-gold", Name: "gce0025", Annotations: map[string]string{ - storageutil.StorageClassAnnotation: "gold", + v1.BetaStorageClassAnnotation: "gold", }, }, Spec: v1.PersistentVolumeSpec{ diff --git a/pkg/controller/volume/persistentvolume/provision_test.go b/pkg/controller/volume/persistentvolume/provision_test.go index 83e802d6304..9827bb2d3df 100644 --- a/pkg/controller/volume/persistentvolume/provision_test.go +++ b/pkg/controller/volume/persistentvolume/provision_test.go @@ -23,7 +23,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/api/v1" storage "k8s.io/kubernetes/pkg/apis/storage/v1beta1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" ) var class1Parameters = map[string]string{ @@ -109,10 +108,10 @@ func TestProvisionSync(t *testing.T) { // Provision a volume (with a default class) "11-1 - successful provision with storage class 1", novolumes, - newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, storageutil.StorageClassAnnotation), - newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), + newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), // Binding will be completed in the next syncClaim - newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { @@ -120,8 +119,8 @@ func TestProvisionSync(t *testing.T) { "11-2 - plugin not found", novolumes, novolumes, - newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), + newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), []string{"Warning ProvisioningFailed"}, noerrors, testSyncClaim, }, @@ -130,8 +129,8 @@ func TestProvisionSync(t *testing.T) { "11-3 - newProvisioner failure", novolumes, novolumes, - newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, @@ -140,18 +139,18 @@ func TestProvisionSync(t *testing.T) { "11-4 - provision failure", novolumes, novolumes, - newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Error}, testSyncClaim), }, { // No provisioning if there is a matching volume available "11-6 - provisioning when there is a volume available", - newVolumeArray("volume11-6", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, storageutil.StorageClassAnnotation), - newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, storageutil.StorageClassAnnotation), - newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, storageutil.StorageClassAnnotation, annBoundByController, annBindCompleted), + newVolumeArray("volume11-6", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), + newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, v1.BetaStorageClassAnnotation, annBoundByController, annBindCompleted), noevents, noerrors, // No provisioning plugin confingure - makes the test fail when // the controller errorneously tries to provision something @@ -162,16 +161,16 @@ func TestProvisionSync(t *testing.T) { // a volume. "11-7 - claim is bound before provisioning", novolumes, - newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, storageutil.StorageClassAnnotation), - newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), + newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), // The claim would be bound in next syncClaim - newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), noevents, noerrors, wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *volumeReactor) { // Create a volume before provisionClaimOperation starts. // This similates a parallel controller provisioning the volume. reactor.lock.Lock() - volume := newVolume("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, storageutil.StorageClassAnnotation) + volume := newVolume("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation) reactor.volumes[volume.Name] = volume reactor.lock.Unlock() }), @@ -181,10 +180,10 @@ func TestProvisionSync(t *testing.T) { // second retry succeeds "11-8 - cannot save provisioned volume", novolumes, - newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, storageutil.StorageClassAnnotation), - newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), + newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), // Binding will be completed in the next syncClaim - newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Normal ProvisioningSucceeded"}, []reactorError{ // Inject error to the first @@ -200,8 +199,8 @@ func TestProvisionSync(t *testing.T) { "11-9 - cannot save provisioned volume, delete succeeds", novolumes, novolumes, - newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -225,8 +224,8 @@ func TestProvisionSync(t *testing.T) { "11-10 - cannot save provisioned volume, no delete plugin found", novolumes, novolumes, - newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -246,8 +245,8 @@ func TestProvisionSync(t *testing.T) { "11-11 - cannot save provisioned volume, deleter fails", novolumes, novolumes, - newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -276,8 +275,8 @@ func TestProvisionSync(t *testing.T) { "11-12 - cannot save provisioned volume, delete succeeds 2nd time", novolumes, novolumes, - newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -367,9 +366,9 @@ func TestAlphaProvisionSync(t *testing.T) { "14-1 - successful alpha provisioning", novolumes, newVolumeArray("pvc-uid14-1", "1Gi", "uid14-1", "claim14-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned), - newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, storageutil.AlphaStorageClassAnnotation), + newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation), // Binding will be completed in the next syncClaim - newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, storageutil.AlphaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation, annStorageProvisioner), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provisionAlphaSuccess}, testSyncClaim), }, { @@ -381,9 +380,9 @@ func TestAlphaProvisionSync(t *testing.T) { newVolume("volume14-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), newVolume("pvc-uid14-2", "1Gi", "uid14-2", "claim14-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned), }, - newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, storageutil.AlphaStorageClassAnnotation), + newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation), // Binding will be completed in the next syncClaim - newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, storageutil.AlphaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation, annStorageProvisioner), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provisionAlphaSuccess}, testSyncClaim), }, } @@ -410,9 +409,9 @@ func TestProvisionMultiSync(t *testing.T) { // Provision a volume with binding "12-1 - successful provision", novolumes, - newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, storageutil.StorageClassAnnotation), - newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, storageutil.StorageClassAnnotation), - newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, storageutil.StorageClassAnnotation, annBoundByController, annBindCompleted, annStorageProvisioner), + newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), + newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, v1.BetaStorageClassAnnotation, annBoundByController, annBindCompleted, annStorageProvisioner), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, } diff --git a/pkg/controller/volume/persistentvolume/pv_controller.go b/pkg/controller/volume/persistentvolume/pv_controller.go index 6e42e1920b4..5f8aac18532 100644 --- a/pkg/controller/volume/persistentvolume/pv_controller.go +++ b/pkg/controller/volume/persistentvolume/pv_controller.go @@ -29,7 +29,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" storage "k8s.io/kubernetes/pkg/apis/storage/v1beta1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" corelisters "k8s.io/kubernetes/pkg/client/listers/core/v1" storagelisters "k8s.io/kubernetes/pkg/client/listers/storage/v1beta1" @@ -244,7 +243,7 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *v1.PersistentVol glog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: no volume found", claimToClaimKey(claim)) // No PV could be found // OBSERVATION: pvc is "Pending", will retry - if storageutil.GetClaimStorageClass(claim) != "" || metav1.HasAnnotation(claim.ObjectMeta, storageutil.AlphaStorageClassAnnotation) { + if v1.GetPersistentVolumeClaimClass(claim) != "" || metav1.HasAnnotation(claim.ObjectMeta, v1.AlphaStorageClassAnnotation) { if err = ctrl.provisionClaim(claim); err != nil { return err } @@ -1224,7 +1223,7 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interfa return } - claimClass := storageutil.GetClaimStorageClass(claim) + claimClass := v1.GetPersistentVolumeClaimClass(claim) glog.V(4).Infof("provisionClaimOperation [%s] started, class: %q", claimToClaimKey(claim), claimClass) plugin, storageClass, err := ctrl.findProvisionablePlugin(claim) @@ -1332,7 +1331,7 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interfa // by storage.AlphaStorageClassAnnotation // TODO: remove this check in 1.5, storage.StorageClassAnnotation will be always non-empty there. if claimClass != "" { - metav1.SetMetaDataAnnotation(&volume.ObjectMeta, storageutil.StorageClassAnnotation, claimClass) + metav1.SetMetaDataAnnotation(&volume.ObjectMeta, v1.BetaStorageClassAnnotation, claimClass) } // Try to create the PV object several times @@ -1439,12 +1438,12 @@ func (ctrl *PersistentVolumeController) newRecyclerEventRecorder(volume *v1.Pers // provisioner is requested. func (ctrl *PersistentVolumeController) findProvisionablePlugin(claim *v1.PersistentVolumeClaim) (vol.ProvisionableVolumePlugin, *storage.StorageClass, error) { // TODO: remove this alpha behavior in 1.5 - alpha := metav1.HasAnnotation(claim.ObjectMeta, storageutil.AlphaStorageClassAnnotation) - beta := metav1.HasAnnotation(claim.ObjectMeta, storageutil.BetaStorageClassAnnotation) - if alpha && beta { - // Both Alpha and Beta annotations are set. Do beta. + alpha := metav1.HasAnnotation(claim.ObjectMeta, v1.AlphaStorageClassAnnotation) + if alpha && v1.PersistentVolumeClaimHasClass(claim) { + // Both Alpha annotation and storage class name is set. Use the storage + // class name. alpha = false - msg := fmt.Sprintf("both %q and %q annotations are present, using %q", storageutil.AlphaStorageClassAnnotation, storageutil.BetaStorageClassAnnotation, storageutil.BetaStorageClassAnnotation) + msg := fmt.Sprintf("both %q annotation and storageClassName are present, using storageClassName", v1.AlphaStorageClassAnnotation) ctrl.eventRecorder.Event(claim, v1.EventTypeNormal, "ProvisioningIgnoreAlpha", msg) } if alpha { @@ -1454,7 +1453,7 @@ func (ctrl *PersistentVolumeController) findProvisionablePlugin(claim *v1.Persis // provisionClaim() which leads here is never called with claimClass=="", we // can save some checks. - claimClass := storageutil.GetClaimStorageClass(claim) + claimClass := v1.GetPersistentVolumeClaimClass(claim) class, err := ctrl.classLister.Get(claimClass) if err != nil { return nil, nil, err diff --git a/pkg/printers/internalversion/describe.go b/pkg/printers/internalversion/describe.go index 4baec3c7cb1..30d68d3f2da 100644 --- a/pkg/printers/internalversion/describe.go +++ b/pkg/printers/internalversion/describe.go @@ -812,7 +812,7 @@ func (d *PersistentVolumeDescriber) Describe(namespace, name string, describerSe w.Write(LEVEL_0, "Name:\t%s\n", pv.Name) printLabelsMultiline(w, "Labels", pv.Labels) printAnnotationsMultiline(w, "Annotations", pv.Annotations) - w.Write(LEVEL_0, "StorageClass:\t%s\n", storageutil.GetStorageClassAnnotation(pv.ObjectMeta)) + w.Write(LEVEL_0, "StorageClass:\t%s\n", api.GetPersistentVolumeClass(pv)) w.Write(LEVEL_0, "Status:\t%s\n", pv.Status.Phase) if pv.Spec.ClaimRef != nil { w.Write(LEVEL_0, "Claim:\t%s\n", pv.Spec.ClaimRef.Namespace+"/"+pv.Spec.ClaimRef.Name) @@ -889,7 +889,7 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri w := &PrefixWriter{out} w.Write(LEVEL_0, "Name:\t%s\n", pvc.Name) w.Write(LEVEL_0, "Namespace:\t%s\n", pvc.Namespace) - w.Write(LEVEL_0, "StorageClass:\t%s\n", storageutil.GetStorageClassAnnotation(pvc.ObjectMeta)) + w.Write(LEVEL_0, "StorageClass:\t%s\n", api.GetPersistentVolumeClaimClass(pvc)) w.Write(LEVEL_0, "Status:\t%v\n", pvc.Status.Phase) w.Write(LEVEL_0, "Volume:\t%s\n", pvc.Spec.VolumeName) printLabelsMultiline(w, "Labels", pvc.Labels) diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index a4c88f4a3e8..0c264d71fdb 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -1179,7 +1179,7 @@ func printPersistentVolume(pv *api.PersistentVolume, w io.Writer, options printe aSize, modesStr, reclaimPolicyStr, pv.Status.Phase, claimRefUID, - storageutil.GetStorageClassAnnotation(pv.ObjectMeta), + api.GetPersistentVolumeClass(pv), pv.Status.Reason, translateTimestamp(pv.CreationTimestamp), ); err != nil { @@ -1222,7 +1222,7 @@ func printPersistentVolumeClaim(pvc *api.PersistentVolumeClaim, w io.Writer, opt capacity = storage.String() } - if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s", name, phase, pvc.Spec.VolumeName, capacity, accessModes, storageutil.GetStorageClassAnnotation(pvc.ObjectMeta), translateTimestamp(pvc.CreationTimestamp)); err != nil { + if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s", name, phase, pvc.Spec.VolumeName, capacity, accessModes, api.GetPersistentVolumeClaimClass(pvc), translateTimestamp(pvc.CreationTimestamp)); err != nil { return err } if _, err := fmt.Fprint(w, AppendLabels(pvc.Labels, options.ColumnLabels)); err != nil { diff --git a/pkg/quota/evaluator/core/persistent_volume_claims.go b/pkg/quota/evaluator/core/persistent_volume_claims.go index 0cae054d8d0..09ebb79c3ef 100644 --- a/pkg/quota/evaluator/core/persistent_volume_claims.go +++ b/pkg/quota/evaluator/core/persistent_volume_claims.go @@ -28,7 +28,6 @@ import ( "k8s.io/apiserver/pkg/admission" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" - "k8s.io/kubernetes/pkg/apis/storage/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions" "k8s.io/kubernetes/pkg/quota" @@ -105,7 +104,7 @@ func (p *pvcEvaluator) Constraints(required []api.ResourceName, item runtime.Obj // these are the items that we will be handling based on the objects actual storage-class pvcRequiredSet := append([]api.ResourceName{}, pvcResources...) - if storageClassRef := util.GetClaimStorageClass(pvc); len(storageClassRef) > 0 { + if storageClassRef := api.GetPersistentVolumeClaimClass(pvc); len(storageClassRef) > 0 { pvcRequiredSet = append(pvcRequiredSet, ResourceByStorageClass(storageClassRef, api.ResourcePersistentVolumeClaims)) pvcRequiredSet = append(pvcRequiredSet, ResourceByStorageClass(storageClassRef, api.ResourceRequestsStorage)) } @@ -176,7 +175,7 @@ func (p *pvcEvaluator) Usage(item runtime.Object) (api.ResourceList, error) { if err != nil { return result, err } - storageClassRef := util.GetClaimStorageClass(pvc) + storageClassRef := api.GetPersistentVolumeClaimClass(pvc) // charge for claim result[api.ResourcePersistentVolumeClaims] = resource.MustParse("1") diff --git a/pkg/quota/evaluator/core/persistent_volume_claims_test.go b/pkg/quota/evaluator/core/persistent_volume_claims_test.go index 9384c19a84b..dbe336d2c77 100644 --- a/pkg/quota/evaluator/core/persistent_volume_claims_test.go +++ b/pkg/quota/evaluator/core/persistent_volume_claims_test.go @@ -22,7 +22,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/api" - "k8s.io/kubernetes/pkg/apis/storage/util" + "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/fake" "k8s.io/kubernetes/pkg/quota" ) @@ -74,7 +74,7 @@ func TestPersistentVolumeClaimsConstraintsFunc(t *testing.T) { }, }) validClaimGoldStorageClass.Annotations = map[string]string{ - util.StorageClassAnnotation: "gold", + v1.BetaStorageClassAnnotation: "gold", } validClaimBronzeStorageClass := testVolumeClaim("foo", "ns", api.PersistentVolumeClaimSpec{ @@ -97,7 +97,7 @@ func TestPersistentVolumeClaimsConstraintsFunc(t *testing.T) { }, }) validClaimBronzeStorageClass.Annotations = map[string]string{ - util.StorageClassAnnotation: "bronze", + v1.BetaStorageClassAnnotation: "bronze", } missingStorage := testVolumeClaim("foo", "ns", api.PersistentVolumeClaimSpec{ @@ -136,7 +136,7 @@ func TestPersistentVolumeClaimsConstraintsFunc(t *testing.T) { }, }) missingGoldStorage.Annotations = map[string]string{ - util.StorageClassAnnotation: "gold", + v1.BetaStorageClassAnnotation: "gold", } testCases := map[string]struct { @@ -240,7 +240,7 @@ func TestPersistentVolumeClaimEvaluatorUsage(t *testing.T) { }) storageClassName := "gold" validClaimByStorageClass.Annotations = map[string]string{ - util.StorageClassAnnotation: storageClassName, + v1.BetaStorageClassAnnotation: storageClassName, } kubeClient := fake.NewSimpleClientset() diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 13ba0cda932..78c9c09dea2 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -35,7 +35,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/api/v1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" "k8s.io/kubernetes/pkg/util/exec" "k8s.io/kubernetes/pkg/util/mount" @@ -471,7 +470,7 @@ func (p *glusterfsPlugin) collectGids(className string, gidTable *MinMaxAllocato } for _, pv := range pvList.Items { - if storageutil.GetVolumeStorageClass(&pv) != className { + if v1.GetPersistentVolumeClass(&pv) != className { continue } @@ -650,7 +649,7 @@ func (r *glusterfsVolumeProvisioner) Provision() (*v1.PersistentVolume, error) { return nil, fmt.Errorf("glusterfs: not able to parse your claim Selector") } glog.V(4).Infof("glusterfs: Provison VolumeOptions %v", r.options) - scName := storageutil.GetClaimStorageClass(r.options.PVC) + scName := v1.GetPersistentVolumeClaimClass(r.options.PVC) cfg, err := parseClassParameters(r.options.Parameters, r.plugin.host.GetKubeClient()) if err != nil { return nil, err diff --git a/plugin/pkg/admission/storageclass/default/admission.go b/plugin/pkg/admission/storageclass/default/admission.go index 86662515ff7..3713e3e850b 100644 --- a/plugin/pkg/admission/storageclass/default/admission.go +++ b/plugin/pkg/admission/storageclass/default/admission.go @@ -96,7 +96,7 @@ func (c *claimDefaulterPlugin) Admit(a admission.Attributes) error { return nil } - if storageutil.HasStorageClassAnnotation(pvc.ObjectMeta) { + if api.PersistentVolumeClaimHasClass(pvc) { // The user asked for a class. return nil } @@ -116,7 +116,7 @@ func (c *claimDefaulterPlugin) Admit(a admission.Attributes) error { if pvc.ObjectMeta.Annotations == nil { pvc.ObjectMeta.Annotations = map[string]string{} } - pvc.Annotations[storageutil.StorageClassAnnotation] = def.Name + pvc.Annotations[api.BetaStorageClassAnnotation] = def.Name return nil } diff --git a/plugin/pkg/admission/storageclass/default/admission_test.go b/plugin/pkg/admission/storageclass/default/admission_test.go index 41d32eb3ffd..4c4e7789bf4 100644 --- a/plugin/pkg/admission/storageclass/default/admission_test.go +++ b/plugin/pkg/admission/storageclass/default/admission_test.go @@ -24,6 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apiserver/pkg/admission" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/apis/storage" storageutil "k8s.io/kubernetes/pkg/apis/storage/util" informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion" @@ -100,7 +101,7 @@ func TestAdmission(t *testing.T) { Name: "claimWithClass", Namespace: "ns", Annotations: map[string]string{ - storageutil.StorageClassAnnotation: "foo", + v1.BetaStorageClassAnnotation: "foo", }, }, } @@ -112,7 +113,7 @@ func TestAdmission(t *testing.T) { Name: "claimWithEmptyClass", Namespace: "ns", Annotations: map[string]string{ - storageutil.StorageClassAnnotation: "", + v1.BetaStorageClassAnnotation: "", }, }, } @@ -222,7 +223,7 @@ func TestAdmission(t *testing.T) { class := "" if claim.Annotations != nil { - if value, ok := claim.Annotations[storageutil.StorageClassAnnotation]; ok { + if value, ok := claim.Annotations[v1.BetaStorageClassAnnotation]; ok { class = value } } diff --git a/test/e2e/resource_quota.go b/test/e2e/resource_quota.go index 3b612691a87..febfcfbd64c 100644 --- a/test/e2e/resource_quota.go +++ b/test/e2e/resource_quota.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/kubernetes/pkg/api/v1" - "k8s.io/kubernetes/pkg/apis/storage/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" "k8s.io/kubernetes/pkg/quota/evaluator/core" "k8s.io/kubernetes/test/e2e/framework" @@ -340,7 +339,7 @@ var _ = framework.KubeDescribe("ResourceQuota", func() { By("Creating a PersistentVolumeClaim with storage class") pvc := newTestPersistentVolumeClaimForQuota("test-claim") pvc.Annotations = map[string]string{ - util.StorageClassAnnotation: "gold", + v1.BetaStorageClassAnnotation: "gold", } pvc, err = f.ClientSet.Core().PersistentVolumeClaims(f.Namespace.Name).Create(pvc) Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/volume_provisioning.go b/test/e2e/volume_provisioning.go index 84f249aff23..563d846b056 100644 --- a/test/e2e/volume_provisioning.go +++ b/test/e2e/volume_provisioning.go @@ -27,7 +27,6 @@ import ( "k8s.io/kubernetes/pkg/api/v1" rbacv1beta1 "k8s.io/kubernetes/pkg/apis/rbac/v1beta1" storage "k8s.io/kubernetes/pkg/apis/storage/v1beta1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" "k8s.io/kubernetes/test/e2e/framework" @@ -263,11 +262,11 @@ func newClaim(ns, suffix string, alpha bool) *v1.PersistentVolumeClaim { if alpha { claim.Annotations = map[string]string{ - storageutil.AlphaStorageClassAnnotation: "", + v1.AlphaStorageClassAnnotation: "", } } else { claim.Annotations = map[string]string{ - storageutil.StorageClassAnnotation: "myclass-" + suffix, + v1.BetaStorageClassAnnotation: "myclass-" + suffix, } } diff --git a/test/integration/storageclasses/storage_classes_test.go b/test/integration/storageclasses/storage_classes_test.go index cedf12c72cd..7c4aef46fdf 100644 --- a/test/integration/storageclasses/storage_classes_test.go +++ b/test/integration/storageclasses/storage_classes_test.go @@ -29,7 +29,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" storage "k8s.io/kubernetes/pkg/apis/storage/v1beta1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" "k8s.io/kubernetes/test/integration/framework" ) @@ -73,7 +72,7 @@ func DoTestStorageClasses(t *testing.T, client clientset.Interface, ns *v1.Names Name: "XXX", Namespace: ns.Name, Annotations: map[string]string{ - storageutil.StorageClassAnnotation: "gold", + v1.BetaStorageClassAnnotation: "gold", }, }, Spec: v1.PersistentVolumeClaimSpec{ diff --git a/test/integration/volume/persistent_volumes_test.go b/test/integration/volume/persistent_volumes_test.go index e271e7dd27a..ccb005e4eb2 100644 --- a/test/integration/volume/persistent_volumes_test.go +++ b/test/integration/volume/persistent_volumes_test.go @@ -34,7 +34,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" storage "k8s.io/kubernetes/pkg/apis/storage/v1beta1" - storageutil "k8s.io/kubernetes/pkg/apis/storage/v1beta1/util" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions" fakecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/fake" @@ -889,7 +888,7 @@ func TestPersistentVolumeProvisionMultiPVCs(t *testing.T) { for i := 0; i < objCount; i++ { pvc := createPVC("pvc-provision-"+strconv.Itoa(i), ns.Name, "1G", []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}) pvc.Annotations = map[string]string{ - storageutil.StorageClassAnnotation: "gold", + v1.BetaStorageClassAnnotation: "gold", } pvcs[i] = pvc }