From 34667bd3b3ae94b88b247c30f72c1870846278f7 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Tue, 15 Jan 2019 12:10:29 +1300 Subject: [PATCH] fix(network-creation): force overlay network creation on manager node (#2622) * fix(network-creation): force overlay network creation on manager node * fix(app): fix function override * fix(app): use portainerAgentManagerOperation in interceptor --- app/app.js | 2 +- app/config.js | 3 +++ .../views/networks/create/createNetworkController.js | 8 +++++++- app/portainer/services/httpRequestHelper.js | 12 +++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/app.js b/app/app.js index 021f4d58a..8d6c669b1 100644 --- a/app/app.js +++ b/app/app.js @@ -30,7 +30,7 @@ function ($rootScope, $state, Authentication, authManager, StateManager, Endpoin }; $transitions.onBefore({ to: 'docker.**' }, function() { - HttpRequestHelper.resetAgentTargetQueue(); + HttpRequestHelper.resetAgentHeaders(); }); }]); diff --git a/app/config.js b/app/config.js index cd21e1f08..268b39288 100644 --- a/app/config.js +++ b/app/config.js @@ -27,6 +27,9 @@ angular.module('portainer') request: function(config) { if (config.url.indexOf('/docker/') > -1) { config.headers['X-PortainerAgent-Target'] = HttpRequestHelper.portainerAgentTargetHeader(); + if (HttpRequestHelper.portainerAgentManagerOperation()) { + config.headers['X-PortainerAgent-ManagerOperation'] = '1'; + } } return config; } diff --git a/app/docker/views/networks/create/createNetworkController.js b/app/docker/views/networks/create/createNetworkController.js index a2893f353..eb92079f3 100644 --- a/app/docker/views/networks/create/createNetworkController.js +++ b/app/docker/views/networks/create/createNetworkController.js @@ -126,6 +126,7 @@ angular.module('portainer.docker') function createNetwork(context) { HttpRequestHelper.setPortainerAgentTargetHeader(context.nodeName); + HttpRequestHelper.setPortainerAgentManagerOperation(context.managerOperation); $scope.state.actionInProgress = true; NetworkService.create(context.networkConfiguration) @@ -162,12 +163,17 @@ angular.module('portainer.docker') var creationContext = { nodeName: $scope.formValues.NodeName, + managerOperation: false, networkConfiguration: networkConfiguration, userDetails: userDetails, accessControlData: accessControlData, reload: true }; + if ($scope.applicationState.endpoint.mode.agentProxy && $scope.applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && $scope.config.Driver === 'overlay') { + creationContext.managerOperation = true; + } + if ($scope.config.Driver === 'macvlan') { if ($scope.formValues.Macvlan.Scope === 'local') { modifyNetworkConfigurationForMacvlanConfigOnly(networkConfiguration); @@ -205,4 +211,4 @@ angular.module('portainer.docker') initView(); } - ]); \ No newline at end of file + ]); diff --git a/app/portainer/services/httpRequestHelper.js b/app/portainer/services/httpRequestHelper.js index 1d5b5dbe8..d63e2fe2f 100644 --- a/app/portainer/services/httpRequestHelper.js +++ b/app/portainer/services/httpRequestHelper.js @@ -5,6 +5,7 @@ angular.module('portainer.app') var service = {}; var headers = {}; headers.agentTargetQueue = []; + headers.agentManagerOperation = false; service.registryAuthenticationHeader = function() { return headers.registryAuthentication; @@ -36,9 +37,18 @@ angular.module('portainer.app') } }; - service.resetAgentTargetQueue = function() { + service.setPortainerAgentManagerOperation = function(set) { + headers.agentManagerOperation = set; + }; + + service.portainerAgentManagerOperation = function() { + return headers.agentManagerOperation; + }; + + service.resetAgentHeaders = function() { headers.agentTargetQueue = []; delete headers.agentTargetLastValue; + headers.agentManagerOperation = false; }; return service;