mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
pvc storage request warning for fractional byte value
- create or update
This commit is contained in:
parent
f3ae27f5ef
commit
0b848bee4e
@ -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
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func (persistentvolumeclaimStrategy) Validate(ctx context.Context, obj runtime.O
|
||||
|
||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||
func (persistentvolumeclaimStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||
return nil
|
||||
return pvcutil.GetWarningsForPersistentVolumeClaim(obj.(*api.PersistentVolumeClaim))
|
||||
}
|
||||
|
||||
// Canonicalize normalizes the object after validation.
|
||||
@ -128,7 +128,7 @@ func (persistentvolumeclaimStrategy) ValidateUpdate(ctx context.Context, obj, ol
|
||||
|
||||
// WarningsOnUpdate returns warnings for the given update.
|
||||
func (persistentvolumeclaimStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||
return nil
|
||||
return pvcutil.GetWarningsForPersistentVolumeClaim(obj.(*api.PersistentVolumeClaim))
|
||||
}
|
||||
|
||||
func (persistentvolumeclaimStrategy) AllowUnconditionalUpdate() bool {
|
||||
|
Loading…
Reference in New Issue
Block a user