const limitRangerAnnotation … const PluginName … // Register registers a plugin func Register(plugins *admission.Plugins) { … } type LimitRanger … var _ … var _ … var _ … var _ … type liveLookupEntry … // SetExternalKubeInformerFactory registers an informer factory into the LimitRanger func (l *LimitRanger) SetExternalKubeInformerFactory(f informers.SharedInformerFactory) { … } // SetExternalKubeClientSet registers the client into LimitRanger func (l *LimitRanger) SetExternalKubeClientSet(client kubernetes.Interface) { … } // ValidateInitialization verifies the LimitRanger object has been properly initialized func (l *LimitRanger) ValidateInitialization() error { … } // Admit admits resources into cluster that do not violate any defined LimitRange in the namespace func (l *LimitRanger) Admit(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) { … } // Validate admits resources into cluster that do not violate any defined LimitRange in the namespace func (l *LimitRanger) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) { … } func (l *LimitRanger) runLimitFunc(a admission.Attributes, limitFn func(limitRange *corev1.LimitRange, kind string, obj runtime.Object) error) (err error) { … } // GetLimitRanges returns a LimitRange object with the items held in // the indexer if available, or do alive lookup of the value. func (l *LimitRanger) GetLimitRanges(a admission.Attributes) ([]*corev1.LimitRange, error) { … } // NewLimitRanger returns an object that enforces limits based on the supplied limit function func NewLimitRanger(actions LimitRangerActions) (*LimitRanger, error) { … } // 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 *corev1.LimitRange) api.ResourceRequirements { … } // mergeContainerResources handles defaulting all of the resources on a container. func mergeContainerResources(container *api.Container, defaultRequirements *api.ResourceRequirements, annotationPrefix string, annotations []string) []string { … } // mergePodResourceRequirements merges enumerated requirements with default requirements // it annotates the pod with information about what requirements were modified func mergePodResourceRequirements(pod *api.Pod, defaultRequirements *api.ResourceRequirements) { … } // requestLimitEnforcedValues returns the specified values at a common precision to support comparability func requestLimitEnforcedValues(requestQuantity, limitQuantity, enforcedQuantity resource.Quantity) (request, limit, enforced int64) { … } // minConstraint enforces the min constraint over the specified resource func minConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error { … } // maxRequestConstraint enforces the max constraint over the specified resource // use when specify LimitType resource doesn't recognize limit values func maxRequestConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList) error { … } // maxConstraint enforces the max constraint over the specified resource func maxConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error { … } // limitRequestRatioConstraint enforces the limit to request ratio over the specified resource func limitRequestRatioConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error { … } type DefaultLimitRangerActions … var _ … // MutateLimit 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 *corev1.LimitRange, resourceName string, obj runtime.Object) error { … } // ValidateLimit verifies the resource requirements of incoming // resources against enumerated constraints on the LimitRange are // valid func (d *DefaultLimitRangerActions) ValidateLimit(limitRange *corev1.LimitRange, resourceName string, obj runtime.Object) error { … } // SupportsAttributes ignores all calls that do not deal with pod resources or storage requests (PVCs). // Also ignores any call that has a subresource defined. func (d *DefaultLimitRangerActions) SupportsAttributes(a admission.Attributes) bool { … } // SupportsLimit always returns true. func (d *DefaultLimitRangerActions) SupportsLimit(limitRange *corev1.LimitRange) bool { … } // PersistentVolumeClaimValidateLimitFunc enforces storage limits for PVCs. // 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 *corev1.LimitRange, pvc *api.PersistentVolumeClaim) error { … } // 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 *corev1.LimitRange, pod *api.Pod) error { … } // PodValidateLimitFunc enforces resource requirements enumerated by the pod against // the specified LimitRange. func PodValidateLimitFunc(limitRange *corev1.LimitRange, pod *api.Pod) error { … } type podResourcesOptions … // podRequests is a simplified version of pkg/api/v1/resource/PodRequests that operates against the core version of // pod. Any changes to that calculation should be reflected here. // TODO: Maybe we can consider doing a partial conversion of the pod to a v1 // type and then using the pkg/api/v1/resource/PodRequests. func podRequests(pod *api.Pod, opts podResourcesOptions) api.ResourceList { … } // podLimits is a simplified version of pkg/api/v1/resource/PodLimits that operates against the core version of // pod. Any changes to that calculation should be reflected here. // TODO: Maybe we can consider doing a partial conversion of the pod to a v1 // type and then using the pkg/api/v1/resource/PodLimits. func podLimits(pod *api.Pod, opts podResourcesOptions) api.ResourceList { … } // addResourceList adds the resources in newList to list. func addResourceList(list, newList api.ResourceList) { … } // maxResourceList sets list to the greater of list/newList for every resource in newList func maxResourceList(list, newList api.ResourceList) { … } // max returns the result of max(a, b) for each named resource and is only used if we can't // accumulate into an existing resource list func max(a api.ResourceList, b api.ResourceList) api.ResourceList { … }