From 308a78db2162b6c1d9e64aa2e36d128c39cb2bd1 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Tue, 28 Mar 2023 09:19:22 +0300 Subject: [PATCH] refactor(edge): deprecate IsEdgeDevice [EE-5046] (#8534) --- api/http/handler/endpoints/endpoint_create.go | 4 ---- api/http/handler/system/system_info.go | 18 +++++---------- api/portainer.go | 6 +++-- app/portainer/react/views/wizard.ts | 2 +- app/portainer/services/api/endpointService.js | 6 ++--- app/portainer/services/fileUpload.js | 4 +--- .../devices/import/importDeviceController.js | 3 +-- .../EnvironmentItem/EnvironmentTypeTag.tsx | 8 +++---- .../environment.service/create.ts | 5 ---- app/react/portainer/environments/types.ts | 1 - .../EndpointTypeView.tsx | 7 ------ .../EnvironmentSelector.tsx | 23 +------------------ .../WizardDocker/WizardDocker.tsx | 8 +------ .../WizardKubernetes/WizardKubernetes.tsx | 5 +--- .../useOnlyEdgeOptions.ts | 17 -------------- .../wizard/hooks/useCreateEdgeDeviceParam.ts | 11 --------- app/react/portainer/system/useSystemInfo.ts | 1 - .../UpgradeBEBanner/UpgradeBEBanner.tsx | 1 - 18 files changed, 21 insertions(+), 109 deletions(-) delete mode 100644 app/react/portainer/environments/wizard/EnvironmentsCreationView/useOnlyEdgeOptions.ts delete mode 100644 app/react/portainer/environments/wizard/hooks/useCreateEdgeDeviceParam.ts diff --git a/api/http/handler/endpoints/endpoint_create.go b/api/http/handler/endpoints/endpoint_create.go index 94abcf113..ecf16e52e 100644 --- a/api/http/handler/endpoints/endpoint_create.go +++ b/api/http/handler/endpoints/endpoint_create.go @@ -38,7 +38,6 @@ type endpointCreatePayload struct { AzureAuthenticationKey string TagIDs []portainer.TagID EdgeCheckinInterval int - IsEdgeDevice bool } type endpointCreationEnum int @@ -381,7 +380,6 @@ func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload) EdgeKey: edgeKey, EdgeCheckinInterval: payload.EdgeCheckinInterval, Kubernetes: portainer.KubernetesDefault(), - IsEdgeDevice: payload.IsEdgeDevice, UserTrusted: true, } @@ -435,7 +433,6 @@ func (handler *Handler) createUnsecuredEndpoint(payload *endpointCreatePayload) Status: portainer.EndpointStatusUp, Snapshots: []portainer.DockerSnapshot{}, Kubernetes: portainer.KubernetesDefault(), - IsEdgeDevice: payload.IsEdgeDevice, } err := handler.snapshotAndPersistEndpoint(endpoint) @@ -501,7 +498,6 @@ func (handler *Handler) createTLSSecuredEndpoint(payload *endpointCreatePayload, Status: portainer.EndpointStatusUp, Snapshots: []portainer.DockerSnapshot{}, Kubernetes: portainer.KubernetesDefault(), - IsEdgeDevice: payload.IsEdgeDevice, } endpoint.Agent.Version = agentVersion diff --git a/api/http/handler/system/system_info.go b/api/http/handler/system/system_info.go index bd2e413a4..d39949cd4 100644 --- a/api/http/handler/system/system_info.go +++ b/api/http/handler/system/system_info.go @@ -10,10 +10,9 @@ import ( ) type systemInfoResponse struct { - Platform plf.ContainerPlatform `json:"platform"` - EdgeAgents int `json:"edgeAgents"` - EdgeDevices int `json:"edgeDevices"` - Agents int `json:"agents"` + Platform plf.ContainerPlatform `json:"platform"` + EdgeAgents int `json:"edgeAgents"` + Agents int `json:"agents"` } // @id systemInfo @@ -34,7 +33,6 @@ func (handler *Handler) systemInfo(w http.ResponseWriter, r *http.Request) *http agents := 0 edgeAgents := 0 - edgeDevices := 0 for _, environment := range environments { if endpointutils.IsAgentEndpoint(&environment) { @@ -45,9 +43,6 @@ func (handler *Handler) systemInfo(w http.ResponseWriter, r *http.Request) *http edgeAgents++ } - if environment.IsEdgeDevice { - edgeDevices++ - } } platform, err := plf.DetermineContainerPlatform() @@ -56,9 +51,8 @@ func (handler *Handler) systemInfo(w http.ResponseWriter, r *http.Request) *http } return response.JSON(w, &systemInfoResponse{ - EdgeAgents: edgeAgents, - EdgeDevices: edgeDevices, - Agents: agents, - Platform: platform, + EdgeAgents: edgeAgents, + Agents: agents, + Platform: platform, }) } diff --git a/api/portainer.go b/api/portainer.go index 7029dc55b..f816deef1 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -388,8 +388,7 @@ type ( LastCheckInDate int64 // QueryDate of each query with the endpoints list QueryDate int64 - // IsEdgeDevice marks if the environment was created as an EdgeDevice - IsEdgeDevice bool + // Whether the device has been trusted or not by the user UserTrusted bool @@ -417,6 +416,9 @@ type ( // Deprecated in DBVersion == 22 Tags []string `json:"Tags"` + + // Deprecated v2.18 + IsEdgeDevice bool } EnvironmentEdgeSettings struct { diff --git a/app/portainer/react/views/wizard.ts b/app/portainer/react/views/wizard.ts index efb8c057e..82635e105 100644 --- a/app/portainer/react/views/wizard.ts +++ b/app/portainer/react/views/wizard.ts @@ -46,7 +46,7 @@ function config($stateRegistryProvider: StateRegistry) { $stateRegistryProvider.register({ name: 'portainer.wizard.endpoints', - url: '/endpoints?edgeDevice', + url: '/endpoints', views: { 'content@': { component: 'wizardEnvironmentTypeSelectView', diff --git a/app/portainer/services/api/endpointService.js b/app/portainer/services/api/endpointService.js index 22b1b45a4..9c726b402 100644 --- a/app/portainer/services/api/endpointService.js +++ b/app/portainer/services/api/endpointService.js @@ -90,8 +90,7 @@ angular.module('portainer.app').factory('EndpointService', [ TLSCAFile, TLSCertFile, TLSKeyFile, - checkinInterval, - isEdgeDevice + checkinInterval ) { var deferred = $q.defer(); @@ -113,8 +112,7 @@ angular.module('portainer.app').factory('EndpointService', [ TLSCAFile, TLSCertFile, TLSKeyFile, - checkinInterval, - isEdgeDevice + checkinInterval ) .then(function success(response) { deferred.resolve(response.data); diff --git a/app/portainer/services/fileUpload.js b/app/portainer/services/fileUpload.js index 0eba97333..914efaea0 100644 --- a/app/portainer/services/fileUpload.js +++ b/app/portainer/services/fileUpload.js @@ -153,8 +153,7 @@ angular.module('portainer.app').factory('FileUploadService', [ TLSCAFile, TLSCertFile, TLSKeyFile, - checkinInterval, - isEdgeDevice + checkinInterval ) { return Upload.upload({ url: 'api/endpoints', @@ -172,7 +171,6 @@ angular.module('portainer.app').factory('FileUploadService', [ TLSCertFile: TLSCertFile, TLSKeyFile: TLSKeyFile, CheckinInterval: checkinInterval, - IsEdgeDevice: isEdgeDevice, }, ignoreLoadingBar: true, }); diff --git a/app/portainer/views/devices/import/importDeviceController.js b/app/portainer/views/devices/import/importDeviceController.js index bc526bd1e..6770196f1 100644 --- a/app/portainer/views/devices/import/importDeviceController.js +++ b/app/portainer/views/devices/import/importDeviceController.js @@ -82,8 +82,7 @@ angular null, null, null, - null, - true + null ); } catch (err) { Notifications.error('Failure', err, 'Unable to create the environment'); diff --git a/app/react/portainer/HomeView/EnvironmentList/EnvironmentItem/EnvironmentTypeTag.tsx b/app/react/portainer/HomeView/EnvironmentList/EnvironmentItem/EnvironmentTypeTag.tsx index bbae9aee2..59dad2f35 100644 --- a/app/react/portainer/HomeView/EnvironmentList/EnvironmentItem/EnvironmentTypeTag.tsx +++ b/app/react/portainer/HomeView/EnvironmentList/EnvironmentItem/EnvironmentTypeTag.tsx @@ -32,11 +32,9 @@ export function EnvironmentTypeTag({ function getTypeLabel(environment: Environment) { if (isEdgeEnvironment(environment.Type)) { - if (environment.Edge.AsyncMode) { - return 'Edge Agent Async'; - } - - return 'Edge Agent Standard'; + return environment.Edge.AsyncMode + ? 'Edge Agent Async' + : 'Edge Agent Standard'; } if (isLocalEnvironment(environment)) { diff --git a/app/react/portainer/environments/environment.service/create.ts b/app/react/portainer/environments/environment.service/create.ts index ba3243e1a..d25de9b96 100644 --- a/app/react/portainer/environments/environment.service/create.ts +++ b/app/react/portainer/environments/environment.service/create.ts @@ -108,7 +108,6 @@ export interface EnvironmentOptions { meta?: EnvironmentMetadata; azure?: AzureSettings; tls?: TLSSettings; - isEdgeDevice?: boolean; pollFrequency?: number; edge?: EdgeSettings; tunnelServerAddr?: string; @@ -167,7 +166,6 @@ interface CreateEdgeAgentEnvironment { tunnelServerAddr?: string; meta?: EnvironmentMetadata; pollFrequency: number; - isEdgeDevice?: boolean; edge: EdgeSettings; } @@ -175,7 +173,6 @@ export function createEdgeAgentEnvironment({ name, portainerUrl, meta = { tagIds: [] }, - isEdgeDevice, pollFrequency, edge, }: CreateEdgeAgentEnvironment) { @@ -188,7 +185,6 @@ export function createEdgeAgentEnvironment({ skipVerify: true, skipClientVerify: true, }, - isEdgeDevice, pollFrequency, edge, meta, @@ -216,7 +212,6 @@ async function createEnvironment( GroupID: groupId, TagIds: arrayToJson(tagIds), CheckinInterval: options.pollFrequency, - IsEdgeDevice: options.isEdgeDevice, }; const { tls, azure } = options; diff --git a/app/react/portainer/environments/types.ts b/app/react/portainer/environments/types.ts index 994434545..bba78ec4d 100644 --- a/app/react/portainer/environments/types.ts +++ b/app/react/portainer/environments/types.ts @@ -152,7 +152,6 @@ export type Environment = { Kubernetes: KubernetesSettings; Nomad: NomadSettings; PublicURL?: string; - IsEdgeDevice?: boolean; UserTrusted: boolean; AMTDeviceGUID?: string; Edge: EnvironmentEdge; diff --git a/app/react/portainer/environments/wizard/EnvironmentTypeSelectView/EndpointTypeView.tsx b/app/react/portainer/environments/wizard/EnvironmentTypeSelectView/EndpointTypeView.tsx index 68b0a8cf5..bf23911be 100644 --- a/app/react/portainer/environments/wizard/EnvironmentTypeSelectView/EndpointTypeView.tsx +++ b/app/react/portainer/environments/wizard/EnvironmentTypeSelectView/EndpointTypeView.tsx @@ -10,8 +10,6 @@ import { PageHeader } from '@@/PageHeader'; import { Widget, WidgetBody, WidgetTitle } from '@@/Widget'; import { FormSection } from '@@/form-components/FormSection'; -import { useCreateEdgeDeviceParam } from '../hooks/useCreateEdgeDeviceParam'; - import { EnvironmentSelector } from './EnvironmentSelector'; import { EnvironmentOptionValue, @@ -20,8 +18,6 @@ import { } from './environment-types'; export function EnvironmentTypeSelectView() { - const createEdgeDevice = useCreateEdgeDeviceParam(); - const [types, setTypes] = useState([]); const { trackEvent } = useAnalytics(); const router = useRouter(); @@ -50,14 +46,12 @@ export function EnvironmentTypeSelectView() {

Set up new environments

); } - -function filterEdgeDevicesIfNeed( - types: EnvironmentOption[], - createEdgeDevice?: boolean -) { - if (!createEdgeDevice) { - return [...types]; - } - - return [...types.filter((eType) => hasEdge.includes(eType.id))]; -} diff --git a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/WizardDocker.tsx b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/WizardDocker.tsx index 90690ecc7..3fc8112e5 100644 --- a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/WizardDocker.tsx +++ b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/WizardDocker.tsx @@ -13,7 +13,6 @@ import { BadgeIcon } from '@@/BadgeIcon'; import { AnalyticsStateKey } from '../types'; import { EdgeAgentTab } from '../shared/EdgeAgentTab'; -import { useFilterEdgeOptionsIfNeeded } from '../useOnlyEdgeOptions'; import { AgentTab } from './AgentTab'; import { APITab } from './APITab'; @@ -24,7 +23,7 @@ interface Props { isDockerStandalone?: boolean; } -const defaultOptions: BoxSelectorOption< +const options: BoxSelectorOption< 'agent' | 'api' | 'socket' | 'edgeAgentStandard' | 'edgeAgentAsync' >[] = _.compact([ { @@ -65,11 +64,6 @@ const defaultOptions: BoxSelectorOption< ]); export function WizardDocker({ onCreate, isDockerStandalone }: Props) { - const options = useFilterEdgeOptionsIfNeeded( - defaultOptions, - 'edgeAgentStandard' - ); - const [creationType, setCreationType] = useState(options[0].value); const tab = getTab(creationType); diff --git a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardKubernetes/WizardKubernetes.tsx b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardKubernetes/WizardKubernetes.tsx index c0af45f76..ed05d8481 100644 --- a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardKubernetes/WizardKubernetes.tsx +++ b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardKubernetes/WizardKubernetes.tsx @@ -15,7 +15,6 @@ import { BEFeatureIndicator } from '@@/BEFeatureIndicator'; import { AnalyticsStateKey } from '../types'; import { EdgeAgentTab } from '../shared/EdgeAgentTab'; -import { useFilterEdgeOptionsIfNeeded } from '../useOnlyEdgeOptions'; import { AgentPanel } from './AgentPanel'; import { KubeConfigTeaserForm } from './KubeConfigTeaserForm'; @@ -30,7 +29,7 @@ type CreationType = | 'edgeAgentAsync' | 'kubeconfig'; -const defaultOptions: BoxSelectorOption[] = _.compact([ +const options: BoxSelectorOption[] = _.compact([ { id: 'agent_endpoint', icon: Zap, @@ -67,8 +66,6 @@ const defaultOptions: BoxSelectorOption[] = _.compact([ ]); export function WizardKubernetes({ onCreate }: Props) { - const options = useFilterEdgeOptionsIfNeeded(defaultOptions, 'agent'); - const [creationType, setCreationType] = useState(options[0].value); const tab = getTab(creationType); diff --git a/app/react/portainer/environments/wizard/EnvironmentsCreationView/useOnlyEdgeOptions.ts b/app/react/portainer/environments/wizard/EnvironmentsCreationView/useOnlyEdgeOptions.ts deleted file mode 100644 index 0714e135a..000000000 --- a/app/react/portainer/environments/wizard/EnvironmentsCreationView/useOnlyEdgeOptions.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { EnvironmentCreationTypes } from '@/react/portainer/environments/types'; - -import { Value, BoxSelectorOption } from '@@/BoxSelector/types'; - -import { useCreateEdgeDeviceParam } from '../hooks/useCreateEdgeDeviceParam'; - -export function useFilterEdgeOptionsIfNeeded< - T extends Value = EnvironmentCreationTypes ->(options: BoxSelectorOption[], edgeValue: T) { - const createEdgeDevice = useCreateEdgeDeviceParam(); - - if (!createEdgeDevice) { - return options; - } - - return options.filter((option) => option.value === edgeValue); -} diff --git a/app/react/portainer/environments/wizard/hooks/useCreateEdgeDeviceParam.ts b/app/react/portainer/environments/wizard/hooks/useCreateEdgeDeviceParam.ts deleted file mode 100644 index 47245375b..000000000 --- a/app/react/portainer/environments/wizard/hooks/useCreateEdgeDeviceParam.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useCurrentStateAndParams } from '@uirouter/react'; - -export function useCreateEdgeDeviceParam() { - const { - params: { edgeDevice: edgeDeviceParam }, - } = useCurrentStateAndParams(); - - const createEdgeDevice = edgeDeviceParam ? edgeDeviceParam === 'true' : false; - - return createEdgeDevice; -} diff --git a/app/react/portainer/system/useSystemInfo.ts b/app/react/portainer/system/useSystemInfo.ts index 41a5eea1a..cd7016170 100644 --- a/app/react/portainer/system/useSystemInfo.ts +++ b/app/react/portainer/system/useSystemInfo.ts @@ -19,7 +19,6 @@ export interface SystemInfoResponse { platform: ContainerPlatform; agents: number; edgeAgents: number; - edgeDevices: number; } async function getSystemInfo() { diff --git a/app/react/sidebar/UpgradeBEBanner/UpgradeBEBanner.tsx b/app/react/sidebar/UpgradeBEBanner/UpgradeBEBanner.tsx index 17ada31dd..5d1fce59a 100644 --- a/app/react/sidebar/UpgradeBEBanner/UpgradeBEBanner.tsx +++ b/app/react/sidebar/UpgradeBEBanner/UpgradeBEBanner.tsx @@ -54,7 +54,6 @@ function UpgradeBEBanner() { nodeCount: nodesCount, platform: systemInfo.platform, edgeAgents: systemInfo.edgeAgents, - edgeDevices: systemInfo.edgeDevices, agents: systemInfo.agents, };