1/* 2Copyright 2017 The Kubernetes Authors. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17package v1 18 19import ( 20 "k8s.io/api/core/v1" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 runtime "k8s.io/apimachinery/pkg/runtime" 23 "k8s.io/apimachinery/pkg/util/intstr" 24) 25 26const ( 27 ControllerRevisionHashLabelKey = "controller-revision-hash" 28 StatefulSetRevisionLabel = ControllerRevisionHashLabelKey 29 DeprecatedRollbackTo = "deprecated.deployment.rollback.to" 30 DeprecatedTemplateGeneration = "deprecated.daemonset.template.generation" 31 StatefulSetPodNameLabel = "statefulset.kubernetes.io/pod-name" 32) 33 34// +genclient 35// +genclient:method=GetScale,verb=get,subresource=scale,result=k8s.io/api/autoscaling/v1.Scale 36// +genclient:method=UpdateScale,verb=update,subresource=scale,input=k8s.io/api/autoscaling/v1.Scale,result=k8s.io/api/autoscaling/v1.Scale 37// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 38 39// StatefulSet represents a set of pods with consistent identities. 40// Identities are defined as: 41// - Network: A single stable DNS and hostname. 42// - Storage: As many VolumeClaims as requested. 43// The StatefulSet guarantees that a given network identity will always 44// map to the same storage identity. 45type StatefulSet struct { 46 metav1.TypeMeta `json:",inline"` 47 // +optional 48 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 49 50 // Spec defines the desired identities of pods in this set. 51 // +optional 52 Spec StatefulSetSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 53 54 // Status is the current status of Pods in this StatefulSet. This data 55 // may be out of date by some window of time. 56 // +optional 57 Status StatefulSetStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 58} 59 60// PodManagementPolicyType defines the policy for creating pods under a stateful set. 61type PodManagementPolicyType string 62 63const ( 64 // OrderedReadyPodManagement will create pods in strictly increasing order on 65 // scale up and strictly decreasing order on scale down, progressing only when 66 // the previous pod is ready or terminated. At most one pod will be changed 67 // at any time. 68 OrderedReadyPodManagement PodManagementPolicyType = "OrderedReady" 69 // ParallelPodManagement will create and delete pods as soon as the stateful set 70 // replica count is changed, and will not wait for pods to be ready or complete 71 // termination. 72 ParallelPodManagement PodManagementPolicyType = "Parallel" 73) 74 75// StatefulSetUpdateStrategy indicates the strategy that the StatefulSet 76// controller will use to perform updates. It includes any additional parameters 77// necessary to perform the update for the indicated strategy. 78type StatefulSetUpdateStrategy struct { 79 // Type indicates the type of the StatefulSetUpdateStrategy. 80 // Default is RollingUpdate. 81 // +optional 82 Type StatefulSetUpdateStrategyType `json:"type,omitempty" protobuf:"bytes,1,opt,name=type,casttype=StatefulSetStrategyType"` 83 // RollingUpdate is used to communicate parameters when Type is RollingUpdateStatefulSetStrategyType. 84 // +optional 85 RollingUpdate *RollingUpdateStatefulSetStrategy `json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"` 86} 87 88// StatefulSetUpdateStrategyType is a string enumeration type that enumerates 89// all possible update strategies for the StatefulSet controller. 90type StatefulSetUpdateStrategyType string 91 92const ( 93 // RollingUpdateStatefulSetStrategyType indicates that update will be 94 // applied to all Pods in the StatefulSet with respect to the StatefulSet 95 // ordering constraints. When a scale operation is performed with this 96 // strategy, new Pods will be created from the specification version indicated 97 // by the StatefulSet's updateRevision. 98 RollingUpdateStatefulSetStrategyType = "RollingUpdate" 99 // OnDeleteStatefulSetStrategyType triggers the legacy behavior. Version 100 // tracking and ordered rolling restarts are disabled. Pods are recreated 101 // from the StatefulSetSpec when they are manually deleted. When a scale 102 // operation is performed with this strategy,specification version indicated 103 // by the StatefulSet's currentRevision. 104 OnDeleteStatefulSetStrategyType = "OnDelete" 105) 106 107// RollingUpdateStatefulSetStrategy is used to communicate parameter for RollingUpdateStatefulSetStrategyType. 108type RollingUpdateStatefulSetStrategy struct { 109 // Partition indicates the ordinal at which the StatefulSet should be 110 // partitioned. 111 // Default value is 0. 112 // +optional 113 Partition *int32 `json:"partition,omitempty" protobuf:"varint,1,opt,name=partition"` 114} 115 116// A StatefulSetSpec is the specification of a StatefulSet. 117type StatefulSetSpec struct { 118 // replicas is the desired number of replicas of the given Template. 119 // These are replicas in the sense that they are instantiations of the 120 // same Template, but individual replicas also have a consistent identity. 121 // If unspecified, defaults to 1. 122 // TODO: Consider a rename of this field. 123 // +optional 124 Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"` 125 126 // selector is a label query over pods that should match the replica count. 127 // It must match the pod template's labels. 128 // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors 129 Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,2,opt,name=selector"` 130 131 // template is the object that describes the pod that will be created if 132 // insufficient replicas are detected. Each pod stamped out by the StatefulSet 133 // will fulfill this Template, but have a unique identity from the rest 134 // of the StatefulSet. 135 Template v1.PodTemplateSpec `json:"template" protobuf:"bytes,3,opt,name=template"` 136 137 // volumeClaimTemplates is a list of claims that pods are allowed to reference. 138 // The StatefulSet controller is responsible for mapping network identities to 139 // claims in a way that maintains the identity of a pod. Every claim in 140 // this list must have at least one matching (by name) volumeMount in one 141 // container in the template. A claim in this list takes precedence over 142 // any volumes in the template, with the same name. 143 // TODO: Define the behavior if a claim already exists with the same name. 144 // +optional 145 VolumeClaimTemplates []v1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty" protobuf:"bytes,4,rep,name=volumeClaimTemplates"` 146 147 // serviceName is the name of the service that governs this StatefulSet. 148 // This service must exist before the StatefulSet, and is responsible for 149 // the network identity of the set. Pods get DNS/hostnames that follow the 150 // pattern: pod-specific-string.serviceName.default.svc.cluster.local 151 // where "pod-specific-string" is managed by the StatefulSet controller. 152 ServiceName string `json:"serviceName" protobuf:"bytes,5,opt,name=serviceName"` 153 154 // podManagementPolicy controls how pods are created during initial scale up, 155 // when replacing pods on nodes, or when scaling down. The default policy is 156 // `OrderedReady`, where pods are created in increasing order (pod-0, then 157 // pod-1, etc) and the controller will wait until each pod is ready before 158 // continuing. When scaling down, the pods are removed in the opposite order. 159 // The alternative policy is `Parallel` which will create pods in parallel 160 // to match the desired scale without waiting, and on scale down will delete 161 // all pods at once. 162 // +optional 163 PodManagementPolicy PodManagementPolicyType `json:"podManagementPolicy,omitempty" protobuf:"bytes,6,opt,name=podManagementPolicy,casttype=PodManagementPolicyType"` 164 165 // updateStrategy indicates the StatefulSetUpdateStrategy that will be 166 // employed to update Pods in the StatefulSet when a revision is made to 167 // Template. 168 UpdateStrategy StatefulSetUpdateStrategy `json:"updateStrategy,omitempty" protobuf:"bytes,7,opt,name=updateStrategy"` 169 170 // revisionHistoryLimit is the maximum number of revisions that will 171 // be maintained in the StatefulSet's revision history. The revision history 172 // consists of all revisions not represented by a currently applied 173 // StatefulSetSpec version. The default value is 10. 174 RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty" protobuf:"varint,8,opt,name=revisionHistoryLimit"` 175} 176 177// StatefulSetStatus represents the current state of a StatefulSet. 178type StatefulSetStatus struct { 179 // observedGeneration is the most recent generation observed for this StatefulSet. It corresponds to the 180 // StatefulSet's generation, which is updated on mutation by the API Server. 181 // +optional 182 ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"` 183 184 // replicas is the number of Pods created by the StatefulSet controller. 185 Replicas int32 `json:"replicas" protobuf:"varint,2,opt,name=replicas"` 186 187 // readyReplicas is the number of Pods created by the StatefulSet controller that have a Ready Condition. 188 ReadyReplicas int32 `json:"readyReplicas,omitempty" protobuf:"varint,3,opt,name=readyReplicas"` 189 190 // currentReplicas is the number of Pods created by the StatefulSet controller from the StatefulSet version 191 // indicated by currentRevision. 192 CurrentReplicas int32 `json:"currentReplicas,omitempty" protobuf:"varint,4,opt,name=currentReplicas"` 193 194 // updatedReplicas is the number of Pods created by the StatefulSet controller from the StatefulSet version 195 // indicated by updateRevision. 196 UpdatedReplicas int32 `json:"updatedReplicas,omitempty" protobuf:"varint,5,opt,name=updatedReplicas"` 197 198 // currentRevision, if not empty, indicates the version of the StatefulSet used to generate Pods in the 199 // sequence [0,currentReplicas). 200 CurrentRevision string `json:"currentRevision,omitempty" protobuf:"bytes,6,opt,name=currentRevision"` 201 202 // updateRevision, if not empty, indicates the version of the StatefulSet used to generate Pods in the sequence 203 // [replicas-updatedReplicas,replicas) 204 UpdateRevision string `json:"updateRevision,omitempty" protobuf:"bytes,7,opt,name=updateRevision"` 205 206 // collisionCount is the count of hash collisions for the StatefulSet. The StatefulSet controller 207 // uses this field as a collision avoidance mechanism when it needs to create the name for the 208 // newest ControllerRevision. 209 // +optional 210 CollisionCount *int32 `json:"collisionCount,omitempty" protobuf:"varint,9,opt,name=collisionCount"` 211 212 // Represents the latest available observations of a statefulset's current state. 213 // +optional 214 // +patchMergeKey=type 215 // +patchStrategy=merge 216 Conditions []StatefulSetCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,10,rep,name=conditions"` 217} 218 219type StatefulSetConditionType string 220 221// StatefulSetCondition describes the state of a statefulset at a certain point. 222type StatefulSetCondition struct { 223 // Type of statefulset condition. 224 Type StatefulSetConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=StatefulSetConditionType"` 225 // Status of the condition, one of True, False, Unknown. 226 Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=k8s.io/api/core/v1.ConditionStatus"` 227 // Last time the condition transitioned from one status to another. 228 // +optional 229 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"` 230 // The reason for the condition's last transition. 231 // +optional 232 Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"` 233 // A human readable message indicating details about the transition. 234 // +optional 235 Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"` 236} 237 238// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 239 240// StatefulSetList is a collection of StatefulSets. 241type StatefulSetList struct { 242 metav1.TypeMeta `json:",inline"` 243 // +optional 244 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 245 Items []StatefulSet `json:"items" protobuf:"bytes,2,rep,name=items"` 246} 247 248// +genclient 249// +genclient:method=GetScale,verb=get,subresource=scale,result=k8s.io/api/autoscaling/v1.Scale 250// +genclient:method=UpdateScale,verb=update,subresource=scale,input=k8s.io/api/autoscaling/v1.Scale,result=k8s.io/api/autoscaling/v1.Scale 251// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 252 253// Deployment enables declarative updates for Pods and ReplicaSets. 254type Deployment struct { 255 metav1.TypeMeta `json:",inline"` 256 // Standard object metadata. 257 // +optional 258 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 259 260 // Specification of the desired behavior of the Deployment. 261 // +optional 262 Spec DeploymentSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 263 264 // Most recently observed status of the Deployment. 265 // +optional 266 Status DeploymentStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 267} 268 269// DeploymentSpec is the specification of the desired behavior of the Deployment. 270type DeploymentSpec struct { 271 // Number of desired pods. This is a pointer to distinguish between explicit 272 // zero and not specified. Defaults to 1. 273 // +optional 274 Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"` 275 276 // Label selector for pods. Existing ReplicaSets whose pods are 277 // selected by this will be the ones affected by this deployment. 278 // It must match the pod template's labels. 279 Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,2,opt,name=selector"` 280 281 // Template describes the pods that will be created. 282 Template v1.PodTemplateSpec `json:"template" protobuf:"bytes,3,opt,name=template"` 283 284 // The deployment strategy to use to replace existing pods with new ones. 285 // +optional 286 // +patchStrategy=retainKeys 287 Strategy DeploymentStrategy `json:"strategy,omitempty" patchStrategy:"retainKeys" protobuf:"bytes,4,opt,name=strategy"` 288 289 // Minimum number of seconds for which a newly created pod should be ready 290 // without any of its container crashing, for it to be considered available. 291 // Defaults to 0 (pod will be considered available as soon as it is ready) 292 // +optional 293 MinReadySeconds int32 `json:"minReadySeconds,omitempty" protobuf:"varint,5,opt,name=minReadySeconds"` 294 295 // The number of old ReplicaSets to retain to allow rollback. 296 // This is a pointer to distinguish between explicit zero and not specified. 297 // Defaults to 10. 298 // +optional 299 RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty" protobuf:"varint,6,opt,name=revisionHistoryLimit"` 300 301 // Indicates that the deployment is paused. 302 // +optional 303 Paused bool `json:"paused,omitempty" protobuf:"varint,7,opt,name=paused"` 304 305 // The maximum time in seconds for a deployment to make progress before it 306 // is considered to be failed. The deployment controller will continue to 307 // process failed deployments and a condition with a ProgressDeadlineExceeded 308 // reason will be surfaced in the deployment status. Note that progress will 309 // not be estimated during the time a deployment is paused. Defaults to 600s. 310 ProgressDeadlineSeconds *int32 `json:"progressDeadlineSeconds,omitempty" protobuf:"varint,9,opt,name=progressDeadlineSeconds"` 311} 312 313const ( 314 // DefaultDeploymentUniqueLabelKey is the default key of the selector that is added 315 // to existing ReplicaSets (and label key that is added to its pods) to prevent the existing ReplicaSets 316 // to select new pods (and old pods being select by new ReplicaSet). 317 DefaultDeploymentUniqueLabelKey string = "pod-template-hash" 318) 319 320// DeploymentStrategy describes how to replace existing pods with new ones. 321type DeploymentStrategy struct { 322 // Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate. 323 // +optional 324 Type DeploymentStrategyType `json:"type,omitempty" protobuf:"bytes,1,opt,name=type,casttype=DeploymentStrategyType"` 325 326 // Rolling update config params. Present only if DeploymentStrategyType = 327 // RollingUpdate. 328 //--- 329 // TODO: Update this to follow our convention for oneOf, whatever we decide it 330 // to be. 331 // +optional 332 RollingUpdate *RollingUpdateDeployment `json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"` 333} 334 335type DeploymentStrategyType string 336 337const ( 338 // Kill all existing pods before creating new ones. 339 RecreateDeploymentStrategyType DeploymentStrategyType = "Recreate" 340 341 // Replace the old ReplicaSets by new one using rolling update i.e gradually scale down the old ReplicaSets and scale up the new one. 342 RollingUpdateDeploymentStrategyType DeploymentStrategyType = "RollingUpdate" 343) 344 345// Spec to control the desired behavior of rolling update. 346type RollingUpdateDeployment struct { 347 // The maximum number of pods that can be unavailable during the update. 348 // Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). 349 // Absolute number is calculated from percentage by rounding down. 350 // This can not be 0 if MaxSurge is 0. 351 // Defaults to 25%. 352 // Example: when this is set to 30%, the old ReplicaSet can be scaled down to 70% of desired pods 353 // immediately when the rolling update starts. Once new pods are ready, old ReplicaSet 354 // can be scaled down further, followed by scaling up the new ReplicaSet, ensuring 355 // that the total number of pods available at all times during the update is at 356 // least 70% of desired pods. 357 // +optional 358 MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty" protobuf:"bytes,1,opt,name=maxUnavailable"` 359 360 // The maximum number of pods that can be scheduled above the desired number of 361 // pods. 362 // Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). 363 // This can not be 0 if MaxUnavailable is 0. 364 // Absolute number is calculated from percentage by rounding up. 365 // Defaults to 25%. 366 // Example: when this is set to 30%, the new ReplicaSet can be scaled up immediately when 367 // the rolling update starts, such that the total number of old and new pods do not exceed 368 // 130% of desired pods. Once old pods have been killed, 369 // new ReplicaSet can be scaled up further, ensuring that total number of pods running 370 // at any time during the update is at most 130% of desired pods. 371 // +optional 372 MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty" protobuf:"bytes,2,opt,name=maxSurge"` 373} 374 375// DeploymentStatus is the most recently observed status of the Deployment. 376type DeploymentStatus struct { 377 // The generation observed by the deployment controller. 378 // +optional 379 ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"` 380 381 // Total number of non-terminated pods targeted by this deployment (their labels match the selector). 382 // +optional 383 Replicas int32 `json:"replicas,omitempty" protobuf:"varint,2,opt,name=replicas"` 384 385 // Total number of non-terminated pods targeted by this deployment that have the desired template spec. 386 // +optional 387 UpdatedReplicas int32 `json:"updatedReplicas,omitempty" protobuf:"varint,3,opt,name=updatedReplicas"` 388 389 // Total number of ready pods targeted by this deployment. 390 // +optional 391 ReadyReplicas int32 `json:"readyReplicas,omitempty" protobuf:"varint,7,opt,name=readyReplicas"` 392 393 // Total number of available pods (ready for at least minReadySeconds) targeted by this deployment. 394 // +optional 395 AvailableReplicas int32 `json:"availableReplicas,omitempty" protobuf:"varint,4,opt,name=availableReplicas"` 396 397 // Total number of unavailable pods targeted by this deployment. This is the total number of 398 // pods that are still required for the deployment to have 100% available capacity. They may 399 // either be pods that are running but not yet available or pods that still have not been created. 400 // +optional 401 UnavailableReplicas int32 `json:"unavailableReplicas,omitempty" protobuf:"varint,5,opt,name=unavailableReplicas"` 402 403 // Represents the latest available observations of a deployment's current state. 404 // +patchMergeKey=type 405 // +patchStrategy=merge 406 Conditions []DeploymentCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,6,rep,name=conditions"` 407 408 // Count of hash collisions for the Deployment. The Deployment controller uses this 409 // field as a collision avoidance mechanism when it needs to create the name for the 410 // newest ReplicaSet. 411 // +optional 412 CollisionCount *int32 `json:"collisionCount,omitempty" protobuf:"varint,8,opt,name=collisionCount"` 413} 414 415type DeploymentConditionType string 416 417// These are valid conditions of a deployment. 418const ( 419 // Available means the deployment is available, ie. at least the minimum available 420 // replicas required are up and running for at least minReadySeconds. 421 DeploymentAvailable DeploymentConditionType = "Available" 422 // Progressing means the deployment is progressing. Progress for a deployment is 423 // considered when a new replica set is created or adopted, and when new pods scale 424 // up or old pods scale down. Progress is not estimated for paused deployments or 425 // when progressDeadlineSeconds is not specified. 426 DeploymentProgressing DeploymentConditionType = "Progressing" 427 // ReplicaFailure is added in a deployment when one of its pods fails to be created 428 // or deleted. 429 DeploymentReplicaFailure DeploymentConditionType = "ReplicaFailure" 430) 431 432// DeploymentCondition describes the state of a deployment at a certain point. 433type DeploymentCondition struct { 434 // Type of deployment condition. 435 Type DeploymentConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=DeploymentConditionType"` 436 // Status of the condition, one of True, False, Unknown. 437 Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=k8s.io/api/core/v1.ConditionStatus"` 438 // The last time this condition was updated. 439 LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty" protobuf:"bytes,6,opt,name=lastUpdateTime"` 440 // Last time the condition transitioned from one status to another. 441 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,7,opt,name=lastTransitionTime"` 442 // The reason for the condition's last transition. 443 Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"` 444 // A human readable message indicating details about the transition. 445 Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"` 446} 447 448// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 449 450// DeploymentList is a list of Deployments. 451type DeploymentList struct { 452 metav1.TypeMeta `json:",inline"` 453 // Standard list metadata. 454 // +optional 455 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 456 457 // Items is the list of Deployments. 458 Items []Deployment `json:"items" protobuf:"bytes,2,rep,name=items"` 459} 460 461// DaemonSetUpdateStrategy is a struct used to control the update strategy for a DaemonSet. 462type DaemonSetUpdateStrategy struct { 463 // Type of daemon set update. Can be "RollingUpdate" or "OnDelete". Default is RollingUpdate. 464 // +optional 465 Type DaemonSetUpdateStrategyType `json:"type,omitempty" protobuf:"bytes,1,opt,name=type"` 466 467 // Rolling update config params. Present only if type = "RollingUpdate". 468 //--- 469 // TODO: Update this to follow our convention for oneOf, whatever we decide it 470 // to be. Same as Deployment `strategy.rollingUpdate`. 471 // See https://github.com/kubernetes/kubernetes/issues/35345 472 // +optional 473 RollingUpdate *RollingUpdateDaemonSet `json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"` 474} 475 476type DaemonSetUpdateStrategyType string 477 478const ( 479 // Replace the old daemons by new ones using rolling update i.e replace them on each node one after the other. 480 RollingUpdateDaemonSetStrategyType DaemonSetUpdateStrategyType = "RollingUpdate" 481 482 // Replace the old daemons only when it's killed 483 OnDeleteDaemonSetStrategyType DaemonSetUpdateStrategyType = "OnDelete" 484) 485 486// Spec to control the desired behavior of daemon set rolling update. 487type RollingUpdateDaemonSet struct { 488 // The maximum number of DaemonSet pods that can be unavailable during the 489 // update. Value can be an absolute number (ex: 5) or a percentage of total 490 // number of DaemonSet pods at the start of the update (ex: 10%). Absolute 491 // number is calculated from percentage by rounding up. 492 // This cannot be 0. 493 // Default value is 1. 494 // Example: when this is set to 30%, at most 30% of the total number of nodes 495 // that should be running the daemon pod (i.e. status.desiredNumberScheduled) 496 // can have their pods stopped for an update at any given 497 // time. The update starts by stopping at most 30% of those DaemonSet pods 498 // and then brings up new DaemonSet pods in their place. Once the new pods 499 // are available, it then proceeds onto other DaemonSet pods, thus ensuring 500 // that at least 70% of original number of DaemonSet pods are available at 501 // all times during the update. 502 // +optional 503 MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty" protobuf:"bytes,1,opt,name=maxUnavailable"` 504} 505 506// DaemonSetSpec is the specification of a daemon set. 507type DaemonSetSpec struct { 508 // A label query over pods that are managed by the daemon set. 509 // Must match in order to be controlled. 510 // It must match the pod template's labels. 511 // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors 512 Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,1,opt,name=selector"` 513 514 // An object that describes the pod that will be created. 515 // The DaemonSet will create exactly one copy of this pod on every node 516 // that matches the template's node selector (or on every node if no node 517 // selector is specified). 518 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template 519 Template v1.PodTemplateSpec `json:"template" protobuf:"bytes,2,opt,name=template"` 520 521 // An update strategy to replace existing DaemonSet pods with new pods. 522 // +optional 523 UpdateStrategy DaemonSetUpdateStrategy `json:"updateStrategy,omitempty" protobuf:"bytes,3,opt,name=updateStrategy"` 524 525 // The minimum number of seconds for which a newly created DaemonSet pod should 526 // be ready without any of its container crashing, for it to be considered 527 // available. Defaults to 0 (pod will be considered available as soon as it 528 // is ready). 529 // +optional 530 MinReadySeconds int32 `json:"minReadySeconds,omitempty" protobuf:"varint,4,opt,name=minReadySeconds"` 531 532 // The number of old history to retain to allow rollback. 533 // This is a pointer to distinguish between explicit zero and not specified. 534 // Defaults to 10. 535 // +optional 536 RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty" protobuf:"varint,6,opt,name=revisionHistoryLimit"` 537} 538 539// DaemonSetStatus represents the current status of a daemon set. 540type DaemonSetStatus struct { 541 // The number of nodes that are running at least 1 542 // daemon pod and are supposed to run the daemon pod. 543 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/ 544 CurrentNumberScheduled int32 `json:"currentNumberScheduled" protobuf:"varint,1,opt,name=currentNumberScheduled"` 545 546 // The number of nodes that are running the daemon pod, but are 547 // not supposed to run the daemon pod. 548 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/ 549 NumberMisscheduled int32 `json:"numberMisscheduled" protobuf:"varint,2,opt,name=numberMisscheduled"` 550 551 // The total number of nodes that should be running the daemon 552 // pod (including nodes correctly running the daemon pod). 553 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/ 554 DesiredNumberScheduled int32 `json:"desiredNumberScheduled" protobuf:"varint,3,opt,name=desiredNumberScheduled"` 555 556 // The number of nodes that should be running the daemon pod and have one 557 // or more of the daemon pod running and ready. 558 NumberReady int32 `json:"numberReady" protobuf:"varint,4,opt,name=numberReady"` 559 560 // The most recent generation observed by the daemon set controller. 561 // +optional 562 ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,5,opt,name=observedGeneration"` 563 564 // The total number of nodes that are running updated daemon pod 565 // +optional 566 UpdatedNumberScheduled int32 `json:"updatedNumberScheduled,omitempty" protobuf:"varint,6,opt,name=updatedNumberScheduled"` 567 568 // The number of nodes that should be running the 569 // daemon pod and have one or more of the daemon pod running and 570 // available (ready for at least spec.minReadySeconds) 571 // +optional 572 NumberAvailable int32 `json:"numberAvailable,omitempty" protobuf:"varint,7,opt,name=numberAvailable"` 573 574 // The number of nodes that should be running the 575 // daemon pod and have none of the daemon pod running and available 576 // (ready for at least spec.minReadySeconds) 577 // +optional 578 NumberUnavailable int32 `json:"numberUnavailable,omitempty" protobuf:"varint,8,opt,name=numberUnavailable"` 579 580 // Count of hash collisions for the DaemonSet. The DaemonSet controller 581 // uses this field as a collision avoidance mechanism when it needs to 582 // create the name for the newest ControllerRevision. 583 // +optional 584 CollisionCount *int32 `json:"collisionCount,omitempty" protobuf:"varint,9,opt,name=collisionCount"` 585 586 // Represents the latest available observations of a DaemonSet's current state. 587 // +optional 588 // +patchMergeKey=type 589 // +patchStrategy=merge 590 Conditions []DaemonSetCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,10,rep,name=conditions"` 591} 592 593type DaemonSetConditionType string 594 595// TODO: Add valid condition types of a DaemonSet. 596 597// DaemonSetCondition describes the state of a DaemonSet at a certain point. 598type DaemonSetCondition struct { 599 // Type of DaemonSet condition. 600 Type DaemonSetConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=DaemonSetConditionType"` 601 // Status of the condition, one of True, False, Unknown. 602 Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=k8s.io/api/core/v1.ConditionStatus"` 603 // Last time the condition transitioned from one status to another. 604 // +optional 605 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"` 606 // The reason for the condition's last transition. 607 // +optional 608 Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"` 609 // A human readable message indicating details about the transition. 610 // +optional 611 Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"` 612} 613 614// +genclient 615// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 616 617// DaemonSet represents the configuration of a daemon set. 618type DaemonSet struct { 619 metav1.TypeMeta `json:",inline"` 620 // Standard object's metadata. 621 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 622 // +optional 623 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 624 625 // The desired behavior of this daemon set. 626 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 627 // +optional 628 Spec DaemonSetSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 629 630 // The current status of this daemon set. This data may be 631 // out of date by some window of time. 632 // Populated by the system. 633 // Read-only. 634 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 635 // +optional 636 Status DaemonSetStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 637} 638 639const ( 640 // DefaultDaemonSetUniqueLabelKey is the default label key that is added 641 // to existing DaemonSet pods to distinguish between old and new 642 // DaemonSet pods during DaemonSet template updates. 643 DefaultDaemonSetUniqueLabelKey = ControllerRevisionHashLabelKey 644) 645 646// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 647 648// DaemonSetList is a collection of daemon sets. 649type DaemonSetList struct { 650 metav1.TypeMeta `json:",inline"` 651 // Standard list metadata. 652 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 653 // +optional 654 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 655 656 // A list of daemon sets. 657 Items []DaemonSet `json:"items" protobuf:"bytes,2,rep,name=items"` 658} 659 660// +genclient 661// +genclient:method=GetScale,verb=get,subresource=scale,result=k8s.io/api/autoscaling/v1.Scale 662// +genclient:method=UpdateScale,verb=update,subresource=scale,input=k8s.io/api/autoscaling/v1.Scale,result=k8s.io/api/autoscaling/v1.Scale 663// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 664 665// ReplicaSet ensures that a specified number of pod replicas are running at any given time. 666type ReplicaSet struct { 667 metav1.TypeMeta `json:",inline"` 668 669 // If the Labels of a ReplicaSet are empty, they are defaulted to 670 // be the same as the Pod(s) that the ReplicaSet manages. 671 // Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 672 // +optional 673 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 674 675 // Spec defines the specification of the desired behavior of the ReplicaSet. 676 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 677 // +optional 678 Spec ReplicaSetSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 679 680 // Status is the most recently observed status of the ReplicaSet. 681 // This data may be out of date by some window of time. 682 // Populated by the system. 683 // Read-only. 684 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 685 // +optional 686 Status ReplicaSetStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 687} 688 689// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 690 691// ReplicaSetList is a collection of ReplicaSets. 692type ReplicaSetList struct { 693 metav1.TypeMeta `json:",inline"` 694 // Standard list metadata. 695 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds 696 // +optional 697 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 698 699 // List of ReplicaSets. 700 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller 701 Items []ReplicaSet `json:"items" protobuf:"bytes,2,rep,name=items"` 702} 703 704// ReplicaSetSpec is the specification of a ReplicaSet. 705type ReplicaSetSpec struct { 706 // Replicas is the number of desired replicas. 707 // This is a pointer to distinguish between explicit zero and unspecified. 708 // Defaults to 1. 709 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/#what-is-a-replicationcontroller 710 // +optional 711 Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"` 712 713 // Minimum number of seconds for which a newly created pod should be ready 714 // without any of its container crashing, for it to be considered available. 715 // Defaults to 0 (pod will be considered available as soon as it is ready) 716 // +optional 717 MinReadySeconds int32 `json:"minReadySeconds,omitempty" protobuf:"varint,4,opt,name=minReadySeconds"` 718 719 // Selector is a label query over pods that should match the replica count. 720 // Label keys and values that must match in order to be controlled by this replica set. 721 // It must match the pod template's labels. 722 // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors 723 Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,2,opt,name=selector"` 724 725 // Template is the object that describes the pod that will be created if 726 // insufficient replicas are detected. 727 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template 728 // +optional 729 Template v1.PodTemplateSpec `json:"template,omitempty" protobuf:"bytes,3,opt,name=template"` 730} 731 732// ReplicaSetStatus represents the current status of a ReplicaSet. 733type ReplicaSetStatus struct { 734 // Replicas is the most recently oberved number of replicas. 735 // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/#what-is-a-replicationcontroller 736 Replicas int32 `json:"replicas" protobuf:"varint,1,opt,name=replicas"` 737 738 // The number of pods that have labels matching the labels of the pod template of the replicaset. 739 // +optional 740 FullyLabeledReplicas int32 `json:"fullyLabeledReplicas,omitempty" protobuf:"varint,2,opt,name=fullyLabeledReplicas"` 741 742 // The number of ready replicas for this replica set. 743 // +optional 744 ReadyReplicas int32 `json:"readyReplicas,omitempty" protobuf:"varint,4,opt,name=readyReplicas"` 745 746 // The number of available replicas (ready for at least minReadySeconds) for this replica set. 747 // +optional 748 AvailableReplicas int32 `json:"availableReplicas,omitempty" protobuf:"varint,5,opt,name=availableReplicas"` 749 750 // ObservedGeneration reflects the generation of the most recently observed ReplicaSet. 751 // +optional 752 ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"` 753 754 // Represents the latest available observations of a replica set's current state. 755 // +optional 756 // +patchMergeKey=type 757 // +patchStrategy=merge 758 Conditions []ReplicaSetCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,6,rep,name=conditions"` 759} 760 761type ReplicaSetConditionType string 762 763// These are valid conditions of a replica set. 764const ( 765 // ReplicaSetReplicaFailure is added in a replica set when one of its pods fails to be created 766 // due to insufficient quota, limit ranges, pod security policy, node selectors, etc. or deleted 767 // due to kubelet being down or finalizers are failing. 768 ReplicaSetReplicaFailure ReplicaSetConditionType = "ReplicaFailure" 769) 770 771// ReplicaSetCondition describes the state of a replica set at a certain point. 772type ReplicaSetCondition struct { 773 // Type of replica set condition. 774 Type ReplicaSetConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=ReplicaSetConditionType"` 775 // Status of the condition, one of True, False, Unknown. 776 Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=k8s.io/api/core/v1.ConditionStatus"` 777 // The last time the condition transitioned from one status to another. 778 // +optional 779 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"` 780 // The reason for the condition's last transition. 781 // +optional 782 Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"` 783 // A human readable message indicating details about the transition. 784 // +optional 785 Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"` 786} 787 788// +genclient 789// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 790 791// ControllerRevision implements an immutable snapshot of state data. Clients 792// are responsible for serializing and deserializing the objects that contain 793// their internal state. 794// Once a ControllerRevision has been successfully created, it can not be updated. 795// The API Server will fail validation of all requests that attempt to mutate 796// the Data field. ControllerRevisions may, however, be deleted. Note that, due to its use by both 797// the DaemonSet and StatefulSet controllers for update and rollback, this object is beta. However, 798// it may be subject to name and representation changes in future releases, and clients should not 799// depend on its stability. It is primarily for internal use by controllers. 800type ControllerRevision struct { 801 metav1.TypeMeta `json:",inline"` 802 // Standard object's metadata. 803 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 804 // +optional 805 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 806 807 // Data is the serialized representation of the state. 808 Data runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,2,opt,name=data"` 809 810 // Revision indicates the revision of the state represented by Data. 811 Revision int64 `json:"revision" protobuf:"varint,3,opt,name=revision"` 812} 813 814// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 815 816// ControllerRevisionList is a resource containing a list of ControllerRevision objects. 817type ControllerRevisionList struct { 818 metav1.TypeMeta `json:",inline"` 819 820 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 821 // +optional 822 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 823 824 // Items is the list of ControllerRevisions 825 Items []ControllerRevision `json:"items" protobuf:"bytes,2,rep,name=items"` 826} 827