mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
removed deprecated fields from Drain structs and API
node drain: use msgtype on txn so that events are emitted wip: encoding extension to add Node.Drain field back to API responses new approach for hiding Node.SecretID in the API, using `json` tag documented this approach in the contributing guide refactored the JSON handlers with extensions modified event stream encoding to use the go-msgpack encoders with the extensions
This commit is contained in:
@@ -20,10 +20,11 @@ import (
|
||||
"github.com/hashicorp/go-connlimit"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-msgpack/codec"
|
||||
"github.com/rs/cors"
|
||||
|
||||
"github.com/hashicorp/nomad/helper/noxssrw"
|
||||
"github.com/hashicorp/nomad/helper/tlsutil"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/rs/cors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -500,7 +501,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
||||
buf.Write([]byte("\n"))
|
||||
}
|
||||
} else {
|
||||
enc := codec.NewEncoder(&buf, structs.JsonHandle)
|
||||
enc := codec.NewEncoder(&buf, structs.JsonHandleWithExtensions)
|
||||
err = enc.Encode(obj)
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -2,9 +2,7 @@ package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
@@ -119,31 +117,9 @@ func (s *HTTPServer) nodeToggleDrain(resp http.ResponseWriter, req *http.Request
|
||||
|
||||
var drainRequest api.NodeUpdateDrainRequest
|
||||
|
||||
// COMPAT: Remove in 0.10. Allow the old style enable query param.
|
||||
// Get the enable parameter
|
||||
enableRaw := req.URL.Query().Get("enable")
|
||||
var enable bool
|
||||
if enableRaw != "" {
|
||||
var err error
|
||||
enable, err = strconv.ParseBool(enableRaw)
|
||||
if err != nil {
|
||||
return nil, CodedError(400, "invalid enable value")
|
||||
}
|
||||
|
||||
// Use the force drain to have it keep the same behavior as old clients.
|
||||
if enable {
|
||||
drainRequest.DrainSpec = &api.DrainSpec{
|
||||
Deadline: -1 * time.Second,
|
||||
}
|
||||
} else {
|
||||
// If drain is disabled on an old client, mark the node as eligible for backwards compatibility
|
||||
drainRequest.MarkEligible = true
|
||||
}
|
||||
} else {
|
||||
err := decodeBody(req, &drainRequest)
|
||||
if err != nil {
|
||||
return nil, CodedError(400, err.Error())
|
||||
}
|
||||
err := decodeBody(req, &drainRequest)
|
||||
if err != nil {
|
||||
return nil, CodedError(400, err.Error())
|
||||
}
|
||||
|
||||
args := structs.NodeUpdateDrainRequest{
|
||||
|
||||
@@ -284,11 +284,9 @@ func TestHTTP_NodeDrain(t *testing.T) {
|
||||
out, err := state.NodeByID(nil, node.ID)
|
||||
require.Nil(err)
|
||||
|
||||
// the node must either be in drain mode or in elligible
|
||||
// the node must either be in drain mode or ineligible
|
||||
// once the node is recognize as not having any running allocs
|
||||
if out.Drain {
|
||||
require.True(out.Drain)
|
||||
require.NotNil(out.DrainStrategy)
|
||||
if out.DrainStrategy != nil {
|
||||
require.Equal(10*time.Second, out.DrainStrategy.Deadline)
|
||||
} else {
|
||||
require.Equal(structs.NodeSchedulingIneligible, out.SchedulingEligibility)
|
||||
@@ -307,7 +305,6 @@ func TestHTTP_NodeDrain(t *testing.T) {
|
||||
|
||||
out, err = state.NodeByID(nil, node.ID)
|
||||
require.Nil(err)
|
||||
require.False(out.Drain)
|
||||
require.Nil(out.DrainStrategy)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user