Skip to content

Commit 5739f4b

Browse files
authored
Merge pull request #3213 from corhere/controlapi-hooks-request-data
api: afford passing params to OnGetNetwork hook
2 parents 40bd11b + f9819ab commit 5739f4b

File tree

7 files changed

+344
-200
lines changed

7 files changed

+344
-200
lines changed

api/api.pb.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8304,6 +8304,14 @@ file {
83048304
type: TYPE_STRING
83058305
json_name: "networkId"
83068306
}
8307+
field {
8308+
name: "appdata"
8309+
number: 3
8310+
label: LABEL_OPTIONAL
8311+
type: TYPE_MESSAGE
8312+
type_name: ".google.protobuf.Any"
8313+
json_name: "appdata"
8314+
}
83078315
}
83088316
message_type {
83098317
name: "GetNetworkResponse"
@@ -8346,6 +8354,14 @@ file {
83468354
type_name: ".docker.swarmkit.v1.ListNetworksRequest.Filters"
83478355
json_name: "filters"
83488356
}
8357+
field {
8358+
name: "appdata"
8359+
number: 2
8360+
label: LABEL_OPTIONAL
8361+
type: TYPE_MESSAGE
8362+
type_name: ".google.protobuf.Any"
8363+
json_name: "appdata"
8364+
}
83498365
nested_type {
83508366
name: "Filters"
83518367
field {

api/control.pb.go

Lines changed: 309 additions & 189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/control.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ message CreateNetworkResponse {
484484
message GetNetworkRequest {
485485
string name = 1;
486486
string network_id = 2;
487+
// Application-specific message for the NetworkAllocator's OnGetNetwork callback.
488+
google.protobuf.Any appdata = 3;
487489
}
488490

489491
message GetNetworkResponse {
@@ -507,6 +509,8 @@ message ListNetworksRequest {
507509
}
508510

509511
Filters filters = 1;
512+
// Application-specific message for the NetworkAllocator's OnGetNetwork callback.
513+
google.protobuf.Any appdata = 2;
510514
}
511515

512516
message ListNetworksResponse {

manager/allocator/networkallocator/networkallocator.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ type OnGetNetworker interface {
9898
// response. The modified network object will not be persisted to the
9999
// store. Errors returned will be bubbled up to the Control API client.
100100
//
101+
// The appdataTypeURL and appdata parameters are set to the TypeUrl and
102+
// value, respectively, of the appdata field in the ListNetworks or
103+
// GetNetwork Control API request.
104+
//
101105
// The network may not have been allocated at the time of the call.
102106
// Calling OnGetNetwork with an unallocated network should not be an
103107
// error.
104108
//
105109
// This method may be called concurrently from multiple goroutines.
106-
OnGetNetwork(context.Context, *api.Network) error
110+
OnGetNetwork(ctx context.Context, network *api.Network, appdataTypeURL string, appdata []byte) error
107111
}
108112

109113
// Config is used to store network related cluster config in the Manager.

manager/apihooks.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ func (m *Manager) networkAllocator() networkallocator.NetworkAllocator {
1616
return m.allocator.NetworkAllocator()
1717
}
1818

19-
func (m *Manager) OnGetNetwork(ctx context.Context, n *api.Network) error {
19+
func (m *Manager) OnGetNetwork(ctx context.Context, n *api.Network, appdataTypeURL string, appdata []byte) error {
2020
if nwh, ok := m.networkAllocator().(networkallocator.OnGetNetworker); ok {
21-
return nwh.OnGetNetwork(ctx, n)
21+
return nwh.OnGetNetwork(ctx, n, appdataTypeURL, appdata)
2222
}
2323
return nil
2424
}
2525

26-
func (m *Manager) OnListNetworks(ctx context.Context, networks []*api.Network) error {
26+
func (m *Manager) OnListNetworks(ctx context.Context, networks []*api.Network, appdataTypeURL string, appdata []byte) error {
2727
if nwh, ok := m.networkAllocator().(networkallocator.OnGetNetworker); ok {
2828
for _, n := range networks {
29-
if err := nwh.OnGetNetwork(ctx, n); err != nil {
29+
if err := nwh.OnGetNetwork(ctx, n, appdataTypeURL, appdata); err != nil {
3030
return err
3131
}
3232
}

manager/controlapi/apihooks.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010
// objects for GetNetwork and ListNetworks Control API requests before they are
1111
// sent to the client.
1212
type NetworkViewResponseMutator interface {
13-
OnGetNetwork(context.Context, *api.Network) error
14-
OnListNetworks(context.Context, []*api.Network) error
13+
OnGetNetwork(context.Context, *api.Network, string, []byte) error
14+
OnListNetworks(context.Context, []*api.Network, string, []byte) error
1515
}
1616

1717
type NoopViewResponseMutator struct{}
1818

19-
func (NoopViewResponseMutator) OnGetNetwork(ctx context.Context, n *api.Network) error {
19+
func (NoopViewResponseMutator) OnGetNetwork(ctx context.Context, n *api.Network, appdataTypeURL string, appdata []byte) error {
2020
return nil
2121
}
2222

23-
func (NoopViewResponseMutator) OnListNetworks(ctx context.Context, networks []*api.Network) error {
23+
func (NoopViewResponseMutator) OnListNetworks(ctx context.Context, networks []*api.Network, appdataTypeURL string, appdata []byte) error {
2424
return nil
2525
}
2626

manager/controlapi/network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (s *Server) GetNetwork(ctx context.Context, request *api.GetNetworkRequest)
148148
if n == nil {
149149
return nil, status.Errorf(codes.NotFound, "network %s not found", request.NetworkID)
150150
}
151-
if err := s.networkhooks().OnGetNetwork(ctx, n); err != nil {
151+
if err := s.networkhooks().OnGetNetwork(ctx, n, request.Appdata.GetTypeUrl(), request.Appdata.GetValue()); err != nil {
152152
return nil, err
153153
}
154154
return &api.GetNetworkResponse{
@@ -295,7 +295,7 @@ func (s *Server) ListNetworks(ctx context.Context, request *api.ListNetworksRequ
295295
)
296296
}
297297

298-
if err := s.networkhooks().OnListNetworks(ctx, networks); err != nil {
298+
if err := s.networkhooks().OnListNetworks(ctx, networks, request.Appdata.GetTypeUrl(), request.Appdata.GetValue()); err != nil {
299299
return nil, err
300300
}
301301

0 commit comments

Comments
 (0)