Merge pull request #42128 from jsafrane/v1-2-combined

Automatic merge from submit-queue (batch tested with PRs 42128, 42064, 42253, 42309, 42322)

Add storage.k8s.io/v1 API

This is combined version of reverted #40088 (first 4 commits) and #41646. The difference is that all controllers and tests use old `storage.k8s.io/v1beta1` API so in theory all tests can pass on GKE.

Release note:
```release-note
StorageClassName attribute has been added to PersistentVolume and PersistentVolumeClaim objects and should be used instead of annotation `volume.beta.kubernetes.io/storage-class`. The beta annotation is still working in this release, however it will be removed in a future release.
```
This commit is contained in:
Kubernetes Submit Queue
2017-03-02 05:00:39 -08:00
committed by GitHub
123 changed files with 9604 additions and 721 deletions

View File

@@ -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
}
@@ -113,10 +113,7 @@ func (c *claimDefaulterPlugin) Admit(a admission.Attributes) error {
}
glog.V(4).Infof("defaulting storage class for claim %s (generate: %s) to %s", pvc.Name, pvc.GenerateName, def.Name)
if pvc.ObjectMeta.Annotations == nil {
pvc.ObjectMeta.Annotations = map[string]string{}
}
pvc.Annotations[storageutil.StorageClassAnnotation] = def.Name
pvc.Spec.StorageClassName = &def.Name
return nil
}

View File

@@ -31,6 +31,9 @@ import (
)
func TestAdmission(t *testing.T) {
empty := ""
foo := "foo"
defaultClass1 := &storage.StorageClass{
TypeMeta: metav1.TypeMeta{
Kind: "StorageClass",
@@ -99,9 +102,9 @@ func TestAdmission(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "claimWithClass",
Namespace: "ns",
Annotations: map[string]string{
storageutil.StorageClassAnnotation: "foo",
},
},
Spec: api.PersistentVolumeClaimSpec{
StorageClassName: &foo,
},
}
claimWithEmptyClass := &api.PersistentVolumeClaim{
@@ -111,9 +114,9 @@ func TestAdmission(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "claimWithEmptyClass",
Namespace: "ns",
Annotations: map[string]string{
storageutil.StorageClassAnnotation: "",
},
},
Spec: api.PersistentVolumeClaimSpec{
StorageClassName: &empty,
},
}
claimWithNoClass := &api.PersistentVolumeClaim{
@@ -221,10 +224,8 @@ func TestAdmission(t *testing.T) {
}
class := ""
if claim.Annotations != nil {
if value, ok := claim.Annotations[storageutil.StorageClassAnnotation]; ok {
class = value
}
if claim.Spec.StorageClassName != nil {
class = *claim.Spec.StorageClassName
}
if test.expectedClassName != "" && test.expectedClassName != class {
t.Errorf("Test %q: expected class name %q, got %q", test.name, test.expectedClassName, class)