mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
admission controller: use attributes instead beta annotations
This commit is contained in:
parent
94e78eabc0
commit
ca7cdc8c96
@ -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)
|
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.Spec.StorageClassName = &def.Name
|
||||||
pvc.ObjectMeta.Annotations = map[string]string{}
|
|
||||||
}
|
|
||||||
pvc.Annotations[api.BetaStorageClassAnnotation] = def.Name
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apiserver/pkg/admission"
|
"k8s.io/apiserver/pkg/admission"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
|
||||||
"k8s.io/kubernetes/pkg/apis/storage"
|
"k8s.io/kubernetes/pkg/apis/storage"
|
||||||
storageutil "k8s.io/kubernetes/pkg/apis/storage/util"
|
storageutil "k8s.io/kubernetes/pkg/apis/storage/util"
|
||||||
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
|
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
|
||||||
@ -32,6 +31,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAdmission(t *testing.T) {
|
func TestAdmission(t *testing.T) {
|
||||||
|
empty := ""
|
||||||
|
foo := "foo"
|
||||||
|
|
||||||
defaultClass1 := &storage.StorageClass{
|
defaultClass1 := &storage.StorageClass{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
Kind: "StorageClass",
|
Kind: "StorageClass",
|
||||||
@ -100,9 +102,9 @@ func TestAdmission(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "claimWithClass",
|
Name: "claimWithClass",
|
||||||
Namespace: "ns",
|
Namespace: "ns",
|
||||||
Annotations: map[string]string{
|
},
|
||||||
v1.BetaStorageClassAnnotation: "foo",
|
Spec: api.PersistentVolumeClaimSpec{
|
||||||
},
|
StorageClassName: &foo,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
claimWithEmptyClass := &api.PersistentVolumeClaim{
|
claimWithEmptyClass := &api.PersistentVolumeClaim{
|
||||||
@ -112,9 +114,9 @@ func TestAdmission(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "claimWithEmptyClass",
|
Name: "claimWithEmptyClass",
|
||||||
Namespace: "ns",
|
Namespace: "ns",
|
||||||
Annotations: map[string]string{
|
},
|
||||||
v1.BetaStorageClassAnnotation: "",
|
Spec: api.PersistentVolumeClaimSpec{
|
||||||
},
|
StorageClassName: &empty,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
claimWithNoClass := &api.PersistentVolumeClaim{
|
claimWithNoClass := &api.PersistentVolumeClaim{
|
||||||
@ -222,10 +224,8 @@ func TestAdmission(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class := ""
|
class := ""
|
||||||
if claim.Annotations != nil {
|
if claim.Spec.StorageClassName != nil {
|
||||||
if value, ok := claim.Annotations[v1.BetaStorageClassAnnotation]; ok {
|
class = *claim.Spec.StorageClassName
|
||||||
class = value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if test.expectedClassName != "" && test.expectedClassName != class {
|
if test.expectedClassName != "" && test.expectedClassName != class {
|
||||||
t.Errorf("Test %q: expected class name %q, got %q", test.name, test.expectedClassName, class)
|
t.Errorf("Test %q: expected class name %q, got %q", test.name, test.expectedClassName, class)
|
||||||
|
Loading…
Reference in New Issue
Block a user