From 13faa75a2d5d6e084e898a75b91fd6e52be7628e Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Mon, 11 Apr 2022 11:26:13 +0300 Subject: [PATCH] fix(endpoints): show edge script when unassociated [EE-2842] (#6730) --- app/portainer/rest/endpoint.js | 2 +- app/portainer/services/api/endpointService.js | 4 +- .../services/modal.service/confirm.ts | 8 +- app/portainer/services/modal.service/index.ts | 4 +- .../views/endpoints/edit/endpoint.html | 203 +++++++++--------- .../endpoints/edit/endpointController.js | 20 +- 6 files changed, 121 insertions(+), 120 deletions(-) diff --git a/app/portainer/rest/endpoint.js b/app/portainer/rest/endpoint.js index 47f82ae93..4f0d4c712 100644 --- a/app/portainer/rest/endpoint.js +++ b/app/portainer/rest/endpoint.js @@ -16,7 +16,7 @@ angular.module('portainer.app').factory('Endpoints', [ }, get: { method: 'GET', params: { id: '@id' } }, update: { method: 'PUT', params: { id: '@id' } }, - deassociate: { method: 'DELETE', params: { id: '@id', action: 'association' } }, + disassociate: { method: 'DELETE', params: { id: '@id', action: 'association' } }, updateAccess: { method: 'PUT', params: { id: '@id', action: 'access' } }, remove: { method: 'DELETE', params: { id: '@id' } }, snapshots: { method: 'POST', params: { action: 'snapshot' } }, diff --git a/app/portainer/services/api/endpointService.js b/app/portainer/services/api/endpointService.js index 7d8b75b5c..5f08fdadf 100644 --- a/app/portainer/services/api/endpointService.js +++ b/app/portainer/services/api/endpointService.js @@ -40,8 +40,8 @@ angular.module('portainer.app').factory('EndpointService', [ return Endpoints.updateAccess({ id: id }, { UserAccessPolicies: userAccessPolicies, TeamAccessPolicies: teamAccessPolicies }).$promise; }; - service.deassociateEndpoint = function (endpointID) { - return Endpoints.deassociate({ id: endpointID }).$promise; + service.disassociateEndpoint = function (endpointID) { + return Endpoints.disassociate({ id: endpointID }).$promise; }; service.updateEndpoint = function (id, payload) { diff --git a/app/portainer/services/modal.service/confirm.ts b/app/portainer/services/modal.service/confirm.ts index eadec442d..407d53017 100644 --- a/app/portainer/services/modal.service/confirm.ts +++ b/app/portainer/services/modal.service/confirm.ts @@ -115,17 +115,17 @@ export function confirmDetachment(message: string, callback: ConfirmCallback) { }); } -export function confirmDeassociate(callback: ConfirmCallback) { +export function confirmDisassociate(callback: ConfirmCallback) { const message = - '

De-associating this Edge environment will mark it as non associated and will clear the registered Edge ID.

' + + '

Disassociating this Edge environment will mark it as non associated and will clear the registered Edge ID.

' + '

Any agent started with the Edge key associated to this environment will be able to re-associate with this environment.

' + '

You can re-use the Edge ID and Edge key that you used to deploy the existing Edge agent to associate a new Edge device to this environment.

'; confirm({ - title: 'About de-associating', + title: 'About disassociating', message: sanitize(message), buttons: { confirm: { - label: 'De-associate', + label: 'Disassociate', className: 'btn-primary', }, }, diff --git a/app/portainer/services/modal.service/index.ts b/app/portainer/services/modal.service/index.ts index f446998a9..b6dcf2a60 100644 --- a/app/portainer/services/modal.service/index.ts +++ b/app/portainer/services/modal.service/index.ts @@ -4,7 +4,7 @@ import bootbox from 'bootbox'; import { cancelRegistryRepositoryAction, confirmAsync, - confirmDeassociate, + confirmDisassociate, confirmDeletion, confirmDetachment, confirmDeletionAsync, @@ -46,7 +46,7 @@ export function ModalServiceAngular() { cancelRegistryRepositoryAction, confirmDeletion, confirmDetachment, - confirmDeassociate, + confirmDisassociate, confirmUpdate, confirmRedeploy, confirmDeletionAsync, diff --git a/app/portainer/views/endpoints/edit/endpoint.html b/app/portainer/views/endpoints/edit/endpoint.html index 5e87052b3..3d580e501 100644 --- a/app/portainer/views/endpoints/edit/endpoint.html +++ b/app/portainer/views/endpoints/edit/endpoint.html @@ -10,113 +10,112 @@
- - -

- - This Edge environment is associated to an Edge environment {{ state.kubernetesEndpoint ? '(Kubernetes)' : '(Docker)' }}. -

-

- Edge key: {{ endpoint.EdgeKey }} -

-

- Edge identifier: {{ endpoint.EdgeID }} -

-

- -

-
-
- - -

- - Refer to the platform related command below to deploy the Edge agent in your remote cluster. -

-

- The agent will communicate with Portainer via {{ edgeKeyDetails.instanceURL }} and tcp://{{ edgeKeyDetails.tunnelServerAddr }} -

-
-
- - +
+ + +

+ + This Edge environment is associated to an Edge environment {{ state.kubernetesEndpoint ? '(Kubernetes)' : '(Docker)' }}. +

+

+ Edge key: {{ endpoint.EdgeKey }} +

+

+ Edge identifier: {{ endpoint.EdgeID }} +

+

+ +

+
+
+ + +

+ + Refer to the platform related command below to deploy the Edge agent in your remote cluster. +

+

+ The agent will communicate with Portainer via {{ edgeKeyDetails.instanceURL }} and tcp://{{ edgeKeyDetails.tunnelServerAddr }} +

+
+
+ + +
-
- -
- -
- -
- -
- +
+ +
+
+ +
+ +
-
- -
- - - {{ - dockerCommands[state.deploymentTab][state.platformType](agentShortVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) - }} - - - {{ - dockerCommands[state.deploymentTab][state.platformType](agentVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) - }} - - - {{ - dockerCommands[state.deploymentTab][state.platformType](agentVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) - }} - -
- Copy command - + + + {{ + dockerCommands[state.deploymentTab][state.platformType](agentShortVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) + }} + + + {{ + dockerCommands[state.deploymentTab][state.platformType](agentVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) + }} + + + {{ + dockerCommands[state.deploymentTab][state.platformType](agentVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) + }} + + +
+ Copy command + +
-
-
Join token
-

- - For those prestaging the edge agent, use the following join token to associate the Edge agent with this environment. -

-

You can read more about pre-staging in the userguide available here.

-
- - {{ endpoint.EdgeKey }} - -
- Copy token - +
Join token
+

+ + For those prestaging the edge agent, use the following join token to associate the Edge agent with this environment. +

+

You can read more about pre-staging in the userguide available here.

+
+ + {{ endpoint.EdgeKey }} + +
+ Copy token + +
-
- - - + + +
+ You should configure the features available in this Kubernetes environment in the diff --git a/app/portainer/views/endpoints/edit/endpointController.js b/app/portainer/views/endpoints/edit/endpointController.js index ba9706325..a60b31828 100644 --- a/app/portainer/views/endpoints/edit/endpointController.js +++ b/app/portainer/views/endpoints/edit/endpointController.js @@ -47,6 +47,7 @@ function EndpointController( kubernetesEndpoint: false, agentEndpoint: false, edgeEndpoint: false, + edgeAssociated: false, allowCreate: Authentication.isAdmin(), availableEdgeAgentCheckinOptions: [ { key: 'Use default interval', value: 0 }, @@ -139,24 +140,24 @@ function EndpointController( } } - $scope.onDeassociateEndpoint = async function () { - ModalService.confirmDeassociate((confirmed) => { + $scope.onDisassociateEndpoint = async function () { + ModalService.confirmDisassociate((confirmed) => { if (confirmed) { - deassociateEndpoint(); + disassociateEndpoint(); } }); }; - async function deassociateEndpoint() { + async function disassociateEndpoint() { var endpoint = $scope.endpoint; try { $scope.state.actionInProgress = true; - await EndpointService.deassociateEndpoint(endpoint.Id); - Notifications.success('Environment de-associated', $scope.endpoint.Name); + await EndpointService.disassociateEndpoint(endpoint.Id); + Notifications.success('Environment disassociated', $scope.endpoint.Name); $state.reload(); } catch (err) { - Notifications.error('Failure', err, 'Unable to de-associate environment'); + Notifications.error('Failure', err, 'Unable to disassociate environment'); } finally { $scope.state.actionInProgress = false; } @@ -280,6 +281,8 @@ function EndpointController( if (endpoint.Type === PortainerEndpointTypes.EdgeAgentOnDockerEnvironment || endpoint.Type === PortainerEndpointTypes.EdgeAgentOnKubernetesEnvironment) { $scope.edgeKeyDetails = decodeEdgeKey(endpoint.EdgeKey); + + $scope.state.edgeAssociated = !!endpoint.EdgeID; endpoint.EdgeID = endpoint.EdgeID || uuidv4(); $scope.state.availableEdgeAgentCheckinOptions[0].key += ` (${settings.EdgeAgentCheckinInterval} seconds)`; @@ -291,8 +294,7 @@ function EndpointController( configureState(); - const disconnectedEdge = $scope.state.edgeEndpoint && !endpoint.EdgeID; - if (EndpointHelper.isDockerEndpoint(endpoint) && !disconnectedEdge) { + if (EndpointHelper.isDockerEndpoint(endpoint) && $scope.state.edgeAssociated) { $scope.state.showAMTInfo = settings && settings.openAMTConfiguration && settings.openAMTConfiguration.enabled; } } catch (err) {