1 /* 2 Copyright 2016 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 policy 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "k8s.io/apimachinery/pkg/util/intstr" 22 ) 23 24 // PodDisruptionBudgetSpec is a description of a PodDisruptionBudget. 25 type PodDisruptionBudgetSpec struct { 26 // An eviction is allowed if at least "minAvailable" pods selected by 27 // "selector" will still be available after the eviction, i.e. even in the 28 // absence of the evicted pod. So for example you can prevent all voluntary 29 // evictions by specifying "100%". 30 // +optional 31 MinAvailable *intstr.IntOrString 32 33 // Label query over pods whose evictions are managed by the disruption 34 // budget. 35 // +optional 36 Selector *metav1.LabelSelector 37 38 // An eviction is allowed if at most "maxUnavailable" pods selected by 39 // "selector" are unavailable after the eviction, i.e. even in absence of 40 // the evicted pod. For example, one can prevent all voluntary evictions 41 // by specifying 0. This is a mutually exclusive setting with "minAvailable". 42 // +optional 43 MaxUnavailable *intstr.IntOrString 44 45 // UnhealthyPodEvictionPolicy defines the criteria for when unhealthy pods 46 // should be considered for eviction. Current implementation considers healthy pods, 47 // as pods that have status.conditions item with type="Ready",status="True". 48 // 49 // Valid policies are IfHealthyBudget and AlwaysAllow. 50 // If no policy is specified, the default behavior will be used, 51 // which corresponds to the IfHealthyBudget policy. 52 // 53 // IfHealthyBudget policy means that running pods (status.phase="Running"), 54 // but not yet healthy can be evicted only if the guarded application is not 55 // disrupted (status.currentHealthy is at least equal to status.desiredHealthy). 56 // Healthy pods will be subject to the PDB for eviction. 57 // 58 // AlwaysAllow policy means that all running pods (status.phase="Running"), 59 // but not yet healthy are considered disrupted and can be evicted regardless 60 // of whether the criteria in a PDB is met. This means perspective running 61 // pods of a disrupted application might not get a chance to become healthy. 62 // Healthy pods will be subject to the PDB for eviction. 63 // 64 // Additional policies may be added in the future. 65 // Clients making eviction decisions should disallow eviction of unhealthy pods 66 // if they encounter an unrecognized policy in this field. 67 // 68 // This field is beta-level. The eviction API uses this field when 69 // the feature gate PDBUnhealthyPodEvictionPolicy is enabled (enabled by default). 70 // +optional 71 UnhealthyPodEvictionPolicy *UnhealthyPodEvictionPolicyType 72 } 73 74 // UnhealthyPodEvictionPolicyType defines the criteria for when unhealthy pods 75 // should be considered for eviction. 76 // +enum 77 type UnhealthyPodEvictionPolicyType string 78 79 const ( 80 // IfHealthyBudget policy means that running pods (status.phase="Running"), 81 // but not yet healthy can be evicted only if the guarded application is not 82 // disrupted (status.currentHealthy is at least equal to status.desiredHealthy). 83 // Healthy pods will be subject to the PDB for eviction. 84 IfHealthyBudget UnhealthyPodEvictionPolicyType = "IfHealthyBudget" 85 86 // AlwaysAllow policy means that all running pods (status.phase="Running"), 87 // but not yet healthy are considered disrupted and can be evicted regardless 88 // of whether the criteria in a PDB is met. This means perspective running 89 // pods of a disrupted application might not get a chance to become healthy. 90 // Healthy pods will be subject to the PDB for eviction. 91 AlwaysAllow UnhealthyPodEvictionPolicyType = "AlwaysAllow" 92 ) 93 94 // PodDisruptionBudgetStatus represents information about the status of a 95 // PodDisruptionBudget. Status may trail the actual state of a system. 96 type PodDisruptionBudgetStatus struct { 97 // Most recent generation observed when updating this PDB status. DisruptionsAllowed and other 98 // status information is valid only if observedGeneration equals to PDB's object generation. 99 // +optional 100 ObservedGeneration int64 101 102 // DisruptedPods contains information about pods whose eviction was 103 // processed by the API server eviction subresource handler but has not 104 // yet been observed by the PodDisruptionBudget controller. 105 // A pod will be in this map from the time when the API server processed the 106 // eviction request to the time when the pod is seen by PDB controller 107 // as having been marked for deletion (or after a timeout). The key in the map is the name of the pod 108 // and the value is the time when the API server processed the eviction request. If 109 // the deletion didn't occur and a pod is still there it will be removed from 110 // the list automatically by PodDisruptionBudget controller after some time. 111 // If everything goes smooth this map should be empty for the most of the time. 112 // Large number of entries in the map may indicate problems with pod deletions. 113 // +optional 114 DisruptedPods map[string]metav1.Time 115 116 // Number of pod disruptions that are currently allowed. 117 DisruptionsAllowed int32 118 119 // current number of healthy pods 120 CurrentHealthy int32 121 122 // minimum desired number of healthy pods 123 DesiredHealthy int32 124 125 // total number of pods counted by this disruption budget 126 ExpectedPods int32 127 128 // Conditions contain conditions for PDB 129 // +optional 130 Conditions []metav1.Condition 131 } 132 133 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 134 135 // PodDisruptionBudget is an object to define the max disruption that can be caused to a collection of pods 136 type PodDisruptionBudget struct { 137 metav1.TypeMeta 138 // +optional 139 metav1.ObjectMeta 140 141 // Specification of the desired behavior of the PodDisruptionBudget. 142 // +optional 143 Spec PodDisruptionBudgetSpec 144 // Most recently observed status of the PodDisruptionBudget. 145 // +optional 146 Status PodDisruptionBudgetStatus 147 } 148 149 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 150 151 // PodDisruptionBudgetList is a collection of PodDisruptionBudgets. 152 type PodDisruptionBudgetList struct { 153 metav1.TypeMeta 154 // +optional 155 metav1.ListMeta 156 Items []PodDisruptionBudget 157 } 158 159 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 160 161 // Eviction evicts a pod from its node subject to certain policies and safety constraints. 162 // This is a subresource of Pod. A request to cause such an eviction is 163 // created by POSTing to .../pods/<pod name>/eviction. 164 type Eviction struct { 165 metav1.TypeMeta 166 167 // ObjectMeta describes the pod that is being evicted. 168 // +optional 169 metav1.ObjectMeta 170 171 // DeleteOptions may be provided 172 // +optional 173 DeleteOptions *metav1.DeleteOptions 174 } 175