Skip to content

Commit f4a28f5

Browse files
committed
fix a bug in -force flag
1 parent 9a010e8 commit f4a28f5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

command/agent/host_volume_endpoint.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package agent
55

66
import (
77
"net/http"
8+
"strconv"
89
"strings"
910

1011
"github.com/hashicorp/nomad/nomad/structs"
@@ -132,6 +133,17 @@ func (s *HTTPServer) hostVolumeDelete(id string, resp http.ResponseWriter, req *
132133
args := structs.HostVolumeDeleteRequest{VolumeID: id}
133134
s.parseWriteRequest(req, &args.WriteRequest)
134135

136+
raw := req.URL.Query().Get("force")
137+
var force bool
138+
if raw != "" {
139+
var err error
140+
force, err = strconv.ParseBool(raw)
141+
if err != nil {
142+
return nil, CodedError(400, "invalid force value")
143+
}
144+
}
145+
args.Force = force
146+
135147
var out structs.HostVolumeDeleteResponse
136148
if err := s.agent.RPC("HostVolume.Delete", &args, &out); err != nil {
137149
return nil, err

nomad/host_volume_endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ func (v *HostVolume) Delete(args *structs.HostVolumeDeleteRequest, reply *struct
671671
// serialize client RPC and raft write per volume ID
672672
index, err := v.serializeCall(vol.ID, "delete", func() (uint64, error) {
673673
if err := v.deleteVolume(vol); err != nil {
674-
if structs.IsErrUnknownNode(err) {
674+
if structs.IsErrUnknownNode(err) || structs.IsErrNoNodeConn(err) {
675675
if !args.Force {
676676
return 0, fmt.Errorf(
677677
"volume cannot be removed from unknown node without force=true")

0 commit comments

Comments
 (0)