Commit Graph

922 Commits

Author SHA1 Message Date
Morten Torkildsen 6c2de94a5d Support ReconcileFailed status in printers 2021-12-07 15:12:52 +01:00
Morten Torkildsen a95e9f43ca Add e2e tests for reconciliation failure and timeout 2021-12-06 00:51:52 -08:00
Kubernetes Prow Robot 9e462c333d
Merge pull request #486 from mortent/HandleStalledResources
Avoid waiting for failed resources
2021-12-02 09:41:33 -08:00
Morten Torkildsen 703535fa6d Avoid waiting for stalled resources 2021-12-02 09:17:44 -08:00
Kubernetes Prow Robot 29c8e1cfd1
Merge pull request #489 from mortent/ReuseStatusReaders
Allow status readers to be reused between invocations
2021-12-01 17:27:33 -08:00
Morten Torkildsen bc9e8c1721 Allow status readers to be reused between invocations 2021-11-30 10:03:55 -08:00
Kubernetes Prow Robot 45a0b5b7e6
Merge pull request #479 from karlkfi/karl-error-string
fix: Make UnknownTypesError error more readable
2021-11-12 20:00:46 -08:00
Karl Isenberg c5452a84c9 fix: Make UnknownTypesError error more readable
- Fix regression from switch to GroupVersionKind from GroupKind
- New error string format: G/V/K, G/V/K
- Avoid K.G/V, which looks like but isn't R.G/V
2021-11-12 11:29:07 -08:00
Kubernetes Prow Robot 39f77432ba
Merge pull request #478 from karlkfi/karl-matcher-fix
fix: Make testutil.AssertEqual more like testify
2021-11-11 14:51:14 -08:00
Karl Isenberg 2ca6f199e4 fix: Make testutil.AssertEqual more like testify
- Swap actual and expected arguments
- Add optional Sprintf arguments
- Add messages to existing usages
2021-11-11 12:59:22 -08:00
Kubernetes Prow Robot 899a44405e
Merge pull request #471 from karlkfi/karl-example-test-failure
fix: Colorize example tests
2021-11-10 16:07:50 -08:00
Karl Isenberg de8f67c0a5 fix: Colorize example tests
- Exit on first test failure for each file
2021-11-10 13:52:31 -08:00
Kubernetes Prow Robot 65a56627e9
Merge pull request #449 from karlkfi/karl-wait-forever
feat: Always wait for reconciliation
2021-11-10 13:47:27 -08:00
Karl Isenberg c5636c0243 feat: Always wait for reconciliation
- Converted WaitTask to use a context for timeout/cancellation, to
  improve readability and reduce error cases. Now it only sends
  TaskResult events from one place, removing the need for a token to
  silence subsequent complete() calls.
- Add pending object tracking to WaitTask to ensure all objects are
  accounted for at least one WaitEvent.
- Upgraded applier tests to use full event comparison, for better signal
  on breaking changes.
- Enhanced task tests to consume all events before validating and test
  actual event output.
- Add set sorting to graph.SortObjs, to make wait event ordering more
  consistent, to make testing easier.

BREAKING CHANGE: wait tasks always execute after apply/prune/delete (except dry runs)
BREAKING CHANGE: wait tasks default to waiting until cancelled (previously 1m default)
2021-11-10 12:34:54 -08:00
Kubernetes Prow Robot d2c4aa9b88
Merge pull request #476 from karlkfi/karl-test-context
fix: Add context & timeouts to e2e tests
2021-11-10 10:19:27 -08:00
Kubernetes Prow Robot a910f40412
Merge pull request #477 from karlkfi/karl-update-status-fix
fix: Ensure WaitTask gets StatusUpdate
2021-11-10 09:55:27 -08:00
Kubernetes Prow Robot 1d5cee4751
Merge pull request #475 from karlkfi/karl-task-logs
fix: Improve task & event logging
2021-11-09 19:33:26 -08:00
Karl Isenberg 99f9626ce6 fix: Ensure WaitTask gets StatusUpdate
This fixes a flakey test failure in the inventory policy test.

The failure was caused by the Deployment becoming reconciled
imediately after apply, before the WaitTask has started. Normally,
this should be fine, but the task runner was "de-duping" status
events without checking for generation changes. So when the status
went from NotFound (gen 1) to Current (gen 2), it was sent to the
still running ApplyTask. And when the status went from Current
(gen 2) to Current (gen 3), it was being de-duped and not sent to
the WaitTask.

Since the inventory test is the only e2e test performing an update,
it's the only one that was failing, and only sometimes.

The fix is to remove de-duping from the task runner, because the
status poller already performs its own deduping:
statusPollerRunner.isUpdatedResourceStatus.
2021-11-09 18:12:37 -08:00
Karl Isenberg 5f80d35a70 fix: Add context & timeouts to e2e tests
Tests will now each have a context that is cancelled on timeout.
BeforeEach and AfterEach blocks have their own timeouts, to allow
bounded setup and cleanup.

- Test Timeout: 5m
- Before Test Timeout: 30s
- After Test Timeout: 30s
2021-11-09 17:50:03 -08:00
Karl Isenberg ab5a4dc294 fix: Improve task & event logging
- Log tasks at start and end
- Log events before sending
- Add String funcs for readable event logs
2021-11-09 16:43:25 -08:00
Kubernetes Prow Robot b7f3c2a936
Merge pull request #472 from ash2k/ash2k/info-helper-for-client
Consistently use InfoHelper to get rest client
2021-11-08 11:11:19 -08:00
Kubernetes Prow Robot 4c8a09e142
Merge pull request #470 from karlkfi/karl-status-printing
feat: Add apply/destroy --status-events flag
2021-11-05 11:52:41 -07:00
Kubernetes Prow Robot a0994fc794
Merge pull request #473 from ash2k/ash2k/missing-return
Add missing returns
2021-11-05 11:05:10 -07:00
Kubernetes Prow Robot ca846ea62d
Merge pull request #474 from ash2k/ash2k/no-lowercase
No need to lowercase namespaces
2021-11-05 10:37:53 -07:00
Mikhail Mazurskiy 38f7478964
No need to lowercase namespaces
They are lowercase and that's enforced by Kubernetes.
2021-11-05 16:41:24 +11:00
Mikhail Mazurskiy 7b53399fc6
Add missing returns 2021-11-05 16:37:16 +11:00
Mikhail Mazurskiy 200d6ec9c4
Consistently use InfoHelper to get rest client 2021-11-05 14:10:14 +11:00
Karl Isenberg 9607cb5cf1 feat: Add apply/destroy --status-events flag
- Status events disabled by default
- Status events always enabled for table output
2021-11-04 13:14:46 -07:00
Kubernetes Prow Robot 8da7837865
Merge pull request #463 from karlkfi/karl-wait-printer
feat: send WaitEvent for every resource
2021-11-04 13:02:23 -07:00
Karl Isenberg 9426fcbea8 fix: disable dupl linter on some e2e tests
Linter complains that the expected event lists are too similar,
which is deliberate and should not be abstracted away. Explicit
test expectations in the test makes it easier to debug failures.
2021-11-04 10:57:35 -07:00
Karl Isenberg a24aaea775 feat: send WaitEvent for every resource
- WaitEvent can be Pending, Reconciled, Skipped, or Timeout.
  Skipped, Pending, and Reconciled events are sent at task start.
  Reconciled events are sent later as status updates are recieved.
  Timeout events are sent for remaining events on timeout.
- Rewrite WaitTask.Start to use context.WithTimeout and a goroutine to
  handle task completion (replacing setTimer and the token hack).
- Replaced Task.ClearTimeout with Task.Cancel.
- Replaced WaitTask.complete & checkCondition with Task.StatusUpdate.
- Replaced WaitTask.startAndComplete with a check in WaitTask.Start.
- Replaced WaitTask.amendTimeoutError with WaitTask.sendTimeoutEvents
  to send multiple timeout events, instead of one event with a list of
  TimedOutResources.
- Updated all printers to handle WaitEvent.
  Event printer now includes reconcile events.
  JSON printer now includes resourceReconciled eventType.
  Table printer not includes reconcile column.
- Added JSON printer tests for error handling.
- Updated Formatter.FormatActionGroupEvent to collect WaitStats.
- Enable status events by default for kapply with table output

BREAKING CHANGE: WaitEvents now sent for each object
2021-11-04 10:57:35 -07:00
Kubernetes Prow Robot 6112508666
Merge pull request #469 from karlkfi/karl-prune-race
fix: race condition in PruneTask
2021-11-04 10:54:23 -07:00
Karl Isenberg 22ec2ac328 fix: race condition in PruneTask
The Pruner modifies the input object when the deletion prevention
annotation is present. This in turn modifies the object map, which
creates a race condition when reading the object map from the task
runner. To fix the race, a copy of the object is made, but only if
the deletion prevention filter prevents deletion.
2021-11-04 10:20:47 -07:00
Kubernetes Prow Robot 594863b776
Merge pull request #468 from karlkfi/karl-info-race
fix: race condition in BuildInfo
2021-11-03 13:36:32 -07:00
Karl Isenberg b977b5960f fix: race condition in BuildInfo
Historically, the objects in ApplyTask were being modified in the
Start func by BuildInfo to remove the path annotation, but this can
cause a race condition in the task runner if it tried to read the
task objects.

Now a DeepCopy is made in BuildInfo instead. This avoids the race
condition but broke mutation, which executes after BuildInfo on the
original object. So we now extract the object from the into after
BuildInfo and use that instead for mutations, filters, and events.
2021-11-03 13:11:20 -07:00
Kubernetes Prow Robot 10f3156431
Merge pull request #465 from seans3/export-status-poller
Exports Applier/Destroyer StatusPoller field
2021-11-02 15:01:42 -07:00
Sean Sullivan 944b7a7d63 Exports Applier StatusPoller field 2021-11-02 11:53:52 -07:00
Kubernetes Prow Robot 7c3417d3a8
Merge pull request #464 from haiyanmeng/run-make
Run `make all`
2021-11-02 09:56:58 -07:00
Haiyan Meng cb9c7fc15f Run `make all` 2021-11-02 07:05:09 -07:00
Kubernetes Prow Robot 64634f0281
Merge pull request #462 from seans3/remove-unused-preprocess
Removed unused command PreProcess function
2021-11-01 18:38:58 -07:00
Sean Sullivan 1034bbe898 Removed unused command PreProcess function 2021-11-01 18:21:11 -07:00
Kubernetes Prow Robot f4b64aada8
Merge pull request #430 from ash2k/ash2k/crd-check-version
Check versions a CRD defines
2021-11-01 13:35:47 -07:00
Kubernetes Prow Robot 108bc093cd
Merge pull request #459 from haiyanmeng/remove
Avoid printing out all the events
2021-11-01 11:23:47 -07:00
Haiyan Meng 461fae877a Avoid printing out all the events
The printing logic was added by accident in https://github.com/kubernetes-sigs/cli-utils/pull/451/files#diff-dee0be9aff370837ed01dcd5dc8f8a414369adc7b3d846453f800c8639fb8d37R255
2021-11-01 11:06:13 -07:00
Kubernetes Prow Robot 0849d300ff
Merge pull request #451 from haiyanmeng/ignore
Change the behavior of hanlding a WaitTask timeout
2021-10-30 16:55:19 -07:00
Kubernetes Prow Robot b66eaeee95
Merge pull request #457 from seans3/inv-info-wrapper
Removes inventory from manifestloader
2021-10-30 04:25:17 -07:00
Kubernetes Prow Robot ed6845051f
Merge pull request #458 from seans3/printer-pkg-move
Moves printers from cmd to pkg
2021-10-29 16:36:15 -07:00
Haiyan Meng 87877d28d1 Change the behavior of hanlding a WaitTask timeout
Today, when a WaitTask timeout happens, the WaitTask sends the
TimeoutError on the TaskChannel. After receiving the TimeoutError,
`baseRunner.run` terminates immediately by returning the error to its
caller (Applier.Run or Destroyer.Run). The caller then sends the error
onto the EventChannel and terminates.

With this PR, when a WaitTask timeout happens, the WaitTask sends a
WaitType Event including the TimeoutError on the EventChannel, and then
sends an empty TaskResult on the TaskChannel. An empty TaskResult
suggests that the task finished successfully, and therefore
`baseRunner.run` would continue instead of terminate.

The motivation of this change is to make sure that cli-utils only
terminates on fatal errors (such as inventory-related errors, and
ApplyOptions creation errors). A WaitTask timeout may not always mean a
fatal error (it may happen because the StatusPoller has not finished
polling everything, or some but not all the resources have not reached
the desired status), and therefore should not terminate cli-utils.
2021-10-29 16:18:21 -07:00
Sean Sullivan 0419797013 Moves printers from cmd to pkg 2021-10-29 12:22:49 -07:00
Kubernetes Prow Robot 6f5ee6f2ef
Merge pull request #456 from karlkfi/karl-fix-skips
fix: skipped deletes no longer cause waiting
2021-10-29 11:41:10 -07:00