Skip to content

Commit

Permalink
try just tweaking the --no-wait flag
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
Doug Davis committed Apr 2, 2020
1 parent 90fa601 commit fd42204
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/cmd/kn_revision_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kn revision delete NAME [flags]
--async DEPRECATED: please use --no-wait instead. Delete revision and don't wait for it to be deleted.
-h, --help help for delete
-n, --namespace string Specify the namespace to operate in.
--no-wait Delete revision and don't wait for it to be deleted.
--no-wait Delete revision and don't wait for it to be deleted. (default true)
--wait-timeout int Seconds to wait before giving up on waiting for revision to be deleted. (default 600)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ kn service delete NAME [flags]
--async DEPRECATED: please use --no-wait instead. Delete service and don't wait for it to be deleted.
-h, --help help for delete
-n, --namespace string Specify the namespace to operate in.
--no-wait Delete service and don't wait for it to be deleted.
--no-wait Delete service and don't wait for it to be deleted. (default true)
--wait-timeout int Seconds to wait before giving up on waiting for service to be deleted. (default 600)
```

Expand Down
9 changes: 8 additions & 1 deletion pkg/kn/commands/wait_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ type WaitFlags struct {
func (p *WaitFlags) AddConditionWaitFlags(command *cobra.Command, waitTimeoutDefault int, action, what, until string) {
waitUsage := fmt.Sprintf("%s %s and don't wait for it to be %s.", action, what, until)
//TODO: deprecated flag should be removed in next release

// Special-case 'delete' command so it comes back to the user immediately
noWaitDefault := false
if action == "Delete" {
noWaitDefault = true
}

command.Flags().BoolVar(&p.Async, "async", false, "DEPRECATED: please use --no-wait instead. "+waitUsage)
command.Flags().BoolVar(&p.NoWait, "no-wait", false, waitUsage)
command.Flags().BoolVar(&p.NoWait, "no-wait", noWaitDefault, waitUsage)

timeoutUsage := fmt.Sprintf("Seconds to wait before giving up on waiting for %s to be %s.", what, until)
command.Flags().IntVar(&p.TimeoutInSeconds, "wait-timeout", waitTimeoutDefault, timeoutUsage)
Expand Down
8 changes: 4 additions & 4 deletions pkg/serving/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,25 @@ func updateServiceWithRetry(cl KnServingClient, name string, updateFunc serviceU
// For `timeout == 0` delete is performed async without any wait.
func (cl *knServingClient) DeleteService(serviceName string, timeout time.Duration) error {
if timeout == 0 {
return cl.deleteService(serviceName)
return cl.deleteService(serviceName, v1.DeletePropagationBackground)
}
waitC := make(chan error)
go func() {
waitForEvent := wait.NewWaitForEvent("service", cl.WatchService, func(evt *watch.Event) bool { return evt.Type == watch.Deleted })
err, _ := waitForEvent.Wait(serviceName, wait.Options{Timeout: &timeout}, wait.NoopMessageCallback())
waitC <- err
}()
err := cl.deleteService(serviceName)
err := cl.deleteService(serviceName, v1.DeletePropagationForeground)
if err != nil {
return err
}
return <-waitC
}

func (cl *knServingClient) deleteService(serviceName string) error {
func (cl *knServingClient) deleteService(serviceName string, propagationPolicy v1.DeletionPropagation) error {
err := cl.client.Services(cl.namespace).Delete(
serviceName,
&v1.DeleteOptions{},
&v1.DeleteOptions{PropagationPolicy: &propagationPolicy},
)
if err != nil {
return clienterrors.GetError(err)
Expand Down

0 comments on commit fd42204

Please sign in to comment.