Commit Graph

45 Commits

Author SHA1 Message Date
Jefftree 03a47d93ec use OpenAPIV3 for kubectl diff
Kubernetes-commit: e7216c6623049d713fbf7cc04e2c42eb957a607e
2023-09-15 17:53:10 -04:00
Frederic Branczyk eca0d6a8b1 kubectl: Allow parallelizing diffing
Kubernetes-commit: 1cfb932111e53e296a3b0f001b6f5d03f212f32f
2023-06-05 13:18:49 +02:00
Chris Bandy facdb16b53 Replace os.Setenv with testing.T.Setenv in tests
T.Setenv ensures that the environment is returned to its prior state
when the test ends. It also panics when called from a parallel test to
prevent racy test interdependencies.

Kubernetes-commit: 2181eea48435310d1b6e366ea8db2968c4941b93
2023-04-15 10:09:47 -05:00
Arda Güçlü 3f05cfcd78 Migrate genericclioptions.IOStreams usage to genericiooptions
Kubernetes-commit: 00c30941260a27e6929aef84c7fdbc8f1508518c
2023-04-05 14:07:46 +03:00
justinsb 180519d83a kubectl diff: refactor tracker into a separate type
This means that we can reuse the logic even if we swap out the pruner.

Kubernetes-commit: 9c5c8b243d1a6524e38d847c54de3046b332d373
2023-03-14 12:06:44 +00: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
Daniel Lenar 5c8d4bb380 Use label selector for filtering out resources when pruning.
Matches same behavior as for kubectl apply

Signed-off-by: Daniel Lenar <dlenar@vailsys.com>

Kubernetes-commit: d53af227870a8e4434a0bf2f58770ec4dbec241f
2023-01-05 13:55:39 -06:00
petya.slavcheva1 cfebade04e Replace os.exit in diff
Kubernetes-commit: 2dce194e1647396fa7bbd926bc8b007e91f09dee
2022-12-13 14:27:35 +01:00
Sean Sullivan 6dde41fea6 Removes unnecessary dry run verifier
Kubernetes-commit: 530f65d6fd5af81c0691143fbf2c00d440476bb9
2022-12-05 16:25:12 -08:00
inosato 8272d71ba6 Remove ioutil from kubectl
Signed-off-by: inosato <si17_21@yahoo.co.jp>

Kubernetes-commit: 774ab1349bfd553c97a99b992e9f38659f541c84
2022-07-30 22:31:16 +09: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
Brian Pursley 7a39dfc2d3 Change kubectl diff to exclude managedFields by default
Changes kubectl diff to exclude managedFields by default.
Adds a new --show-managed-fields flag that allows you to
include managed fields in the diff.

Kubernetes-commit: e88470c31f74cbb1ed685ef1bc2ba91e74fc1c5e
2022-07-27 12:53:32 -04:00
Arda Güçlü 81a25f37b5 Set validate functions requiring no parameters for all commands
Validate function is used to validate command options and should not get
any additional parameter. To preserve compatibility across all
kubectl commands, this PR removes all parameters in validate functions.

Kubernetes-commit: 8fb423bfabe0d53934cc94c154c7da2dc3ce1332
2022-05-17 11:38:20 +03:00
Arda Güçlü 1474736be3 Remove DiscoveryClient from diff command
This PR removes `DiscoveryClient` field in diff command. Because
it is not used anywhere in diff command.

Kubernetes-commit: 5fdf97ad8e3a9b7a16479a5ec4ebff3d38c55a18
2022-03-08 09:59:49 +03:00
Kevin Delgado 7e681490ec Generalize dry run verify to arbitrary query param
Kubernetes-commit: d6c83281bc696474a76365a879f2255b8b568786
2022-03-09 14:51:50 +00:00
Aram Peres 8e80d8fd7e Cleanup kubectl label selectors with 'cmdutil.AddLabelSelectorFlagVar'
Kubernetes-commit: 8f8138bc35f59ef04b77a3520d8d1065603ccdb7
2022-01-06 23:28:44 -05: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ü 2d0f4303f1 Get object name correctly for pruned resources
Kubernetes-commit: a19bd5e47436c1f0a2aea20c4a992da18f8ba480
2021-10-06 17:01:19 +03:00
Arda Güçlü 292510bc0b Add pruner constructor, tweak DiffOptions
Kubernetes-commit: 05100c0e49328cd149e96aa78fefc91c8c97ffee
2021-09-30 11:26:40 +03:00
Arda Güçlü 3f914a34f1 Add new unit tests for diff/prune
Kubernetes-commit: 17de414905fb3463ec17ec63f40180fa09965d98
2021-09-24 09:40:26 +03:00
Arda Güçlü ff5d018049 Introduce new prune parameter into diff command
This PR introduces new prune and it's dependent parameters to simulate
`kubectl apply --prune` command.

Kubernetes-commit: 56c19f1056ad6d4a4bb926fe90e37f56a31c4e2f
2021-09-17 15:27:21 +03:00
Arda Güçlü 8307ca4a3c Add diff command return status code greater than 1 when flags invalid
This PR adds flagerror handler function to detect when flags are invalid.
Default flag handler returns status code 1. However, diff command embraces
this status code as changes are found. By overriding flag errors,
this PR shows same message with default case and returns status code 2.

Kubernetes-commit: 4f0848520d4cdd679c76479949546002c5935e3c
2021-10-04 13:02:34 +03:00
Andrea Hoffer 09ed00ef49 Minor adjustments to descriptions and example text
Kubernetes-commit: 6b736f348483bb6b20d4633319305960f4d9e4c1
2021-07-06 15:05:26 -04:00
ZhengYuan Loo c155b7bb87 feat: masked secrets in kubectl diff output (#96084)
* fix tests

* add changes

Kubernetes-commit: 0cbf00ad018d5104e438b5693fde435fa06e30c9
2021-05-18 14:19:27 +00:00
Masashi Honma c011a4ab83 Fix a unit test failure in non English languages
This is a result in Japanese language.

$ make test WHAT=./staging/src/k8s.io/kubectl/pkg/cmd/diff
[0402 07:24:05] Running tests without code coverage
FAIL: TestDiffProgram (0.00s)
    diff_test.go:73: stdout = "ファイル /dev/zero と /dev/zero は同一です\n", expected = Files /dev/zero and /dev/zero are identical
        "
FAIL
FAIL	k8s.io/kubernetes/staging/src/k8s.io/kubectl/pkg/cmd/diff	0.045s
FAIL
make: *** [Makefile:184: test] エラー 1

Kubernetes-commit: 6b9ff98dd72503e0cad5c626f67c716d465d18b2
2021-04-02 15:59:47 +09:00
Julian V. Modesto 04f62ffb0b Cache the OpenAPI schema for server-side dry-run.
Currently, server-side dry-run fetches the OpenAPI schema for every
single object.

This change fetches the OpenAPI schema only once.

Kubernetes-commit: caa158610dfb53de3582ed6df0eb37359206fc66
2021-01-19 16:36:14 -05:00
Douglas Schilling Landgraf 2560231a8d kubectl diff: update regex to allow equal param
When using GNU diffutils, some commands (e.g. --color[=WHEN])
requires an equal sign.

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

Kubernetes-commit: 722751accf7607f4d0573778e85027c63e1802ce
2021-01-18 23:22:36 -05:00
Sai Harsha Kottapalli 61b85bce7c warn user about resource being deleted
Kubernetes-commit: 7b0ef888f3205f06c871cff901ef0f5b8fdb250c
2020-10-11 02:21:32 +05:30
Douglas Schilling Landgraf bafd13fd9f kubectl: allow users to use args with KUBECTL_EXTERNAL_DIFF
Currently, if users try to use external diff command with arguments
will fail because the entire command won't be available through $PATH.
This patch allow users to use external diff tools with args (or not)
via KUBECTL_EXTERNAL_DIFF env.

Reference: https://github.com/kubernetes/kubectl/issues/937

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

Kubernetes-commit: a6158c01b9add5b580059d24cb66e54c37ea2531
2020-10-04 23:29:27 -04:00
Seth Pollack b55288a363 add labels to diff command
Kubernetes-commit: 75af2fca6125516dff42e9825ceea89367986f78
2020-05-07 14:30:00 -04: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
Davanum Srinivas 445ad1366b switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 442a69c3bdf6fe8e525b05887e57d89db1e2f3a5
2020-04-17 15:25:06 -04:00
Julian V. Modesto 415a73888a Set kubectl field manager names
Kubernetes-commit: 360c348d0eb5be8c7c9720d5bfda16dbe04e8d15
2020-03-04 22:04:01 -05:00
Julian V. Modesto 1cfa7c66b3 Ensure diff doesn't persist patches
Kubernetes-commit: 9c0320f1bfd8edfb11c283b3fd422dc6e49360c5
2020-04-02 17:14:17 -04:00
Julian V. Modesto 87fc988437 Set field manager for kubectl diff --server-side.
Bonus: check diff only dry-runs without persisting.

Co-authored-by: Takahiro HATORI <tahatori@zlab.co.jp>

Kubernetes-commit: bacc2c49605f608d3f919109e0c37ebf6e1d7036
2020-03-02 14:06:50 -05:00
zhouya0 9c14935e27 Add kubectl diff exit code doc
Kubernetes-commit: 527e66fc2829917444d874771142fdd834feb8d6
2020-02-04 17:22:23 +08:00
Antoine Pelisse 4c36396b35 kubectl-diff: Return non-1 errors on kubectl failures
Currently, diff AND kubectl can return 1 errors either when diff finds
differences, or when kubectl fails something. It also prints an ugly
error when diff finds a differences, since 1 is treated as an error.

Two things this PR does:

1. If diff returns 1, then do not treat it as an error, and exit with
exit code 1. It no longer prints the ugly error.

2. Kubectl errors are +1'd so that they never return 1 which shouldn't
be considered an error.

We need to update the documentation accordingly, to mention that
`KUBECTL_EXTERNAL_DIFF` programs must also follow the convention of
using one as their exit code for changes detected.

Kubernetes-commit: f2b21f08d95291212ba8987aa9d446c02a96089a
2020-01-21 13:52:41 -08:00
Julian V. Modesto a3f7877cd1 Support DryRun in cli-runtime REST Helper.
- Move TestSupportsDryRun to cli-runtime
- Move TestDryRunVerifier to cli-runtime
- Add OpenAPI schema for testdata to cli-runtime
- Use Helper.DryRun and DryRunVerifier for Apply
- Add WithOptions methods to Helper

Kubernetes-commit: 6bea0e469bcfe4967cbf2656a998d60e0b684747
2019-12-18 22:00:34 -05:00
Antoine Pelisse 104e4d1e7a Improve error message when diff binary is not in PATH
Kubernetes-commit: c1a4cd9c75b4ed476ec3ed1b27a785dd1685a6e3
2020-01-17 16:17:41 -08:00
louisgong ae926dc56e fix kubectl diff panic
Kubernetes-commit: 4f13f2739a3a33c7ed4b86b98054972c0fde4579
2019-11-09 20:34:51 +08:00
David Symonds deabbd435b Fix description of diff flags.
Running `diff -u` produces a unified diff. It isn't related to Unicode.
Also, `diff -N` treats _absent_ files as empty, not new files.

Kubernetes-commit: 0af2dedd96e973f4ed59af0cc325a70ca0b9100a
2019-05-22 13:34:30 +10:00
Antoine Pelisse 4574b365f9 Rename --experimental-* flags to --* for server-side apply
Kubernetes-commit: a3f4e6e933d3292b3921cdc7b60d7ae019ca1580
2019-08-26 09:09:40 -07:00
Sean Sullivan 1483769081 Update gofmt
Kubernetes-commit: e2cae2344486af198f8ab38e4dd97d4f24dfd190
2019-08-01 13:14:06 -07:00
Sean Sullivan 5b48717f2d Update import statements to reflect code move
Kubernetes-commit: acece3c2964115a4f29a43e368ad5de59dbbc258
2019-08-01 11:10:05 -07:00
Sean Sullivan c6063dd846 Move pkg/kubectl/cmd/{command} to staging
Kubernetes-commit: 0e0ea523392f1121f61f99ac30a9bc2043eaed90
2019-08-01 11:01:40 -07:00