Commit Graph

15 Commits

Author SHA1 Message Date
Justin SB 0567f1e464 prunev2: Implement basic pruning
Implement the basic prune strategy where we find-by-label and then
delete unknown objects.

Kubernetes-commit: f17a319dc60374a46be1b37a453227d134ac479e
2023-02-22 21:40:25 -05:00
Justin SB a7db218701 cleanup: replace deprecated sets.String
Replace with generics, including using the more-accurate type
types.UID for visitedUids.

Kubernetes-commit: 0b5fa1934250307c4df7c6bcabf6a6b1b00e73d9
2023-03-01 09:05:59 -05:00
Paco Xu 89470f4910 kubectl apply: warning that in future release, prune will ignores no-namespaced resource if -n is not empty
Signed-off-by: Paco Xu <paco.xu@daocloud.io>

Kubernetes-commit: f3b49adadf2182ba0a7fb930e6340da725053520
2022-11-09 07:43:03 +08:00
Arda Güçlü ab3928acd9 Refactor diff/prune
This PR does some refactors for diff/prune;

- GetRESTMappings takes value array instead reference
- Move getObjectName into diff instead prune
- License, etc. changes

Kubernetes-commit: 6c449dd272c95f2aeb3bb77e67d312d8df21bd62
2021-11-08 11:22:10 +03:00
Arda Güçlü 3f914a34f1 Add new unit tests for diff/prune
Kubernetes-commit: 17de414905fb3463ec17ec63f40180fa09965d98
2021-09-24 09:40:26 +03:00
Maciej Szulik 0173fa9c51 Clean apply's prune and kube addons with batch/v1 CronJob
Kubernetes-commit: 1619e8eb953042facabc448bf6cbc67eeb46d5cc
2021-06-02 14:27:29 +02:00
Ricardo Pchevuzinske Katz 922a8a5058 Remove extensions v1beta1 from addon manager and kubectl prune
Kubernetes-commit: 25f3cf55509acdd3bd31bc9ca028c5d5a3bd22b0
2021-02-05 09:38:28 -03:00
zhouya0 8411619cbf Support kubectl delete foreground
Kubernetes-commit: 383b5f676670d99dc1fba4254ba7f6a81a052ba3
2020-07-23 18:45:59 +08:00
Julian V. Modesto 0d395d7c98 Make client-side apply safer
- Remove the ServerDryRun field and delegate it entirely to the resource.Helper
- Use resource.Helper for deletions (as in `kubectl apply --force`)
instead of using the pruner's method that uses a dynamic client
- Reduce the resource.Helpers and times we check for server-side dry-run
in apply

Kubernetes-commit: f0eb68c0cfcff6d50d9d5ec278f96820e3cb3f9a
2020-04-02 18:26:32 -04:00
Tatsuhiro Tsujikawa e7bb62301f Restore the ability to `kubectl apply --prune` without -n flag
Before https://github.com/kubernetes/kubernetes/pull/83084, `kubectl
apply --prune` can prune resources in all namespaces specified in
config files.  After that PR got merged, only a single namespace is
considered for pruning.  It is OK if namespace is explicitly specified
by --namespace option, but what the PR does is use the default
namespace (or from kubeconfig) if not overridden by command line flag.
That breaks the existing usage of `kubectl apply --prune` without
--namespace option.  If --namespace is not used, there is no error,
and no one notices this issue unless they actually check that pruning
happens.  This issue also prevents resources in multiple namespaces in
config file from being pruned.

kubectl 1.16 does not have this bug.  Let's see the difference between
kubectl 1.16 and kubectl 1.17.  Suppose the following config file:

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: foo
  namespace: a
  labels:
    pl: foo
data:
  foo: bar
---
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: bar
  namespace: a
  labels:
    pl: foo
data:
  foo: bar
```

Apply it with `kubectl apply -f file`.  Then comment out ConfigMap foo
in this file.  kubectl 1.16 prunes ConfigMap foo with the following
command:

$ kubectl-1.16 apply -f file -l pl=foo --prune
configmap/bar configured
configmap/foo pruned

But kubectl 1.17 does not prune ConfigMap foo with the same command:

$ kubectl-1.17 apply -f file -l pl=foo --prune
configmap/bar configured

With this patch, kubectl once again can prune the resource as before.

Kubernetes-commit: 7af3b01f24edfde34e42640ee565a5a6bb66ce26
2020-03-27 01:11:36 +00:00
Jordan Liggitt 0c62c9a83a client-go dynamic client: add context to callers
Kubernetes-commit: b7c2faf26c2a25427794478c6265e6d55e8acb5a
2020-03-06 10:17:41 -05:00
Jordan Liggitt 1de89515de client-go dynamic client: update DeleteOptions callers
Kubernetes-commit: b19dc3a474e840340cb357f5ea9f4e575bad888d
2020-03-06 10:20:40 -05: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
Sean Sullivan 641631dfad Moves visitedUids and visitedNamespaces (used for pruning) into ApplyOptions
Kubernetes-commit: 4e45421f610eb881a03c0d82fca038788db12b08
2019-12-17 14:19:00 -08:00
Sean Sullivan 65d873e277 Moved prune functionality into its own file.
Kubernetes-commit: e38e320222a1f44373ab3eaea8713f4772b26f6b
2019-12-16 16:13:39 -08:00