Skip to content

Commit

Permalink
Remove Managed Sinks from Nomad (#9470)
Browse files Browse the repository at this point in the history
* Remove Managed Sinks from Nomad

Managed Sinks were a beta feature in Nomad 1.0-beta2. During the beta
period it was determined that this was not a scalable approach to
support community and third party sinks.

* update comment

* changelog
  • Loading branch information
drewbailey authored Nov 30, 2020
1 parent f5806ee commit bf225f7
Show file tree
Hide file tree
Showing 36 changed files with 9 additions and 3,446 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ IMPROVEMENTS:
* jobspec: Added support for `headers` option in `artifact` stanza [[GH-9306](https://github.com/hashicorp/nomad/issues/9306)]

__BACKWARDS INCOMPATIBILITIES:__
* core: `nomad event sink` beta cli commands and API endpoints have been removed. [[GH-9470](https://github.com/hashicorp/nomad/issues/9470)]
* core: null characters are prohibited in region, datacenter, job name/ID, task group name, and task name [[GH-9020](https://github.com/hashicorp/nomad/issues/9020)]
* csi: registering a CSI volume with a `block-device` attachment mode and `mount_options` now returns a validation error, instead of silently dropping the `mount_options`. [[GH-9044](https://github.com/hashicorp/nomad/issues/9044)]
* driver/docker: Tasks are now issued SIGTERM instead of SIGINT when stopping [[GH-8932](https://github.com/hashicorp/nomad/issues/8932)]
Expand Down
57 changes: 0 additions & 57 deletions api/event_sink.go

This file was deleted.

73 changes: 0 additions & 73 deletions api/event_sink_test.go

This file was deleted.

96 changes: 0 additions & 96 deletions command/agent/event_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,102 +17,6 @@ import (
"golang.org/x/sync/errgroup"
)

func (s *HTTPServer) EventSinksRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != http.MethodGet {
return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
}

args := structs.EventSinkListRequest{}
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
return nil, nil
}

var out structs.EventSinkListResponse
if err := s.agent.RPC("Event.ListSinks", &args, &out); err != nil {
return nil, err
}

if out.Sinks == nil {
out.Sinks = make([]*structs.EventSink, 0)
}
setMeta(resp, &out.QueryMeta)
return out.Sinks, nil
}

func (s *HTTPServer) EventSinkSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
name := strings.TrimPrefix(req.URL.Path, "/v1/event/sink/")
if len(name) == 0 {
return nil, CodedError(http.StatusBadRequest, "Missing Policy Name")
}
switch req.Method {
case http.MethodGet:
return s.eventSinkGet(resp, req, name)
case http.MethodPost, http.MethodPut:
return s.eventSinkUpdate(resp, req, name)
case http.MethodDelete:
return s.eventSinkDelete(resp, req, name)
default:
return nil, CodedError(405, ErrInvalidMethod)
}
}

func (s *HTTPServer) eventSinkGet(resp http.ResponseWriter, req *http.Request, sink string) (interface{}, error) {
args := structs.EventSinkSpecificRequest{
ID: sink,
}
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
return nil, nil
}

var out structs.EventSinkResponse
if err := s.agent.RPC("Event.GetSink", &args, &out); err != nil {
return nil, err
}
setMeta(resp, &out.QueryMeta)
if out.Sink == nil {
return nil, CodedError(404, "event sink not found")
}
return out.Sink, nil
}

func (s *HTTPServer) eventSinkUpdate(resp http.ResponseWriter, req *http.Request, sinkName string) (interface{}, error) {
var sink structs.EventSink
if err := decodeBody(req, &sink); err != nil {
return nil, CodedError(500, err.Error())
}

if sink.ID != sinkName {
return nil, CodedError(400, "Event sink name does not match request path")
}

args := structs.EventSinkUpsertRequest{
Sink: &sink,
}
s.parseWriteRequest(req, &args.WriteRequest)

var out structs.GenericResponse
if err := s.agent.RPC("Event.UpsertSink", &args, &out); err != nil {
return nil, err
}

setIndex(resp, out.Index)
return nil, nil
}

func (s *HTTPServer) eventSinkDelete(resp http.ResponseWriter, req *http.Request, sink string) (interface{}, error) {
args := structs.EventSinkDeleteRequest{
IDs: []string{sink},
}
s.parseWriteRequest(req, &args.WriteRequest)

var out structs.GenericResponse
if err := s.agent.RPC("Event.DeleteSink", &args, &out); err != nil {
return nil, err
}
setIndex(resp, out.Index)
return nil, nil
}

func (s *HTTPServer) EventStream(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
query := req.URL.Query()

Expand Down
90 changes: 0 additions & 90 deletions command/agent/event_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"

"github.com/hashicorp/nomad/testutil"
Expand All @@ -23,95 +22,6 @@ type testEvent struct {
ID string
}

func TestHTTP_EventSinkList(t *testing.T) {
t.Parallel()

httpTest(t, nil, func(s *TestAgent) {
s1 := mock.EventSink()
s2 := mock.EventSink()

require.NoError(t, s.Agent.server.State().UpsertEventSink(1000, s1))
require.NoError(t, s.Agent.server.State().UpsertEventSink(1001, s2))

req, err := http.NewRequest("GET", "/v1/event/sinks", nil)
require.NoError(t, err)

respW := httptest.NewRecorder()
obj, err := s.Server.EventSinksRequest(respW, req)
require.NoError(t, err)

require.Equal(t, "1001", respW.HeaderMap.Get("X-Nomad-Index"))

n := obj.([]*structs.EventSink)
require.Len(t, n, 2)
})
}

func TestHTTP_EventSinkGet(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
s1 := mock.EventSink()

require.NoError(t, s.Agent.server.State().UpsertEventSink(1000, s1))

req, err := http.NewRequest("GET", "/v1/event/sink/"+s1.ID, nil)
require.NoError(t, err)

respW := httptest.NewRecorder()
obj, err := s.Server.EventSinkSpecificRequest(respW, req)
require.NoError(t, err)

require.Equal(t, "1000", respW.HeaderMap.Get("X-Nomad-Index"))

n := obj.(*structs.EventSink)
require.Equal(t, s1, n)
})
}

func TestHTTP_EventSinkUpsert(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
s1 := mock.EventSink()

buf := encodeReq(s1)

req, err := http.NewRequest("POST", "/v1/event/sink/"+s1.ID, buf)
require.NoError(t, err)

respW := httptest.NewRecorder()
_, err = s.Server.EventSinkSpecificRequest(respW, req)
require.NoError(t, err)

require.NotEqual(t, "", respW.HeaderMap.Get("X-Nomad-Index"))

state := s.Agent.server.State()
out, err := state.EventSinkByID(nil, s1.ID)
require.NoError(t, err)
require.Equal(t, s1.Address, out.Address)
require.Equal(t, s1.ID, out.ID)
})
}

func TestHTTP_EventSinkDelete(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
s1 := mock.EventSink()

require.NoError(t, s.Agent.server.State().UpsertEventSink(1000, s1))

req, err := http.NewRequest("DELETE", "/v1/event/sink/"+s1.ID, nil)
require.NoError(t, err)

respW := httptest.NewRecorder()
_, err = s.Server.EventSinkSpecificRequest(respW, req)
require.NoError(t, err)

require.NotEqual(t, "", respW.HeaderMap.Get("X-Nomad-Index"))

state := s.Agent.server.State()
out, err := state.EventSinkByID(nil, s1.ID)
require.NoError(t, err)
require.Nil(t, out)
})
}

func TestEventStream(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 0 additions & 3 deletions command/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
s.mux.HandleFunc("/v1/operator/scheduler/configuration", s.wrap(s.OperatorSchedulerConfiguration))

s.mux.HandleFunc("/v1/event/stream", s.wrap(s.EventStream))
s.mux.HandleFunc("/v1/event/sinks", s.wrap(s.EventSinksRequest))
s.mux.HandleFunc("/v1/event/sink/", s.wrap(s.EventSinkSpecificRequest))

s.mux.HandleFunc("/v1/namespaces", s.wrap(s.NamespacesRequest))
s.mux.HandleFunc("/v1/namespace", s.wrap(s.NamespaceCreateRequest))
s.mux.HandleFunc("/v1/namespace/", s.wrap(s.NamespaceSpecificRequest))
Expand Down
20 changes: 0 additions & 20 deletions command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,6 @@ func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory {
Meta: meta,
}, nil
},
"event": func() (cli.Command, error) {
return &EventCommand{
Meta: meta,
}, nil
},
"event sink deregister": func() (cli.Command, error) {
return &EventSinkDeregisterCommand{
Meta: meta,
}, nil
},
"event sink list": func() (cli.Command, error) {
return &EventSinkListCommand{
Meta: meta,
}, nil
},
"event sink register": func() (cli.Command, error) {
return &EventSinkRegisterCommand{
Meta: meta,
}, nil
},
"exec": func() (cli.Command, error) {
return &AllocExecCommand{
Meta: meta,
Expand Down
Loading

2 comments on commit bf225f7

@vercel
Copy link

@vercel vercel bot commented on bf225f7 Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nomad-storybook – ./ui/stories

nomad-storybook.vercel.app
nomad-storybook-git-master.hashicorp.vercel.app
nomad-storybook.hashicorp.vercel.app

@vercel
Copy link

@vercel vercel bot commented on bf225f7 Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nomad-ui – ./ui

nomad-ui.vercel.app
nomad-ui-git-master.hashicorp.vercel.app
nomad-ui.hashicorp.vercel.app

Please sign in to comment.