-
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 1 commit
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 |
---|---|---|
|
@@ -125,6 +125,16 @@ func (c *MockKnServingClient) WaitForService(name string, timeout time.Duration, | |
return mock.ErrorOrNil(call.Result[0]), call.Result[1].(time.Duration) | ||
} | ||
|
||
// Wait for a service to become ready, but not longer than provided timeout | ||
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 method ServingRecorder.WaitForEvent should be of the form "WaitForEvent ...". More info. |
||
func (sr *ServingRecorder) WaitForEvent(kind, name interface{}, timeout interface{}, done interface{}, err error) { | ||
sr.r.Add("WaitForEvent", []interface{}{kind, name, timeout, done}, []interface{}{err}) | ||
} | ||
|
||
func (c *MockKnServingClient) WaitForEvent(kind, name string, timeout time.Duration, done wait.EventDone) 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.WaitForEvent should have comment or be unexported. More info. |
||
call := c.recorder.r.VerifyCall("WaitForEvent", kind, name, timeout, done) | ||
return mock.ErrorOrNil(call.Result[0]) | ||
} | ||
|
||
// Get a revision by name | ||
func (sr *ServingRecorder) GetRevision(name interface{}, revision *servingv1.Revision, err error) { | ||
sr.r.Add("GetRevision", []interface{}{name}, []interface{}{revision, err}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,17 @@ type waitForReadyConfig struct { | |
kind string | ||
} | ||
|
||
type waitForEvent struct { | ||
watchMaker WatchMaker | ||
eventDone EventDone | ||
kind string | ||
} | ||
|
||
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 +64,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 +194,29 @@ func (w *waitForReadyConfig) waitForReadyCondition(start time.Time, name string, | |
} | ||
} | ||
|
||
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 nil, 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.