-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wait): add wait for delete operation #682
Changes from 3 commits
80d0001
adf36de
01d2b0f
9221ab8
44e33d7
e0cc636
b97e2ca
a49748c
9bb60ac
7ff0fe5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,12 +106,12 @@ func (c *MockKnServingClient) UpdateServiceWithRetry(name string, updateFunc ser | |
} | ||
|
||
// Delete a service by name | ||
func (sr *ServingRecorder) DeleteService(name interface{}, err error) { | ||
sr.r.Add("DeleteService", []interface{}{name}, []interface{}{err}) | ||
func (sr *ServingRecorder) DeleteService(name, timeout interface{}, err error) { | ||
sr.r.Add("DeleteService", []interface{}{name, timeout}, []interface{}{err}) | ||
} | ||
|
||
func (c *MockKnServingClient) DeleteService(name string) error { | ||
call := c.recorder.r.VerifyCall("DeleteService", name) | ||
func (c *MockKnServingClient) DeleteService(name string, timeout time.Duration) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: exported method MockKnServingClient.DeleteService should have comment or be unexported. More info. |
||
call := c.recorder.r.VerifyCall("DeleteService", name, timeout) | ||
return mock.ErrorOrNil(call.Result[0]) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,19 @@ type waitForReadyConfig struct { | |
kind string | ||
} | ||
|
||
// Callbacks and configuration used while waiting for event | ||
type waitForEvent struct { | ||
watchMaker WatchMaker | ||
eventDone EventDone | ||
kind string | ||
} | ||
|
||
// Done marker to stop actual waiting on given event state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: comment on exported type EventDone should be of the form "EventDone ..." (with optional leading article). More info. |
||
type EventDone func(ev *watch.Event) bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: exported type EventDone should have comment or be unexported. More info. |
||
|
||
// Interface used for waiting of a resource of a given name to reach a definitive | ||
// state in its "Ready" condition. | ||
type WaitForReady interface { | ||
type Wait interface { | ||
|
||
// Wait on resource the resource with this name until a given timeout | ||
// and write event messages for unknown event to the status writer. | ||
|
@@ -56,14 +66,22 @@ type ConditionsExtractor func(obj runtime.Object) (apis.Conditions, error) | |
type MessageCallback func(durationSinceState time.Duration, message string) | ||
|
||
// Constructor with resource type specific configuration | ||
func NewWaitForReady(kind string, watchMaker WatchMaker, extractor ConditionsExtractor) WaitForReady { | ||
func NewWaitForReady(kind string, watchMaker WatchMaker, extractor ConditionsExtractor) Wait { | ||
return &waitForReadyConfig{ | ||
kind: kind, | ||
watchMaker: watchMaker, | ||
conditionsExtractor: extractor, | ||
} | ||
} | ||
|
||
func NewWaitForEvent(kind string, watchMaker WatchMaker, eventDone EventDone) Wait { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: exported function NewWaitForEvent should have comment or be unexported. More info. |
||
return &waitForEvent{ | ||
kind: kind, | ||
watchMaker: watchMaker, | ||
eventDone: eventDone, | ||
} | ||
} | ||
|
||
// A simple message callback which prints out messages line by line | ||
func SimpleMessageCallback(out io.Writer) MessageCallback { | ||
oldMessage := "" | ||
|
@@ -178,6 +196,30 @@ func (w *waitForReadyConfig) waitForReadyCondition(start time.Time, name string, | |
} | ||
} | ||
|
||
// Wait until the expected EventDone is satisfied | ||
func (w *waitForEvent) Wait(name string, timeout time.Duration, msgCallback MessageCallback) (error, time.Duration) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint arg-order: error should be the last type when returning multiple items. |
||
watcher, err := w.watchMaker(name, timeout) | ||
if err != nil { | ||
return err, 0 | ||
} | ||
defer watcher.Stop() | ||
start := time.Now() | ||
// channel used to transport the error | ||
errChan := make(chan error) | ||
for { | ||
select { | ||
case <-time.After(timeout): | ||
dsimansk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fmt.Errorf("timeout: %s '%s' not ready after %d seconds", w.kind, name, int(timeout/time.Second)), time.Since(start) | ||
case err = <-errChan: | ||
return err, time.Since(start) | ||
case event := <-watcher.ResultChan(): | ||
if w.eventDone(&event) { | ||
return nil, time.Since(start) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Going over Unstructured to keep that function generally applicable. | ||
// Alternative implemenentation: Add a func-field to waitForReadyConfig which has to be | ||
// provided for every resource (like the conditions extractor) | ||
dsimansk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't add that, not deeded to add a deprecated option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still part of
AddConditionWaitFlags()
and I wish I could create overloaded method...:) But of course, I agress it shouldn't be created with deprecated flag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I've seen. its ok.