emit warning on deprecated annotation volume.beta.kubernetes.io/storage-class

This commit is contained in:
Hao Ruan
2023-03-31 17:33:41 +08:00
parent c3e7eca7fd
commit 19ae103e82
4 changed files with 56 additions and 5 deletions

View File

@@ -26,8 +26,9 @@ import (
)
const (
pvc string = "PersistentVolumeClaim"
volumeSnapshot string = "VolumeSnapshot"
pvc string = "PersistentVolumeClaim"
volumeSnapshot string = "VolumeSnapshot"
deprecatedStorageClassAnnotationsMsg = `deprecated since v1.8; use "storageClassName" attribute instead`
)
// DropDisabledFields removes disabled fields from the pvc spec.
@@ -197,11 +198,25 @@ func allocatedResourcesInUse(oldPVC *core.PersistentVolumeClaim) bool {
}
func GetWarningsForPersistentVolumeClaim(pv *core.PersistentVolumeClaim) []string {
var warnings []string
if pv == nil {
return nil
}
return GetWarningsForPersistentVolumeClaimSpec(field.NewPath("spec"), pv.Spec)
if _, ok := pv.ObjectMeta.Annotations[core.BetaStorageClassAnnotation]; ok {
warnings = append(warnings,
fmt.Sprintf(
"%s: %s",
field.NewPath("metadata", "annotations").Key(core.BetaStorageClassAnnotation),
deprecatedStorageClassAnnotationsMsg,
),
)
}
warnings = append(warnings, GetWarningsForPersistentVolumeClaimSpec(field.NewPath("spec"), pv.Spec)...)
return warnings
}
func GetWarningsForPersistentVolumeClaimSpec(fieldPath *field.Path, pvSpec core.PersistentVolumeClaimSpec) []string {