...

Source file src/k8s.io/kubernetes/pkg/kubelet/eviction/api/types.go

Documentation: k8s.io/kubernetes/pkg/kubelet/eviction/api

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package api
    18  
    19  import (
    20  	"time"
    21  
    22  	"k8s.io/apimachinery/pkg/api/resource"
    23  )
    24  
    25  // Signal defines a signal that can trigger eviction of pods on a node.
    26  type Signal string
    27  
    28  const (
    29  	// SignalMemoryAvailable is memory available (i.e. capacity - workingSet), in bytes.
    30  	SignalMemoryAvailable Signal = "memory.available"
    31  	// SignalNodeFsAvailable is amount of storage available on filesystem that kubelet uses for volumes, daemon logs, etc.
    32  	SignalNodeFsAvailable Signal = "nodefs.available"
    33  	// SignalNodeFsInodesFree is amount of inodes available on filesystem that kubelet uses for volumes, daemon logs, etc.
    34  	SignalNodeFsInodesFree Signal = "nodefs.inodesFree"
    35  	// SignalImageFsAvailable is amount of storage available on filesystem that container runtime uses for storing images layers.
    36  	// If the container filesystem and image filesystem are not separate,
    37  	// than imagefs can store both image layers and writeable layers.
    38  	SignalImageFsAvailable Signal = "imagefs.available"
    39  	// SignalImageFsInodesFree is amount of inodes available on filesystem that container runtime uses for storing images layers.
    40  	// If the container filesystem and image filesystem are not separate,
    41  	// than imagefs can store both image layers and writeable layers.
    42  	SignalImageFsInodesFree Signal = "imagefs.inodesFree"
    43  	// SignalContainerFsAvailable is amount of storage available on filesystem that container runtime uses for container writable layers.
    44  	// In case of a single filesystem, containerfs=nodefs.
    45  	// In case of a image filesystem, containerfs=imagefs.
    46  	// We will override user settings and set to either imagefs or nodefs depending on configuration.
    47  	SignalContainerFsAvailable Signal = "containerfs.available"
    48  	// SignalContainerFsInodesFree is amount of inodes available on filesystem that container runtime uses for container writable layers.
    49  	// SignalContainerFsAvailable is amount of storage available on filesystem that container runtime uses for container writable layers.
    50  	// In case of a single filesystem, containerfs=nodefs.
    51  	// In case of a image filesystem, containerfs=imagefs.
    52  	// We will override user settings and set to either imagefs or nodefs depending on configuration.
    53  	SignalContainerFsInodesFree Signal = "containerfs.inodesFree"
    54  	// SignalAllocatableMemoryAvailable is amount of memory available for pod allocation (i.e. allocatable - workingSet (of pods), in bytes.
    55  	SignalAllocatableMemoryAvailable Signal = "allocatableMemory.available"
    56  	// SignalPIDAvailable is amount of PID available for pod allocation
    57  	SignalPIDAvailable Signal = "pid.available"
    58  )
    59  
    60  // ThresholdOperator is the operator used to express a Threshold.
    61  type ThresholdOperator string
    62  
    63  const (
    64  	// OpLessThan is the operator that expresses a less than operator.
    65  	OpLessThan ThresholdOperator = "LessThan"
    66  )
    67  
    68  // OpForSignal maps Signals to ThresholdOperators.
    69  // Today, the only supported operator is "LessThan". This may change in the future,
    70  // for example if "consumed" (as opposed to "available") type signals are added.
    71  // In both cases the directionality of the threshold is implicit to the signal type
    72  // (for a given signal, the decision to evict will be made when crossing the threshold
    73  // from either above or below, never both). There is thus no reason to expose the
    74  // operator in the Kubelet's public API. Instead, we internally map signal types to operators.
    75  var OpForSignal = map[Signal]ThresholdOperator{
    76  	SignalMemoryAvailable:            OpLessThan,
    77  	SignalNodeFsAvailable:            OpLessThan,
    78  	SignalNodeFsInodesFree:           OpLessThan,
    79  	SignalImageFsAvailable:           OpLessThan,
    80  	SignalImageFsInodesFree:          OpLessThan,
    81  	SignalContainerFsAvailable:       OpLessThan,
    82  	SignalContainerFsInodesFree:      OpLessThan,
    83  	SignalAllocatableMemoryAvailable: OpLessThan,
    84  	SignalPIDAvailable:               OpLessThan,
    85  }
    86  
    87  // ThresholdValue is a value holder that abstracts literal versus percentage based quantity
    88  type ThresholdValue struct {
    89  	// The following fields are exclusive. Only the topmost non-zero field is used.
    90  
    91  	// Quantity is a quantity associated with the signal that is evaluated against the specified operator.
    92  	Quantity *resource.Quantity
    93  	// Percentage represents the usage percentage over the total resource that is evaluated against the specified operator.
    94  	Percentage float32
    95  }
    96  
    97  // Threshold defines a metric for when eviction should occur.
    98  type Threshold struct {
    99  	// Signal defines the entity that was measured.
   100  	Signal Signal
   101  	// Operator represents a relationship of a signal to a value.
   102  	Operator ThresholdOperator
   103  	// Value is the threshold the resource is evaluated against.
   104  	Value ThresholdValue
   105  	// GracePeriod represents the amount of time that a threshold must be met before eviction is triggered.
   106  	GracePeriod time.Duration
   107  	// MinReclaim represents the minimum amount of resource to reclaim if the threshold is met.
   108  	MinReclaim *ThresholdValue
   109  }
   110  
   111  // GetThresholdQuantity returns the expected quantity value for a thresholdValue
   112  func GetThresholdQuantity(value ThresholdValue, capacity *resource.Quantity) *resource.Quantity {
   113  	if value.Quantity != nil {
   114  		res := value.Quantity.DeepCopy()
   115  		return &res
   116  	}
   117  	return resource.NewQuantity(int64(float64(capacity.Value())*float64(value.Percentage)), resource.BinarySI)
   118  }
   119  

View as plain text