|
|
|
@@ -23,8 +23,9 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
lru "github.com/hashicorp/golang-lru"
|
|
|
|
|
"github.com/hashicorp/golang-lru"
|
|
|
|
|
|
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
|
"k8s.io/apimachinery/pkg/api/meta"
|
|
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
@@ -32,11 +33,11 @@ import (
|
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
|
|
|
|
"k8s.io/apiserver/pkg/admission"
|
|
|
|
|
genericadmissioninitailizer "k8s.io/apiserver/pkg/admission/initializer"
|
|
|
|
|
"k8s.io/client-go/informers"
|
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
|
corev1listers "k8s.io/client-go/listers/core/v1"
|
|
|
|
|
api "k8s.io/kubernetes/pkg/apis/core"
|
|
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
|
|
|
|
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
|
|
|
|
|
corelisters "k8s.io/kubernetes/pkg/client/listers/core/internalversion"
|
|
|
|
|
kubeapiserveradmission "k8s.io/kubernetes/pkg/kubeapiserver/admission"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
@@ -55,9 +56,9 @@ func Register(plugins *admission.Plugins) {
|
|
|
|
|
// LimitRanger enforces usage limits on a per resource basis in the namespace
|
|
|
|
|
type LimitRanger struct {
|
|
|
|
|
*admission.Handler
|
|
|
|
|
client internalclientset.Interface
|
|
|
|
|
client kubernetes.Interface
|
|
|
|
|
actions LimitRangerActions
|
|
|
|
|
lister corelisters.LimitRangeLister
|
|
|
|
|
lister corev1listers.LimitRangeLister
|
|
|
|
|
|
|
|
|
|
// liveLookups holds the last few live lookups we've done to help ammortize cost on repeated lookup failures.
|
|
|
|
|
// This let's us handle the case of latent caches, by looking up actual results for a namespace on cache miss/no results.
|
|
|
|
@@ -68,19 +69,25 @@ type LimitRanger struct {
|
|
|
|
|
|
|
|
|
|
var _ admission.MutationInterface = &LimitRanger{}
|
|
|
|
|
var _ admission.ValidationInterface = &LimitRanger{}
|
|
|
|
|
var _ kubeapiserveradmission.WantsInternalKubeInformerFactory = &LimitRanger{}
|
|
|
|
|
|
|
|
|
|
var _ genericadmissioninitailizer.WantsExternalKubeInformerFactory = &LimitRanger{}
|
|
|
|
|
var _ genericadmissioninitailizer.WantsExternalKubeClientSet = &LimitRanger{}
|
|
|
|
|
|
|
|
|
|
type liveLookupEntry struct {
|
|
|
|
|
expiry time.Time
|
|
|
|
|
items []*api.LimitRange
|
|
|
|
|
items []*corev1.LimitRange
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *LimitRanger) SetInternalKubeInformerFactory(f informers.SharedInformerFactory) {
|
|
|
|
|
limitRangeInformer := f.Core().InternalVersion().LimitRanges()
|
|
|
|
|
func (l *LimitRanger) SetExternalKubeInformerFactory(f informers.SharedInformerFactory) {
|
|
|
|
|
limitRangeInformer := f.Core().V1().LimitRanges()
|
|
|
|
|
l.SetReadyFunc(limitRangeInformer.Informer().HasSynced)
|
|
|
|
|
l.lister = limitRangeInformer.Lister()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *LimitRanger) SetExternalKubeClientSet(client kubernetes.Interface) {
|
|
|
|
|
a.client = client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *LimitRanger) ValidateInitialization() error {
|
|
|
|
|
if l.lister == nil {
|
|
|
|
|
return fmt.Errorf("missing limitRange lister")
|
|
|
|
@@ -101,20 +108,11 @@ func (l *LimitRanger) Validate(a admission.Attributes) (err error) {
|
|
|
|
|
return l.runLimitFunc(a, l.actions.ValidateLimit)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *LimitRanger) runLimitFunc(a admission.Attributes, limitFn func(limitRange *api.LimitRange, kind string, obj runtime.Object) error) (err error) {
|
|
|
|
|
func (l *LimitRanger) runLimitFunc(a admission.Attributes, limitFn func(limitRange *corev1.LimitRange, kind string, obj runtime.Object) error) (err error) {
|
|
|
|
|
if !l.actions.SupportsAttributes(a) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obj := a.GetObject()
|
|
|
|
|
name := "Unknown"
|
|
|
|
|
if obj != nil {
|
|
|
|
|
name, _ = meta.NewAccessor().Name(obj)
|
|
|
|
|
if len(name) == 0 {
|
|
|
|
|
name, _ = meta.NewAccessor().GenerateName(obj)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ignore all objects marked for deletion
|
|
|
|
|
oldObj := a.GetOldObject()
|
|
|
|
|
if oldObj != nil {
|
|
|
|
@@ -148,7 +146,7 @@ func (l *LimitRanger) runLimitFunc(a admission.Attributes, limitFn func(limitRan
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *LimitRanger) GetLimitRanges(a admission.Attributes) ([]*api.LimitRange, error) {
|
|
|
|
|
func (l *LimitRanger) GetLimitRanges(a admission.Attributes) ([]*corev1.LimitRange, error) {
|
|
|
|
|
items, err := l.lister.LimitRanges(a.GetNamespace()).List(labels.Everything())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, admission.NewForbidden(a, fmt.Errorf("unable to %s %v at this time because there was an error enforcing limit ranges", a.GetOperation(), a.GetResource()))
|
|
|
|
@@ -163,7 +161,7 @@ func (l *LimitRanger) GetLimitRanges(a admission.Attributes) ([]*api.LimitRange,
|
|
|
|
|
// If there is already in-flight List() for a given namespace, we should wait until
|
|
|
|
|
// it is finished and cache is updated instead of doing the same, also to avoid
|
|
|
|
|
// throttling - see #22422 for details.
|
|
|
|
|
liveList, err := l.client.Core().LimitRanges(a.GetNamespace()).List(metav1.ListOptions{})
|
|
|
|
|
liveList, err := l.client.CoreV1().LimitRanges(a.GetNamespace()).List(metav1.ListOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, admission.NewForbidden(a, err)
|
|
|
|
|
}
|
|
|
|
@@ -204,31 +202,24 @@ func NewLimitRanger(actions LimitRangerActions) (*LimitRanger, error) {
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ = kubeapiserveradmission.WantsInternalKubeInformerFactory(&LimitRanger{})
|
|
|
|
|
var _ = kubeapiserveradmission.WantsInternalKubeClientSet(&LimitRanger{})
|
|
|
|
|
|
|
|
|
|
func (a *LimitRanger) SetInternalKubeClientSet(client internalclientset.Interface) {
|
|
|
|
|
a.client = client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// defaultContainerResourceRequirements returns the default requirements for a container
|
|
|
|
|
// the requirement.Limits are taken from the LimitRange defaults (if specified)
|
|
|
|
|
// the requirement.Requests are taken from the LimitRange default request (if specified)
|
|
|
|
|
func defaultContainerResourceRequirements(limitRange *api.LimitRange) api.ResourceRequirements {
|
|
|
|
|
func defaultContainerResourceRequirements(limitRange *corev1.LimitRange) api.ResourceRequirements {
|
|
|
|
|
requirements := api.ResourceRequirements{}
|
|
|
|
|
requirements.Requests = api.ResourceList{}
|
|
|
|
|
requirements.Limits = api.ResourceList{}
|
|
|
|
|
|
|
|
|
|
for i := range limitRange.Spec.Limits {
|
|
|
|
|
limit := limitRange.Spec.Limits[i]
|
|
|
|
|
if limit.Type == api.LimitTypeContainer {
|
|
|
|
|
if limit.Type == corev1.LimitTypeContainer {
|
|
|
|
|
for k, v := range limit.DefaultRequest {
|
|
|
|
|
value := v.Copy()
|
|
|
|
|
requirements.Requests[k] = *value
|
|
|
|
|
requirements.Requests[api.ResourceName(k)] = *value
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.Default {
|
|
|
|
|
value := v.Copy()
|
|
|
|
|
requirements.Limits[k] = *value
|
|
|
|
|
requirements.Limits[api.ResourceName(k)] = *value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -309,9 +300,9 @@ func requestLimitEnforcedValues(requestQuantity, limitQuantity, enforcedQuantity
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// minConstraint enforces the min constraint over the specified resource
|
|
|
|
|
func minConstraint(limitType api.LimitType, resourceName api.ResourceName, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[resourceName]
|
|
|
|
|
lim, limExists := limit[resourceName]
|
|
|
|
|
func minConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[api.ResourceName(resourceName)]
|
|
|
|
|
lim, limExists := limit[api.ResourceName(resourceName)]
|
|
|
|
|
observedReqValue, observedLimValue, enforcedValue := requestLimitEnforcedValues(req, lim, enforced)
|
|
|
|
|
|
|
|
|
|
if !reqExists {
|
|
|
|
@@ -328,8 +319,8 @@ func minConstraint(limitType api.LimitType, resourceName api.ResourceName, enfor
|
|
|
|
|
|
|
|
|
|
// maxRequestConstraint enforces the max constraint over the specified resource
|
|
|
|
|
// use when specify LimitType resource doesn't recognize limit values
|
|
|
|
|
func maxRequestConstraint(limitType api.LimitType, resourceName api.ResourceName, enforced resource.Quantity, request api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[resourceName]
|
|
|
|
|
func maxRequestConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[api.ResourceName(resourceName)]
|
|
|
|
|
observedReqValue, _, enforcedValue := requestLimitEnforcedValues(req, resource.Quantity{}, enforced)
|
|
|
|
|
|
|
|
|
|
if !reqExists {
|
|
|
|
@@ -342,9 +333,9 @@ func maxRequestConstraint(limitType api.LimitType, resourceName api.ResourceName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// maxConstraint enforces the max constraint over the specified resource
|
|
|
|
|
func maxConstraint(limitType api.LimitType, resourceName api.ResourceName, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[resourceName]
|
|
|
|
|
lim, limExists := limit[resourceName]
|
|
|
|
|
func maxConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[api.ResourceName(resourceName)]
|
|
|
|
|
lim, limExists := limit[api.ResourceName(resourceName)]
|
|
|
|
|
observedReqValue, observedLimValue, enforcedValue := requestLimitEnforcedValues(req, lim, enforced)
|
|
|
|
|
|
|
|
|
|
if !limExists {
|
|
|
|
@@ -360,9 +351,9 @@ func maxConstraint(limitType api.LimitType, resourceName api.ResourceName, enfor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// limitRequestRatioConstraint enforces the limit to request ratio over the specified resource
|
|
|
|
|
func limitRequestRatioConstraint(limitType api.LimitType, resourceName api.ResourceName, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[resourceName]
|
|
|
|
|
lim, limExists := limit[resourceName]
|
|
|
|
|
func limitRequestRatioConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
|
|
|
|
|
req, reqExists := request[api.ResourceName(resourceName)]
|
|
|
|
|
lim, limExists := limit[api.ResourceName(resourceName)]
|
|
|
|
|
observedReqValue, observedLimValue, _ := requestLimitEnforcedValues(req, lim, enforced)
|
|
|
|
|
|
|
|
|
|
if !reqExists || (observedReqValue == int64(0)) {
|
|
|
|
@@ -435,7 +426,7 @@ var _ LimitRangerActions = &DefaultLimitRangerActions{}
|
|
|
|
|
// Limit enforces resource requirements of incoming resources against enumerated constraints
|
|
|
|
|
// on the LimitRange. It may modify the incoming object to apply default resource requirements
|
|
|
|
|
// if not specified, and enumerated on the LimitRange
|
|
|
|
|
func (d *DefaultLimitRangerActions) MutateLimit(limitRange *api.LimitRange, resourceName string, obj runtime.Object) error {
|
|
|
|
|
func (d *DefaultLimitRangerActions) MutateLimit(limitRange *corev1.LimitRange, resourceName string, obj runtime.Object) error {
|
|
|
|
|
switch resourceName {
|
|
|
|
|
case "pods":
|
|
|
|
|
return PodMutateLimitFunc(limitRange, obj.(*api.Pod))
|
|
|
|
@@ -446,7 +437,7 @@ func (d *DefaultLimitRangerActions) MutateLimit(limitRange *api.LimitRange, reso
|
|
|
|
|
// Limit enforces resource requirements of incoming resources against enumerated constraints
|
|
|
|
|
// on the LimitRange. It may modify the incoming object to apply default resource requirements
|
|
|
|
|
// if not specified, and enumerated on the LimitRange
|
|
|
|
|
func (d *DefaultLimitRangerActions) ValidateLimit(limitRange *api.LimitRange, resourceName string, obj runtime.Object) error {
|
|
|
|
|
func (d *DefaultLimitRangerActions) ValidateLimit(limitRange *corev1.LimitRange, resourceName string, obj runtime.Object) error {
|
|
|
|
|
switch resourceName {
|
|
|
|
|
case "pods":
|
|
|
|
|
return PodValidateLimitFunc(limitRange, obj.(*api.Pod))
|
|
|
|
@@ -467,7 +458,7 @@ func (d *DefaultLimitRangerActions) SupportsAttributes(a admission.Attributes) b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SupportsLimit always returns true.
|
|
|
|
|
func (d *DefaultLimitRangerActions) SupportsLimit(limitRange *api.LimitRange) bool {
|
|
|
|
|
func (d *DefaultLimitRangerActions) SupportsLimit(limitRange *corev1.LimitRange) bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -475,22 +466,22 @@ func (d *DefaultLimitRangerActions) SupportsLimit(limitRange *api.LimitRange) bo
|
|
|
|
|
// Users request storage via pvc.Spec.Resources.Requests. Min/Max is enforced by an admin with LimitRange.
|
|
|
|
|
// Claims will not be modified with default values because storage is a required part of pvc.Spec.
|
|
|
|
|
// All storage enforced values *only* apply to pvc.Spec.Resources.Requests.
|
|
|
|
|
func PersistentVolumeClaimValidateLimitFunc(limitRange *api.LimitRange, pvc *api.PersistentVolumeClaim) error {
|
|
|
|
|
func PersistentVolumeClaimValidateLimitFunc(limitRange *corev1.LimitRange, pvc *api.PersistentVolumeClaim) error {
|
|
|
|
|
var errs []error
|
|
|
|
|
for i := range limitRange.Spec.Limits {
|
|
|
|
|
limit := limitRange.Spec.Limits[i]
|
|
|
|
|
limitType := limit.Type
|
|
|
|
|
if limitType == api.LimitTypePersistentVolumeClaim {
|
|
|
|
|
if limitType == corev1.LimitTypePersistentVolumeClaim {
|
|
|
|
|
for k, v := range limit.Min {
|
|
|
|
|
// normal usage of minConstraint. pvc.Spec.Resources.Limits is not recognized as user input
|
|
|
|
|
if err := minConstraint(limitType, k, v, pvc.Spec.Resources.Requests, api.ResourceList{}); err != nil {
|
|
|
|
|
if err := minConstraint(string(limitType), string(k), v, pvc.Spec.Resources.Requests, api.ResourceList{}); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.Max {
|
|
|
|
|
// We want to enforce the max of the LimitRange against what
|
|
|
|
|
// the user requested.
|
|
|
|
|
if err := maxRequestConstraint(limitType, k, v, pvc.Spec.Resources.Requests); err != nil {
|
|
|
|
|
if err := maxRequestConstraint(string(limitType), string(k), v, pvc.Spec.Resources.Requests); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -502,7 +493,7 @@ func PersistentVolumeClaimValidateLimitFunc(limitRange *api.LimitRange, pvc *api
|
|
|
|
|
// PodMutateLimitFunc sets resource requirements enumerated by the pod against
|
|
|
|
|
// the specified LimitRange. The pod may be modified to apply default resource
|
|
|
|
|
// requirements if not specified, and enumerated on the LimitRange
|
|
|
|
|
func PodMutateLimitFunc(limitRange *api.LimitRange, pod *api.Pod) error {
|
|
|
|
|
func PodMutateLimitFunc(limitRange *corev1.LimitRange, pod *api.Pod) error {
|
|
|
|
|
defaultResources := defaultContainerResourceRequirements(limitRange)
|
|
|
|
|
mergePodResourceRequirements(pod, &defaultResources)
|
|
|
|
|
return nil
|
|
|
|
@@ -510,28 +501,28 @@ func PodMutateLimitFunc(limitRange *api.LimitRange, pod *api.Pod) error {
|
|
|
|
|
|
|
|
|
|
// PodValidateLimitFunc enforces resource requirements enumerated by the pod against
|
|
|
|
|
// the specified LimitRange.
|
|
|
|
|
func PodValidateLimitFunc(limitRange *api.LimitRange, pod *api.Pod) error {
|
|
|
|
|
func PodValidateLimitFunc(limitRange *corev1.LimitRange, pod *api.Pod) error {
|
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
|
|
for i := range limitRange.Spec.Limits {
|
|
|
|
|
limit := limitRange.Spec.Limits[i]
|
|
|
|
|
limitType := limit.Type
|
|
|
|
|
// enforce container limits
|
|
|
|
|
if limitType == api.LimitTypeContainer {
|
|
|
|
|
if limitType == corev1.LimitTypeContainer {
|
|
|
|
|
for j := range pod.Spec.Containers {
|
|
|
|
|
container := &pod.Spec.Containers[j]
|
|
|
|
|
for k, v := range limit.Min {
|
|
|
|
|
if err := minConstraint(limitType, k, v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
if err := minConstraint(string(limitType), string(k), v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.Max {
|
|
|
|
|
if err := maxConstraint(limitType, k, v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
if err := maxConstraint(string(limitType), string(k), v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.MaxLimitRequestRatio {
|
|
|
|
|
if err := limitRequestRatioConstraint(limitType, k, v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
if err := limitRequestRatioConstraint(string(limitType), string(k), v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -539,17 +530,17 @@ func PodValidateLimitFunc(limitRange *api.LimitRange, pod *api.Pod) error {
|
|
|
|
|
for j := range pod.Spec.InitContainers {
|
|
|
|
|
container := &pod.Spec.InitContainers[j]
|
|
|
|
|
for k, v := range limit.Min {
|
|
|
|
|
if err := minConstraint(limitType, k, v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
if err := minConstraint(string(limitType), string(k), v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.Max {
|
|
|
|
|
if err := maxConstraint(limitType, k, v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
if err := maxConstraint(string(limitType), string(k), v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.MaxLimitRequestRatio {
|
|
|
|
|
if err := limitRequestRatioConstraint(limitType, k, v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
if err := limitRequestRatioConstraint(string(limitType), string(k), v, container.Resources.Requests, container.Resources.Limits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -557,7 +548,7 @@ func PodValidateLimitFunc(limitRange *api.LimitRange, pod *api.Pod) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// enforce pod limits on init containers
|
|
|
|
|
if limitType == api.LimitTypePod {
|
|
|
|
|
if limitType == corev1.LimitTypePod {
|
|
|
|
|
containerRequests, containerLimits := []api.ResourceList{}, []api.ResourceList{}
|
|
|
|
|
for j := range pod.Spec.Containers {
|
|
|
|
|
container := &pod.Spec.Containers[j]
|
|
|
|
@@ -589,17 +580,17 @@ func PodValidateLimitFunc(limitRange *api.LimitRange, pod *api.Pod) error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.Min {
|
|
|
|
|
if err := minConstraint(limitType, k, v, podRequests, podLimits); err != nil {
|
|
|
|
|
if err := minConstraint(string(limitType), string(k), v, podRequests, podLimits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.Max {
|
|
|
|
|
if err := maxConstraint(limitType, k, v, podRequests, podLimits); err != nil {
|
|
|
|
|
if err := maxConstraint(string(limitType), string(k), v, podRequests, podLimits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for k, v := range limit.MaxLimitRequestRatio {
|
|
|
|
|
if err := limitRequestRatioConstraint(limitType, k, v, podRequests, podLimits); err != nil {
|
|
|
|
|
if err := limitRequestRatioConstraint(string(limitType), string(k), v, podRequests, podLimits); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|