Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
fleetctl:destroy: on destroy check if the unit does not exist
Browse files Browse the repository at this point in the history
Add IsErrorUnitNotFound() and use it in destroy to check if the error
indicates that the unit does not exist.

For the moment we just want to check if the error is 'unit not found', if
later we want more we may export a more generic function into cAPI.
  • Loading branch information
Djalal Harouni committed Feb 24, 2016
1 parent 9400eeb commit 4a71826
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ func is404(err error) bool {
googerr, ok := err.(*googleapi.Error)
return ok && googerr.Code == http.StatusNotFound
}

func IsErrorUnitNotFound(err error) bool {
return is404(err)
}
6 changes: 6 additions & 0 deletions fleetctl/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package main

import (
"time"

"github.com/coreos/fleet/client"
)

var cmdDestroyUnit = &Command{
Expand All @@ -42,6 +44,10 @@ func runDestroyUnits(args []string) (exit int) {
for _, v := range units {
err := cAPI.DestroyUnit(v.Name)
if err != nil {
// Ignore 'Unit does not exist' error
if client.IsErrorUnitNotFound(err) {
continue
}
stderr("Error destroying units: %v", err)
exit = 1
continue
Expand Down

0 comments on commit 4a71826

Please sign in to comment.