pvc storage request warning for fractional byte value

- create or update
This commit is contained in:
Paco Xu
2022-10-21 13:31:43 +08:00
parent f3ae27f5ef
commit 0b848bee4e
2 changed files with 22 additions and 2 deletions

View File

@@ -17,6 +17,10 @@ limitations under the License.
package persistentvolumeclaim
import (
"fmt"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/validation/field"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/features"
@@ -151,3 +155,19 @@ func allocatedResourcesInUse(oldPVC *core.PersistentVolumeClaim) bool {
return false
}
func GetWarningsForPersistentVolumeClaim(pv *core.PersistentVolumeClaim) []string {
if pv == nil {
return nil
}
storageValue := pv.Spec.Resources.Requests[core.ResourceStorage]
return warningsForPersistentVolumeClaimResources(field.NewPath("spec").Child("Resources").Child("Requests").Key(core.ResourceStorage.String()), storageValue)
}
func warningsForPersistentVolumeClaimResources(fieldPath *field.Path, storageValue resource.Quantity) []string {
var warnings []string
if storageValue.MilliValue()%int64(1000) != int64(0) {
warnings = append(warnings, fmt.Sprintf("%s: fractional byte value %q is invalid, must be an integer", fieldPath.String(), storageValue.String()))
}
return warnings
}