...

Source file src/k8s.io/api/policy/v1beta1/types.go

Documentation: k8s.io/api/policy/v1beta1

     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 v1beta1
    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 `json:"minAvailable,omitempty" protobuf:"bytes,1,opt,name=minAvailable"`
    32  
    33  	// Label query over pods whose evictions are managed by the disruption
    34  	// budget.
    35  	// A null selector selects no pods.
    36  	// An empty selector ({}) also selects no pods, which differs from standard behavior of selecting all pods.
    37  	// In policy/v1, an empty selector will select all pods in the namespace.
    38  	// +optional
    39  	Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,2,opt,name=selector"`
    40  
    41  	// An eviction is allowed if at most "maxUnavailable" pods selected by
    42  	// "selector" are unavailable after the eviction, i.e. even in absence of
    43  	// the evicted pod. For example, one can prevent all voluntary evictions
    44  	// by specifying 0. This is a mutually exclusive setting with "minAvailable".
    45  	// +optional
    46  	MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty" protobuf:"bytes,3,opt,name=maxUnavailable"`
    47  
    48  	// UnhealthyPodEvictionPolicy defines the criteria for when unhealthy pods
    49  	// should be considered for eviction. Current implementation considers healthy pods,
    50  	// as pods that have status.conditions item with type="Ready",status="True".
    51  	//
    52  	// Valid policies are IfHealthyBudget and AlwaysAllow.
    53  	// If no policy is specified, the default behavior will be used,
    54  	// which corresponds to the IfHealthyBudget policy.
    55  	//
    56  	// IfHealthyBudget policy means that running pods (status.phase="Running"),
    57  	// but not yet healthy can be evicted only if the guarded application is not
    58  	// disrupted (status.currentHealthy is at least equal to status.desiredHealthy).
    59  	// Healthy pods will be subject to the PDB for eviction.
    60  	//
    61  	// AlwaysAllow policy means that all running pods (status.phase="Running"),
    62  	// but not yet healthy are considered disrupted and can be evicted regardless
    63  	// of whether the criteria in a PDB is met. This means perspective running
    64  	// pods of a disrupted application might not get a chance to become healthy.
    65  	// Healthy pods will be subject to the PDB for eviction.
    66  	//
    67  	// Additional policies may be added in the future.
    68  	// Clients making eviction decisions should disallow eviction of unhealthy pods
    69  	// if they encounter an unrecognized policy in this field.
    70  	//
    71  	// This field is beta-level. The eviction API uses this field when
    72  	// the feature gate PDBUnhealthyPodEvictionPolicy is enabled (enabled by default).
    73  	// +optional
    74  	UnhealthyPodEvictionPolicy *UnhealthyPodEvictionPolicyType `json:"unhealthyPodEvictionPolicy,omitempty" protobuf:"bytes,4,opt,name=unhealthyPodEvictionPolicy"`
    75  }
    76  
    77  // UnhealthyPodEvictionPolicyType defines the criteria for when unhealthy pods
    78  // should be considered for eviction.
    79  // +enum
    80  type UnhealthyPodEvictionPolicyType string
    81  
    82  const (
    83  	// IfHealthyBudget policy means that running pods (status.phase="Running"),
    84  	// but not yet healthy can be evicted only if the guarded application is not
    85  	// disrupted (status.currentHealthy is at least equal to status.desiredHealthy).
    86  	// Healthy pods will be subject to the PDB for eviction.
    87  	IfHealthyBudget UnhealthyPodEvictionPolicyType = "IfHealthyBudget"
    88  
    89  	// AlwaysAllow policy means that all running pods (status.phase="Running"),
    90  	// but not yet healthy are considered disrupted and can be evicted regardless
    91  	// of whether the criteria in a PDB is met. This means perspective running
    92  	// pods of a disrupted application might not get a chance to become healthy.
    93  	// Healthy pods will be subject to the PDB for eviction.
    94  	AlwaysAllow UnhealthyPodEvictionPolicyType = "AlwaysAllow"
    95  )
    96  
    97  // PodDisruptionBudgetStatus represents information about the status of a
    98  // PodDisruptionBudget. Status may trail the actual state of a system.
    99  type PodDisruptionBudgetStatus struct {
   100  	// Most recent generation observed when updating this PDB status. DisruptionsAllowed and other
   101  	// status information is valid only if observedGeneration equals to PDB's object generation.
   102  	// +optional
   103  	ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"`
   104  
   105  	// DisruptedPods contains information about pods whose eviction was
   106  	// processed by the API server eviction subresource handler but has not
   107  	// yet been observed by the PodDisruptionBudget controller.
   108  	// A pod will be in this map from the time when the API server processed the
   109  	// eviction request to the time when the pod is seen by PDB controller
   110  	// as having been marked for deletion (or after a timeout). The key in the map is the name of the pod
   111  	// and the value is the time when the API server processed the eviction request. If
   112  	// the deletion didn't occur and a pod is still there it will be removed from
   113  	// the list automatically by PodDisruptionBudget controller after some time.
   114  	// If everything goes smooth this map should be empty for the most of the time.
   115  	// Large number of entries in the map may indicate problems with pod deletions.
   116  	// +optional
   117  	DisruptedPods map[string]metav1.Time `json:"disruptedPods,omitempty" protobuf:"bytes,2,rep,name=disruptedPods"`
   118  
   119  	// Number of pod disruptions that are currently allowed.
   120  	DisruptionsAllowed int32 `json:"disruptionsAllowed" protobuf:"varint,3,opt,name=disruptionsAllowed"`
   121  
   122  	// current number of healthy pods
   123  	CurrentHealthy int32 `json:"currentHealthy" protobuf:"varint,4,opt,name=currentHealthy"`
   124  
   125  	// minimum desired number of healthy pods
   126  	DesiredHealthy int32 `json:"desiredHealthy" protobuf:"varint,5,opt,name=desiredHealthy"`
   127  
   128  	// total number of pods counted by this disruption budget
   129  	ExpectedPods int32 `json:"expectedPods" protobuf:"varint,6,opt,name=expectedPods"`
   130  
   131  	// Conditions contain conditions for PDB. The disruption controller sets the
   132  	// DisruptionAllowed condition. The following are known values for the reason field
   133  	// (additional reasons could be added in the future):
   134  	// - SyncFailed: The controller encountered an error and wasn't able to compute
   135  	//               the number of allowed disruptions. Therefore no disruptions are
   136  	//               allowed and the status of the condition will be False.
   137  	// - InsufficientPods: The number of pods are either at or below the number
   138  	//                     required by the PodDisruptionBudget. No disruptions are
   139  	//                     allowed and the status of the condition will be False.
   140  	// - SufficientPods: There are more pods than required by the PodDisruptionBudget.
   141  	//                   The condition will be True, and the number of allowed
   142  	//                   disruptions are provided by the disruptionsAllowed property.
   143  	//
   144  	// +optional
   145  	// +patchMergeKey=type
   146  	// +patchStrategy=merge
   147  	// +listType=map
   148  	// +listMapKey=type
   149  	Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,7,rep,name=conditions"`
   150  }
   151  
   152  const (
   153  	// DisruptionAllowedCondition is a condition set by the disruption controller
   154  	// that signal whether any of the pods covered by the PDB can be disrupted.
   155  	DisruptionAllowedCondition = "DisruptionAllowed"
   156  
   157  	// SyncFailedReason is set on the DisruptionAllowed condition if reconcile
   158  	// of the PDB failed and therefore disruption of pods are not allowed.
   159  	SyncFailedReason = "SyncFailed"
   160  	// SufficientPodsReason is set on the DisruptionAllowed condition if there are
   161  	// more pods covered by the PDB than required and at least one can be disrupted.
   162  	SufficientPodsReason = "SufficientPods"
   163  	// InsufficientPodsReason is set on the DisruptionAllowed condition if the number
   164  	// of pods are equal to or fewer than required by the PDB.
   165  	InsufficientPodsReason = "InsufficientPods"
   166  )
   167  
   168  // +genclient
   169  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   170  // +k8s:prerelease-lifecycle-gen:introduced=1.5
   171  // +k8s:prerelease-lifecycle-gen:deprecated=1.21
   172  // +k8s:prerelease-lifecycle-gen:removed=1.25
   173  // +k8s:prerelease-lifecycle-gen:replacement=policy,v1,PodDisruptionBudget
   174  
   175  // PodDisruptionBudget is an object to define the max disruption that can be caused to a collection of pods
   176  type PodDisruptionBudget struct {
   177  	metav1.TypeMeta `json:",inline"`
   178  
   179  	// Standard object's metadata.
   180  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   181  	// +optional
   182  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
   183  
   184  	// Specification of the desired behavior of the PodDisruptionBudget.
   185  	// +optional
   186  	Spec PodDisruptionBudgetSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
   187  	// Most recently observed status of the PodDisruptionBudget.
   188  	// +optional
   189  	Status PodDisruptionBudgetStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
   190  }
   191  
   192  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   193  // +k8s:prerelease-lifecycle-gen:introduced=1.5
   194  // +k8s:prerelease-lifecycle-gen:deprecated=1.21
   195  // +k8s:prerelease-lifecycle-gen:removed=1.25
   196  // +k8s:prerelease-lifecycle-gen:replacement=policy,v1,PodDisruptionBudgetList
   197  
   198  // PodDisruptionBudgetList is a collection of PodDisruptionBudgets.
   199  type PodDisruptionBudgetList struct {
   200  	metav1.TypeMeta `json:",inline"`
   201  
   202  	// Standard object's metadata.
   203  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   204  	// +optional
   205  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
   206  	// items list individual PodDisruptionBudget objects
   207  	Items []PodDisruptionBudget `json:"items" protobuf:"bytes,2,rep,name=items"`
   208  }
   209  
   210  // +genclient
   211  // +genclient:noVerbs
   212  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   213  // +k8s:prerelease-lifecycle-gen:introduced=1.5
   214  // +k8s:prerelease-lifecycle-gen:deprecated=1.22
   215  
   216  // Eviction evicts a pod from its node subject to certain policies and safety constraints.
   217  // This is a subresource of Pod.  A request to cause such an eviction is
   218  // created by POSTing to .../pods/<pod name>/evictions.
   219  type Eviction struct {
   220  	metav1.TypeMeta `json:",inline"`
   221  
   222  	// ObjectMeta describes the pod that is being evicted.
   223  	// +optional
   224  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
   225  
   226  	// DeleteOptions may be provided
   227  	// +optional
   228  	DeleteOptions *metav1.DeleteOptions `json:"deleteOptions,omitempty" protobuf:"bytes,2,opt,name=deleteOptions"`
   229  }
   230  

View as plain text