Merge pull request #124819 from carlory/add-warning-MountOptionAnnotation

mark volume.beta.kubernetes.io/mount-options as deprecated
This commit is contained in:
Kubernetes Prow Robot 2024-07-23 12:21:11 -07:00 committed by GitHub
commit 13d9d7c689
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 12 deletions

View File

@ -27,10 +27,6 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
) )
const (
deprecatedStorageClassAnnotationsMsg = `deprecated since v1.8; use "storageClassName" attribute instead`
)
// DropDisabledSpecFields removes disabled fields from the pv spec. // DropDisabledSpecFields removes disabled fields from the pv spec.
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec. // This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec.
func DropDisabledSpecFields(pvSpec *api.PersistentVolumeSpec, oldPVSpec *api.PersistentVolumeSpec) { func DropDisabledSpecFields(pvSpec *api.PersistentVolumeSpec, oldPVSpec *api.PersistentVolumeSpec) {
@ -48,17 +44,28 @@ func GetWarningsForPersistentVolume(pv *api.PersistentVolume) []string {
return warningsForPersistentVolumeSpecAndMeta(nil, &pv.Spec, &pv.ObjectMeta) 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 { func warningsForPersistentVolumeSpecAndMeta(fieldPath *field.Path, pvSpec *api.PersistentVolumeSpec, pvMeta *metav1.ObjectMeta) []string {
var warnings []string var warnings []string
if _, ok := pvMeta.Annotations[api.BetaStorageClassAnnotation]; ok { // use of deprecated annotations
warnings = append(warnings, for _, deprecated := range deprecatedAnnotations {
fmt.Sprintf( if _, exists := pvMeta.Annotations[deprecated.key]; exists {
"%s: %s", warnings = append(warnings, fmt.Sprintf("%s: %s", fieldPath.Child("metadata", "annotations").Key(deprecated.key), deprecated.message))
fieldPath.Child("metadata", "annotations").Key(api.BetaStorageClassAnnotation), }
deprecatedStorageClassAnnotationsMsg,
),
)
} }
if pvSpec.PersistentVolumeReclaimPolicy == api.PersistentVolumeReclaimRecycle { if pvSpec.PersistentVolumeReclaimPolicy == api.PersistentVolumeReclaimRecycle {

View File

@ -146,6 +146,7 @@ func TestWarnings(t *testing.T) {
Name: "foo", Name: "foo",
Annotations: map[string]string{ Annotations: map[string]string{
api.BetaStorageClassAnnotation: "", api.BetaStorageClassAnnotation: "",
api.MountOptionAnnotation: "",
}, },
}, },
Spec: api.PersistentVolumeSpec{ Spec: api.PersistentVolumeSpec{
@ -171,6 +172,7 @@ func TestWarnings(t *testing.T) {
}, },
expected: []string{ expected: []string{
`metadata.annotations[volume.beta.kubernetes.io/storage-class]: deprecated since v1.8; use "storageClassName" attribute instead`, `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`, `spec.nodeAffinity.required.nodeSelectorTerms[0].matchExpressions[0].key: beta.kubernetes.io/os is deprecated since v1.14; use "kubernetes.io/os" instead`,
}, },
}, },