Commit Graph

49 Commits

Author SHA1 Message Date
Omer Aplatony 120105a0a9 kubectl: add test coverage for cordon command (#129202)
* kubectl: add test coverage for cordon command

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* using cmp.Diff

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

---------

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

Kubernetes-commit: 3ec97a445f036a38bfec6291dee661954138bac9
2024-12-17 06:34:43 +00:00
Omer Aplatony c329ccff7c Update waitForDelete to use PollUntilContextTimeout
Signed-off-by: Omer Aplatony <omerap12@gmail.com>

Kubernetes-commit: bba055067e6283f94ee05cedeb33dacafe4a1094
2024-10-05 22:07:37 +03:00
tux bd15ba4612 fix: use the getContext() method for evicting pods
Kubernetes-commit: cc244e8d1d9d57818816e8e35651b78b0c6f9709
2024-08-21 14:08:57 +08:00
Brian Pursley 2687c08c5c Fix kubectl drain error handling bug.
Fixed a bug where kubectl drain would consider a pod as having been deleted if an error occurs while calling the API.

Kubernetes-commit: 4aecb151b8301a6fc69f63c08f640c7b2b4289fc
2024-01-04 08:53:57 -05:00
ithrael b7a900337d fix(kubectl): delete pod declare no controllor note
Kubernetes-commit: c7549fe340dfa3c038addf84e61f7a923c6e39d5
2023-08-24 23:51:14 +08:00
adil ghaffar e112354038 adding more callbacks in kubedrain helper
Kubernetes-commit: 0323fe42e23aee176ff14f3385bc15e81216c7bb
2023-04-20 16:16:11 +03:00
W. Trevor King 7ad33aa9fe kubectl/pkg/drain: Include namespace in evictPods return error
And also in the terminating-namespace log output.  This makes it
easier to track down drain-blocking pods, without having to hunt
around in earlier logs for 'evicting pod ...' messages.  Before this
change, caller logs might look like:

  evicting pod {namespace}/{name}
  ...
  error when waiting for pod "{name}" terminating: global timeout reached: 20s

With this change, they will look like:

  evicting pod {namespace}/{name}
  ...
  error when waiting for pod "{name}" in namespace "{namespace}" to terminate: global timeout reached: 20s

Kubernetes-commit: b6318d4e5b9b8eb0d2e2d5a8568df14817733f26
2023-02-07 13:10:30 -08:00
Sean Sullivan 6dde41fea6 Removes unnecessary dry run verifier
Kubernetes-commit: 530f65d6fd5af81c0691143fbf2c00d440476bb9
2022-12-05 16:25:12 -08:00
Kevin Delgado 7e681490ec Generalize dry run verify to arbitrary query param
Kubernetes-commit: d6c83281bc696474a76365a879f2255b8b568786
2022-03-09 14:51:50 +00:00
W. Trevor King 5ff8356c5b kubectl drain: Generic "declare a controller" message
When it initially landed in kubernetes/kubernetes@c6e9ad066e (Initial
node drain implementation for #3885, 2015-08-30,
kubernetes/kubernetes#16698), the drain logic looked in a created-by
annotation for recognized kinds [1], so listing the set of recognized
kinds was a clear approach.

Sometime later, the source moved into ownerReferences, but the
hard-coded set of recognized controller kinds remained.

When kubernetes/kubernetes@2f1108451f (Remove hard-coded
pod-controller check, 2017-12-05, kubernetes/kubernetes#56864) removed
the hard-coded set of recognized controller kinds, it should have also
updated these messages to remove stale references to the previous
hard-coded values.  This commit catches the message strings up with
that commit.

[1]: c6e9ad066e (diff-211259b8a8ec42f105264c10897dad48029badb538684e60e43eaead68c3d219R216)

Kubernetes-commit: 587f4f04cc5fc18f4e85ed6a4a06bbf1bfee0496
2022-02-23 16:26:59 -08:00
Jack 5fb22b2ab8 RunCordonOrUncordon error if drainer has nil Ctx or Client
Kubernetes-commit: ee02f5ddc42a67166c91e539fe98cc6541db668e
2021-09-27 14:20:24 -07:00
Bronson Mirafuentes 1d62bce235 wrap error from RunCordonOrUncordon
Kubernetes-commit: 297432f0e92479cfbb62d182d9d20c1833a3521c
2022-01-25 10:34:47 -08:00
yuzhiquan c74a1185c3 remove ignore error flag for drain, and set this feature as default
Kubernetes-commit: f54d2a0dd1dd5c143fb32dae5c627dba87d6df7e
2021-10-08 19:44:26 +08:00
Zhou Peng 7454a6489e [k8s.io/kubectl/pkg/drain/drain]: minor typo fixup
Signed-off-by: Zhou Peng <p@ctriple.cn>

Kubernetes-commit: 7e2d6301bf95893ea74116871d2c2f6392217105
2021-08-01 07:07:31 +08:00
Jordan Liggitt 49f840d934 kubectl: send policy/v1 evictions to servers that support it
Kubernetes-commit: f07fc213b07568442b22757b2220b80a5041cced
2021-04-01 22:50:59 -04:00
Katrina Verey ea308b60b6 Add --chunk-size flag to kubectl drain
Kubernetes-commit: 5200ff86d0983e42c3d2d5c0d830e96495516347
2021-03-19 08:32:37 -07:00
Sagar Muchhal 27325b0861 Adds actual context to node drainer code
Signed-off-by: Sagar Muchhal <muchhals@vmware.com>

Kubernetes-commit: 2e01560fd0c1fc6eec607c5a01022384feda67d6
2021-03-21 18:11:50 -07:00
Katrina Verey 5105e147ad Fix kubectl drain --dry-run=server
Adds missing type meta to PodDelete items

Kubernetes-commit: ff9ada1b550852c697af5250c90e8e4de69110e4
2021-03-12 16:26:48 -08:00
rkilingr 1d4a9f61b6 Provides capacity for make slice
* Providing capacity for slice decreases memory allocations performed

Kubernetes-commit: dfe29ae7f84dccb3a989ed1f5d73bde3f58d4ed8
2021-01-31 20:56:11 +05:30
yuzhiquan 7e8ba7c82e add ignore-errors flag, support none break drain in group
add warning msg

Kubernetes-commit: db264eaa6e2db5f344ec40dc6dd632ece8fe5768
2021-01-20 15:02:00 +08:00
Sagar Muchhal 72f141c577 Passes a context to the drain helper object
Enables the PatchOrReplace call for the cordon helper to accept a
user-supplied context to be used for the client.Patch/Update calls to
alter the node status while cordoning/uncordoning the node.

Signed-off-by: Sagar Muchhal <muchhals@vmware.com>

Kubernetes-commit: 017eaa519de5926fd75a9ddc61bedf2398b69653
2020-12-04 15:13:03 -08:00
Bryan Boreham 40c811e2d9 Comment default behaviour of GracePeriodSeconds
It took me a while to spot this subtlety.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

Kubernetes-commit: 7c764c8550121b48a6e2678700b6a80fa7d3e2f0
2020-11-23 17:46:14 +00:00
blade 9cc15e588a return success if cordon node by replace
Kubernetes-commit: c825e8ec16482ebbefc3ae96a26f4dcf924e750c
2019-12-12 20:20:29 +08:00
Douglas Schilling Landgraf 56ea9621b7 kubectl: deprecate --delete-local-data
The option --delete-local-data according with users is not clear.
This patch deprecate --delete-local-data in favor of --delete-emptydir-data.

Reference:
https://github.com/kubernetes/kubernetes/issues/80228

Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>

Kubernetes-commit: 625e47aaa2769d221c59e5b9b05b4ac97212719b
2020-09-25 17:33:45 -04:00
Amanda Hager Lopes de Andrade Katz 587d894118 Fixes high CPU usage in kubectl drain
Kubernetes-commit: de9c2c2090bbf66943022e902868a5457410af90
2020-10-02 16:02:12 -03:00
Michael Gugino a28f944c90 kubectl/drain add support for custom pod filters
Currently, there is no way to supply custom pod filters to
exclude pods meeting arbitrary criteria when using drain
as a library.

This commit adds the ability for developers to add custom
filters to the drain operation when utilizing drain
as a library.

This commit exports certain types that were previously
private to allow for better code reuse.

This commit also adds appropriate unit tests.

Kubernetes-commit: 85004f030dc3dceb9d15f41fdd607545758d5da2
2020-02-18 19:15:07 -05:00
Michael Gugino e5ddedb459 Handle eviction of pods in deleted namespace
If a pod is already marked deleted, and the eviction
api returns an unauthorized response, ignore that
error since the pod is marked for deletion already.

If the pod is not already marked deleted, retry.

Kubernetes-commit: 8d2a2ffe014ed06b5f8971e7f3dc25ec155e44d4
2020-08-12 16:15:54 -04:00
Ryan Phillips de06b92a12 drain: eviction creates in a deleting namespace will throw a forbidden error
we can safely ignore this error since a deleting namespace will delete
all pods

Kubernetes-commit: 93f62dad6c58bb41c396c48f54c0a73830779599
2020-03-20 14:43:33 -05:00
David Eads 25d0565d86 update drain message to include namespace for pod in kubectl get compatible format
Kubernetes-commit: 9655953000406ce413772ac7d5082c923e913bb4
2020-08-26 11:58:14 -04:00
Jordan Liggitt 197605389f Fix int->string casts
Kubernetes-commit: 124a5ddf725c4862520d8619017cac9db7a03522
2020-07-24 11:13:07 -04:00
Jordan Liggitt cfef71236e client-go: update expansions callers
Kubernetes-commit: d8abacba40a63395cc064452b09a244555536fca
2020-03-06 16:29:23 -05:00
Mike Danese 15efe80aa3 more artisanal fixes
Most of these could have been refactored automatically but it wouldn't
have been uglier. The unsophisticated tooling left lots of unnecessary
struct -> pointer -> struct transitions.

Kubernetes-commit: 76f85943787a5901a34a314a935712177edd2db0
2020-03-01 09:34:30 -08:00
Mike Danese 96c320d500 automated refactor
Kubernetes-commit: c58e69ec791e4dd8a1298d5c2cc0649cf9176f67
2020-03-01 09:24:42 -08:00
Julian V. Modesto f9460c5333 Use --dry-run=client,server in kubectl.
- Support --dry-run=server for subcommands apply, run, create, annotate,
expose, patch, label, autoscale, apply set-last-applied, drain, rollout undo
- Support --dry-run=server for set subcommands
  - image
  - resources
  - serviceaccount
  - selector
  - env
  - subject
- Support --dry-run=server for create subcommands.
  - clusterrole
  - clusterrolebinding
  - configmap
  - cronjob
  - job
  - deployment
  - namespace
  - poddisruptionbudget
  - priorityclass
  - quota
  - role
  - rolebinding
  - service
  - secret
  - serviceaccount
- Remove GetClientSideDryRun

Kubernetes-commit: 13b80b48cd02b8263d910f2423a1f5b92cdf7644
2020-01-30 20:23:33 -05:00
zhouya0 94b91c1d51 fix kubectl drain ignore daemonsets and others
Kubernetes-commit: e3c8add683a095f1bffef1b0ca413f1e42be7fe0
2020-01-19 14:28:53 +08:00
Mike Danese 29cd24b6cc generated: run refactor
Kubernetes-commit: 25651408aeadf38c3df7ea8c760e7519fd37d625
2020-02-08 12:30:21 -05:00
Mike Danese 71d8052cb0 generated: run refactor
Kubernetes-commit: 3aa59f7f3077642592dc8a864fcef8ba98699894
2020-02-07 18:16:47 -08:00
Michael Gugino a17d91f9f5 kubectl: remove unreachable code
This code cannot be reached and causes some external linters
to fail.

Kubernetes-commit: 46fd8fce45cfbbe5681a44872602da6daea80cf6
2019-10-23 11:20:40 -04:00
Michael Gugino ebda9f6262 kubectl/drain: add option skip-wait-for-delete-timeout
Currently, some circumstances may cause waitForDelete to
never succeed after the pod has been marked for deletion.
In particular, Nodes that are unresponsive and have
pods with local-storage will not be able to
successfully drain.

We should allow drain to ignore pods that have a
DeletionTimestamp older than a user-provided age.
This will allow controllers utilizing kubectl/drain
to optionally account for a pod that cannot be
removed due to a misbehaving node.

Kubernetes-commit: da53044abdf8c8a9771a5c3dfd861f0c4ec78c40
2019-11-23 20:00:06 -05:00
Sally O'Malley 6d309ed99e When running `kubectl drain` in dry-run, list warnings and pods that would be deleted.
Kubernetes-commit: 909300b8be909c48a68900c407de03be95555409
2019-09-12 14:31:09 -04:00
Michael Gugino feccbe3c28 kubectl/drain: add disable-eviction option
Currently, if eviction is supported during a drain operation,
eviction is always used.

This commit allows the user to specify disabling eviction.
This is particularly useful when you wish to ignore
PodDisruptionBudgets after a normal drain has failed for
some time.

Kubernetes-commit: 6c1d587d5142b95e6c169a198a086332a7e4d8ad
2019-11-23 11:18:52 -05:00
Michael Gugino fe592e7f80 kubectl/drain: Add context support
This commits allows specifying a context.Context
in the Helper type. This context is utilized to
cancel waitForDelete.

Kubernetes-commit: 8682e902f5487e04b893da7230125db0d7ae66b4
2019-11-23 13:58:59 -05:00
Ted Yu eb7c1bf189 Only put un-filtered pod in podDeleteList
Kubernetes-commit: 65c2f61806468d25795516d6077ce0c31c83adcd
2019-10-30 09:55:34 -07:00
ritho b0cd1c2290 Do some Kubectl optimizations suggested by the golangci linter
The tool golangci-lint gives a bunch of warnings. This PR solves the easier/less controversial ones, so the code is simpler and a little bit more optimal, since it removes some if conditions.

Kubernetes-commit: cd2adbe760641f844d84d411f9adcf17fb6982ff
2019-06-04 01:25:43 -05:00
Michael Gugino ff5adba11b Add timeout info to kubectl drain logging
Kubernetes-commit: 0088a9e6a8c47b2710fc49b82a912861cda8a554
2019-10-21 15:21:26 -04:00
Michael Gugino e09feee202 kubectl drain: avoid leaking goroutines
Recently, kubectl drain has been refactored to be consumeable
as a library.  Currently, if a pod cannot be evicted due
to PDBs, we will leak a goroutine.

This commit ensures the goroutine always exists.

Related-bug: https://github.com/kubernetes/kubernetes/issues/81333

Kubernetes-commit: 0e8998a040efe5dd82592911e739fe2e2258cfa3
2019-10-15 15:24:27 -04:00
Justin SB 75fdf29ade Add tests for newly exposed drain code
Kubernetes-commit: 4bba4449ae41a7889ad29da4bd1704ae8d19d126
2019-08-19 16:22:04 -04:00
Justin SB 3989dccd8b Make drain library more reusable
Move more functionality from the kubectl cmd to a package with
fewer dependencies.

Kubernetes-commit: c74f2f6a72bf6fe2718d1e386e4e08747f34fe7b
2019-07-11 13:28:25 -04:00
Sean Sullivan 200ba9edb8 Move pkg/kubectl/drain to staging
Kubernetes-commit: eaea71cf8449a804c762b96f6d278064c0926ae4
2019-07-24 21:10:54 -07:00