From 8e40eb1844eaa5fa0cac0f1e4cbecd397148bfb7 Mon Sep 17 00:00:00 2001 From: "Miguel A. C" <30386061+doncicuto@users.noreply.github.com> Date: Thu, 21 Dec 2017 09:53:34 +0100 Subject: [PATCH] feat(service): add hosts file entries in service create/update (#1511) --- .../createService/createServiceController.js | 26 +++++++++ .../createService/createservice.html | 23 ++++++++ app/components/service/includes/hosts.html | 57 +++++++++++++++++++ app/components/service/service.html | 1 + app/components/service/serviceController.js | 20 ++++++- app/helpers/serviceHelper.js | 26 +++++++++ 6 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 app/components/service/includes/hosts.html diff --git a/app/components/createService/createServiceController.js b/app/components/createService/createServiceController.js index ab85f14ed..369c219cf 100644 --- a/app/components/createService/createServiceController.js +++ b/app/components/createService/createServiceController.js @@ -20,6 +20,7 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C Volumes: [], Network: '', ExtraNetworks: [], + HostsEntries: [], Ports: [], Parallelism: 1, PlacementConstraints: [], @@ -69,6 +70,14 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C $scope.formValues.ExtraNetworks.splice(index, 1); }; + $scope.addHostsEntry = function() { + $scope.formValues.HostsEntries.push({}); + }; + + $scope.removeHostsEntry = function(index) { + $scope.formValues.HostsEntries.splice(index, 1); + }; + $scope.addVolume = function() { $scope.formValues.Volumes.push({ Source: '', Target: '', ReadOnly: false, Type: 'volume' }); }; @@ -244,6 +253,22 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C config.Networks = _.uniqWith(networks, _.isEqual); } + function prepareHostsEntries(config, input) { + var hostsEntries = []; + if (input.HostsEntries) { + input.HostsEntries.forEach(function (host_ip) { + if (host_ip.value && host_ip.value.indexOf(':') && host_ip.value.split(':').length === 2) { + var keyVal = host_ip.value.split(':'); + // Hosts file format, IP_address canonical_hostname + hostsEntries.push(keyVal[1] + ' ' + keyVal[0]); + } + }); + if (hostsEntries.length > 0) { + config.TaskTemplate.ContainerSpec.Hosts = hostsEntries; + } + } + } + function prepareUpdateConfig(config, input) { config.UpdateConfig = { Parallelism: input.Parallelism || 0, @@ -355,6 +380,7 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C prepareLabelsConfig(config, input); prepareVolumes(config, input); prepareNetworks(config, input); + prepareHostsEntries(config, input); prepareUpdateConfig(config, input); prepareConfigConfig(config, input); prepareSecretConfig(config, input); diff --git a/app/components/createService/createservice.html b/app/components/createService/createservice.html index 9a86ee73c..3f96b372c 100644 --- a/app/components/createService/createservice.html +++ b/app/components/createService/createservice.html @@ -308,6 +308,29 @@ + +
The Hosts file has no extra entries.
+Hostname | +IP | +
---|---|
+
+
+
+ |
+
+
+
+
+
+
+
+ |
+