Skip to content

Commit

Permalink
Log fewer spurious status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hausdorff committed Nov 16, 2018
1 parent d64a9f1 commit c6ca8a3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ func Creation(
var clientForResource dynamic.ResourceInterface
err := sleepingRetry(
func(i uint) error {
if i > 0 {
_ = host.LogStatus(ctx, diag.Info, urn, fmt.Sprintf("Creation failed, retrying (%d)", i))
}

// Recreate the client for resource, in case the client's cache of the server API was
// invalidated. For example, when a CRD is created, it will invalidate the client cache;
// this allows CRs that we tried (and failed) to create before to re-try with the new
Expand All @@ -83,6 +79,9 @@ func Creation(
}
}
outputs, err = clientForResource.Create(inputs)
if err != nil {
_ = host.LogStatus(ctx, diag.Info, urn, fmt.Sprintf("Retry #%d; creation failed: %v", i, err))
}
return err
}).
WithMaxRetries(5).
Expand All @@ -91,6 +90,7 @@ func Creation(
if err != nil {
return nil, err
}
_ = clearStatus(ctx, host, urn)

// Wait until create resolves as success or error. Note that the conditional is set up to log
// only if we don't have an entry for the resource type; in the event that we do, but the await
Expand Down Expand Up @@ -380,13 +380,12 @@ func Deletion(
if awaiter, exists := awaiters[id]; exists && awaiter.awaitDeletion != nil {
waitErr = awaiter.awaitDeletion(ctx, clientForResource, name)
} else {
_ = host.LogStatus(ctx, diag.Info, urn, fmt.Sprintf("Waiting for deletion of %s '%s'", id, name))

for {
select {
case event, ok := <-watcher.ResultChan():
if !ok {
if deleted, obj := checkIfResourceDeleted(name, clientForResource); deleted {
_ = clearStatus(ctx, host, urn)
return nil
} else {
return &timeoutError{
Expand All @@ -398,9 +397,11 @@ func Deletion(

switch event.Type {
case watch.Deleted:
_ = clearStatus(ctx, host, urn)
return nil
case watch.Error:
if deleted, obj := checkIfResourceDeleted(name, clientForResource); deleted {
_ = clearStatus(ctx, host, urn)
return nil
} else {
return &initializationError{
Expand All @@ -413,6 +414,7 @@ func Deletion(
watcher.Stop()
glog.V(3).Infof("Received error deleting object '%s': %#v", id, err)
if deleted, obj := checkIfResourceDeleted(name, clientForResource); deleted {
_ = clearStatus(ctx, host, urn)
return nil
} else {
return &cancellationError{
Expand All @@ -436,3 +438,8 @@ func checkIfResourceDeleted(name string, client dynamic.ResourceInterface) (bool

return false, obj
}

// clearStatus will clear the `Info` column of the CLI of all statuses and messages.
func clearStatus(context context.Context, host *provider.HostClient, urn resource.URN) error {
return host.LogStatus(context, diag.Info, urn, "")
}

0 comments on commit c6ca8a3

Please sign in to comment.