From 13fd8d8058223eab863e1735a524f2879a8bd39c Mon Sep 17 00:00:00 2001 From: carlory Date: Sat, 11 May 2024 18:04:33 +0800 Subject: [PATCH] mark volume.beta.kubernetes.io/mount-options as deprecated --- pkg/api/persistentvolume/util.go | 31 ++++++++++++++++----------- pkg/api/persistentvolume/util_test.go | 2 ++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pkg/api/persistentvolume/util.go b/pkg/api/persistentvolume/util.go index bf703f7aa69..00e161c9f60 100644 --- a/pkg/api/persistentvolume/util.go +++ b/pkg/api/persistentvolume/util.go @@ -27,10 +27,6 @@ import ( "k8s.io/kubernetes/pkg/features" ) -const ( - deprecatedStorageClassAnnotationsMsg = `deprecated since v1.8; use "storageClassName" attribute instead` -) - // DropDisabledSpecFields removes disabled fields from the pv spec. // This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec. func DropDisabledSpecFields(pvSpec *api.PersistentVolumeSpec, oldPVSpec *api.PersistentVolumeSpec) { @@ -56,17 +52,28 @@ func GetWarningsForPersistentVolume(pv *api.PersistentVolume) []string { return warningsForPersistentVolumeSpecAndMeta(nil, &pv.Spec, &pv.ObjectMeta) } +var deprecatedAnnotations = []struct { + key string + message string +}{ + { + key: `volume.beta.kubernetes.io/storage-class`, + message: `deprecated since v1.8; use "storageClassName" attribute instead`, + }, + { + key: `volume.beta.kubernetes.io/mount-options`, + message: `deprecated since v1.31; use "mountOptions" attribute instead`, + }, +} + func warningsForPersistentVolumeSpecAndMeta(fieldPath *field.Path, pvSpec *api.PersistentVolumeSpec, pvMeta *metav1.ObjectMeta) []string { var warnings []string - if _, ok := pvMeta.Annotations[api.BetaStorageClassAnnotation]; ok { - warnings = append(warnings, - fmt.Sprintf( - "%s: %s", - fieldPath.Child("metadata", "annotations").Key(api.BetaStorageClassAnnotation), - deprecatedStorageClassAnnotationsMsg, - ), - ) + // use of deprecated annotations + for _, deprecated := range deprecatedAnnotations { + if _, exists := pvMeta.Annotations[deprecated.key]; exists { + warnings = append(warnings, fmt.Sprintf("%s: %s", fieldPath.Child("metadata", "annotations").Key(deprecated.key), deprecated.message)) + } } if pvSpec.PersistentVolumeReclaimPolicy == api.PersistentVolumeReclaimRecycle { diff --git a/pkg/api/persistentvolume/util_test.go b/pkg/api/persistentvolume/util_test.go index 9ac3c18ecce..c0e410cb0e3 100644 --- a/pkg/api/persistentvolume/util_test.go +++ b/pkg/api/persistentvolume/util_test.go @@ -146,6 +146,7 @@ func TestWarnings(t *testing.T) { Name: "foo", Annotations: map[string]string{ api.BetaStorageClassAnnotation: "", + api.MountOptionAnnotation: "", }, }, Spec: api.PersistentVolumeSpec{ @@ -171,6 +172,7 @@ func TestWarnings(t *testing.T) { }, expected: []string{ `metadata.annotations[volume.beta.kubernetes.io/storage-class]: deprecated since v1.8; use "storageClassName" attribute instead`, + `metadata.annotations[volume.beta.kubernetes.io/mount-options]: deprecated since v1.31; use "mountOptions" attribute instead`, `spec.nodeAffinity.required.nodeSelectorTerms[0].matchExpressions[0].key: beta.kubernetes.io/os is deprecated since v1.14; use "kubernetes.io/os" instead`, }, },