From ac87f316afd381de975c33698d09af7ac6f8d1c7 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Wed, 16 Sep 2020 08:54:03 -0400 Subject: [PATCH] api: target servers for allocation requests Allocation requests should target servers, which then can forward the connection to the appropriate servers. Contacting clients directly is fragile and prune to failures: e.g. clients maybe firewalled and not accessible from the API client, or have some internal certificates not trusted by the API client. FWIW, in contexts where we anticipate lots of traffic (e.g. logs, or exec), the api package attempts contacting server directly but then fallsback to using the client. This approach seems excessive in these simple GET/PUT requests. --- api/allocations.go | 14 ++------------ .../github.com/hashicorp/nomad/api/allocations.go | 14 ++------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/api/allocations.go b/api/allocations.go index 7c5ab64059cc..737c0f8e9fcb 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -286,13 +286,8 @@ func (a *Allocations) Stats(alloc *Allocation, q *QueryOptions) (*AllocResourceU } func (a *Allocations) GC(alloc *Allocation, q *QueryOptions) error { - nodeClient, err := a.client.GetNodeClient(alloc.NodeID, q) - if err != nil { - return err - } - var resp struct{} - _, err = nodeClient.query("/v1/client/allocation/"+alloc.ID+"/gc", &resp, nil) + _, err := a.client.query("/v1/client/allocation/"+alloc.ID+"/gc", &resp, nil) return err } @@ -321,18 +316,13 @@ type AllocStopResponse struct { } func (a *Allocations) Signal(alloc *Allocation, q *QueryOptions, task, signal string) error { - nodeClient, err := a.client.GetNodeClient(alloc.NodeID, q) - if err != nil { - return err - } - req := AllocSignalRequest{ Signal: signal, Task: task, } var resp GenericResponse - _, err = nodeClient.putQuery("/v1/client/allocation/"+alloc.ID+"/signal", &req, &resp, q) + _, err := a.client.putQuery("/v1/client/allocation/"+alloc.ID+"/signal", &req, &resp, q) return err } diff --git a/vendor/github.com/hashicorp/nomad/api/allocations.go b/vendor/github.com/hashicorp/nomad/api/allocations.go index 7c5ab64059cc..737c0f8e9fcb 100644 --- a/vendor/github.com/hashicorp/nomad/api/allocations.go +++ b/vendor/github.com/hashicorp/nomad/api/allocations.go @@ -286,13 +286,8 @@ func (a *Allocations) Stats(alloc *Allocation, q *QueryOptions) (*AllocResourceU } func (a *Allocations) GC(alloc *Allocation, q *QueryOptions) error { - nodeClient, err := a.client.GetNodeClient(alloc.NodeID, q) - if err != nil { - return err - } - var resp struct{} - _, err = nodeClient.query("/v1/client/allocation/"+alloc.ID+"/gc", &resp, nil) + _, err := a.client.query("/v1/client/allocation/"+alloc.ID+"/gc", &resp, nil) return err } @@ -321,18 +316,13 @@ type AllocStopResponse struct { } func (a *Allocations) Signal(alloc *Allocation, q *QueryOptions, task, signal string) error { - nodeClient, err := a.client.GetNodeClient(alloc.NodeID, q) - if err != nil { - return err - } - req := AllocSignalRequest{ Signal: signal, Task: task, } var resp GenericResponse - _, err = nodeClient.putQuery("/v1/client/allocation/"+alloc.ID+"/signal", &req, &resp, q) + _, err := a.client.putQuery("/v1/client/allocation/"+alloc.ID+"/signal", &req, &resp, q) return err }