refactor(edge): deprecate IsEdgeDevice [EE-5046] (#8534)

pull/8728/head
Chaim Lev-Ari 2023-03-28 09:19:22 +03:00 committed by GitHub
parent 814fc9dfc0
commit 308a78db21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 21 additions and 109 deletions

View File

@ -38,7 +38,6 @@ type endpointCreatePayload struct {
AzureAuthenticationKey string AzureAuthenticationKey string
TagIDs []portainer.TagID TagIDs []portainer.TagID
EdgeCheckinInterval int EdgeCheckinInterval int
IsEdgeDevice bool
} }
type endpointCreationEnum int type endpointCreationEnum int
@ -381,7 +380,6 @@ func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload)
EdgeKey: edgeKey, EdgeKey: edgeKey,
EdgeCheckinInterval: payload.EdgeCheckinInterval, EdgeCheckinInterval: payload.EdgeCheckinInterval,
Kubernetes: portainer.KubernetesDefault(), Kubernetes: portainer.KubernetesDefault(),
IsEdgeDevice: payload.IsEdgeDevice,
UserTrusted: true, UserTrusted: true,
} }
@ -435,7 +433,6 @@ func (handler *Handler) createUnsecuredEndpoint(payload *endpointCreatePayload)
Status: portainer.EndpointStatusUp, Status: portainer.EndpointStatusUp,
Snapshots: []portainer.DockerSnapshot{}, Snapshots: []portainer.DockerSnapshot{},
Kubernetes: portainer.KubernetesDefault(), Kubernetes: portainer.KubernetesDefault(),
IsEdgeDevice: payload.IsEdgeDevice,
} }
err := handler.snapshotAndPersistEndpoint(endpoint) err := handler.snapshotAndPersistEndpoint(endpoint)
@ -501,7 +498,6 @@ func (handler *Handler) createTLSSecuredEndpoint(payload *endpointCreatePayload,
Status: portainer.EndpointStatusUp, Status: portainer.EndpointStatusUp,
Snapshots: []portainer.DockerSnapshot{}, Snapshots: []portainer.DockerSnapshot{},
Kubernetes: portainer.KubernetesDefault(), Kubernetes: portainer.KubernetesDefault(),
IsEdgeDevice: payload.IsEdgeDevice,
} }
endpoint.Agent.Version = agentVersion endpoint.Agent.Version = agentVersion

View File

@ -12,7 +12,6 @@ import (
type systemInfoResponse struct { type systemInfoResponse struct {
Platform plf.ContainerPlatform `json:"platform"` Platform plf.ContainerPlatform `json:"platform"`
EdgeAgents int `json:"edgeAgents"` EdgeAgents int `json:"edgeAgents"`
EdgeDevices int `json:"edgeDevices"`
Agents int `json:"agents"` Agents int `json:"agents"`
} }
@ -34,7 +33,6 @@ func (handler *Handler) systemInfo(w http.ResponseWriter, r *http.Request) *http
agents := 0 agents := 0
edgeAgents := 0 edgeAgents := 0
edgeDevices := 0
for _, environment := range environments { for _, environment := range environments {
if endpointutils.IsAgentEndpoint(&environment) { if endpointutils.IsAgentEndpoint(&environment) {
@ -45,9 +43,6 @@ func (handler *Handler) systemInfo(w http.ResponseWriter, r *http.Request) *http
edgeAgents++ edgeAgents++
} }
if environment.IsEdgeDevice {
edgeDevices++
}
} }
platform, err := plf.DetermineContainerPlatform() platform, err := plf.DetermineContainerPlatform()
@ -57,7 +52,6 @@ func (handler *Handler) systemInfo(w http.ResponseWriter, r *http.Request) *http
return response.JSON(w, &systemInfoResponse{ return response.JSON(w, &systemInfoResponse{
EdgeAgents: edgeAgents, EdgeAgents: edgeAgents,
EdgeDevices: edgeDevices,
Agents: agents, Agents: agents,
Platform: platform, Platform: platform,
}) })

View File

@ -388,8 +388,7 @@ type (
LastCheckInDate int64 LastCheckInDate int64
// QueryDate of each query with the endpoints list // QueryDate of each query with the endpoints list
QueryDate int64 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 // Whether the device has been trusted or not by the user
UserTrusted bool UserTrusted bool
@ -417,6 +416,9 @@ type (
// Deprecated in DBVersion == 22 // Deprecated in DBVersion == 22
Tags []string `json:"Tags"` Tags []string `json:"Tags"`
// Deprecated v2.18
IsEdgeDevice bool
} }
EnvironmentEdgeSettings struct { EnvironmentEdgeSettings struct {

View File

@ -46,7 +46,7 @@ function config($stateRegistryProvider: StateRegistry) {
$stateRegistryProvider.register({ $stateRegistryProvider.register({
name: 'portainer.wizard.endpoints', name: 'portainer.wizard.endpoints',
url: '/endpoints?edgeDevice', url: '/endpoints',
views: { views: {
'content@': { 'content@': {
component: 'wizardEnvironmentTypeSelectView', component: 'wizardEnvironmentTypeSelectView',

View File

@ -90,8 +90,7 @@ angular.module('portainer.app').factory('EndpointService', [
TLSCAFile, TLSCAFile,
TLSCertFile, TLSCertFile,
TLSKeyFile, TLSKeyFile,
checkinInterval, checkinInterval
isEdgeDevice
) { ) {
var deferred = $q.defer(); var deferred = $q.defer();
@ -113,8 +112,7 @@ angular.module('portainer.app').factory('EndpointService', [
TLSCAFile, TLSCAFile,
TLSCertFile, TLSCertFile,
TLSKeyFile, TLSKeyFile,
checkinInterval, checkinInterval
isEdgeDevice
) )
.then(function success(response) { .then(function success(response) {
deferred.resolve(response.data); deferred.resolve(response.data);

View File

@ -153,8 +153,7 @@ angular.module('portainer.app').factory('FileUploadService', [
TLSCAFile, TLSCAFile,
TLSCertFile, TLSCertFile,
TLSKeyFile, TLSKeyFile,
checkinInterval, checkinInterval
isEdgeDevice
) { ) {
return Upload.upload({ return Upload.upload({
url: 'api/endpoints', url: 'api/endpoints',
@ -172,7 +171,6 @@ angular.module('portainer.app').factory('FileUploadService', [
TLSCertFile: TLSCertFile, TLSCertFile: TLSCertFile,
TLSKeyFile: TLSKeyFile, TLSKeyFile: TLSKeyFile,
CheckinInterval: checkinInterval, CheckinInterval: checkinInterval,
IsEdgeDevice: isEdgeDevice,
}, },
ignoreLoadingBar: true, ignoreLoadingBar: true,
}); });

View File

@ -82,8 +82,7 @@ angular
null, null,
null, null,
null, null,
null, null
true
); );
} catch (err) { } catch (err) {
Notifications.error('Failure', err, 'Unable to create the environment'); Notifications.error('Failure', err, 'Unable to create the environment');

View File

@ -32,11 +32,9 @@ export function EnvironmentTypeTag({
function getTypeLabel(environment: Environment) { function getTypeLabel(environment: Environment) {
if (isEdgeEnvironment(environment.Type)) { if (isEdgeEnvironment(environment.Type)) {
if (environment.Edge.AsyncMode) { return environment.Edge.AsyncMode
return 'Edge Agent Async'; ? 'Edge Agent Async'
} : 'Edge Agent Standard';
return 'Edge Agent Standard';
} }
if (isLocalEnvironment(environment)) { if (isLocalEnvironment(environment)) {

View File

@ -108,7 +108,6 @@ export interface EnvironmentOptions {
meta?: EnvironmentMetadata; meta?: EnvironmentMetadata;
azure?: AzureSettings; azure?: AzureSettings;
tls?: TLSSettings; tls?: TLSSettings;
isEdgeDevice?: boolean;
pollFrequency?: number; pollFrequency?: number;
edge?: EdgeSettings; edge?: EdgeSettings;
tunnelServerAddr?: string; tunnelServerAddr?: string;
@ -167,7 +166,6 @@ interface CreateEdgeAgentEnvironment {
tunnelServerAddr?: string; tunnelServerAddr?: string;
meta?: EnvironmentMetadata; meta?: EnvironmentMetadata;
pollFrequency: number; pollFrequency: number;
isEdgeDevice?: boolean;
edge: EdgeSettings; edge: EdgeSettings;
} }
@ -175,7 +173,6 @@ export function createEdgeAgentEnvironment({
name, name,
portainerUrl, portainerUrl,
meta = { tagIds: [] }, meta = { tagIds: [] },
isEdgeDevice,
pollFrequency, pollFrequency,
edge, edge,
}: CreateEdgeAgentEnvironment) { }: CreateEdgeAgentEnvironment) {
@ -188,7 +185,6 @@ export function createEdgeAgentEnvironment({
skipVerify: true, skipVerify: true,
skipClientVerify: true, skipClientVerify: true,
}, },
isEdgeDevice,
pollFrequency, pollFrequency,
edge, edge,
meta, meta,
@ -216,7 +212,6 @@ async function createEnvironment(
GroupID: groupId, GroupID: groupId,
TagIds: arrayToJson(tagIds), TagIds: arrayToJson(tagIds),
CheckinInterval: options.pollFrequency, CheckinInterval: options.pollFrequency,
IsEdgeDevice: options.isEdgeDevice,
}; };
const { tls, azure } = options; const { tls, azure } = options;

View File

@ -152,7 +152,6 @@ export type Environment = {
Kubernetes: KubernetesSettings; Kubernetes: KubernetesSettings;
Nomad: NomadSettings; Nomad: NomadSettings;
PublicURL?: string; PublicURL?: string;
IsEdgeDevice?: boolean;
UserTrusted: boolean; UserTrusted: boolean;
AMTDeviceGUID?: string; AMTDeviceGUID?: string;
Edge: EnvironmentEdge; Edge: EnvironmentEdge;

View File

@ -10,8 +10,6 @@ import { PageHeader } from '@@/PageHeader';
import { Widget, WidgetBody, WidgetTitle } from '@@/Widget'; import { Widget, WidgetBody, WidgetTitle } from '@@/Widget';
import { FormSection } from '@@/form-components/FormSection'; import { FormSection } from '@@/form-components/FormSection';
import { useCreateEdgeDeviceParam } from '../hooks/useCreateEdgeDeviceParam';
import { EnvironmentSelector } from './EnvironmentSelector'; import { EnvironmentSelector } from './EnvironmentSelector';
import { import {
EnvironmentOptionValue, EnvironmentOptionValue,
@ -20,8 +18,6 @@ import {
} from './environment-types'; } from './environment-types';
export function EnvironmentTypeSelectView() { export function EnvironmentTypeSelectView() {
const createEdgeDevice = useCreateEdgeDeviceParam();
const [types, setTypes] = useState<EnvironmentOptionValue[]>([]); const [types, setTypes] = useState<EnvironmentOptionValue[]>([]);
const { trackEvent } = useAnalytics(); const { trackEvent } = useAnalytics();
const router = useRouter(); const router = useRouter();
@ -50,14 +46,12 @@ export function EnvironmentTypeSelectView() {
<EnvironmentSelector <EnvironmentSelector
value={types} value={types}
onChange={setTypes} onChange={setTypes}
createEdgeDevice={createEdgeDevice}
options={existingEnvironmentTypes} options={existingEnvironmentTypes}
/> />
<p className="control-label !mb-2">Set up new environments</p> <p className="control-label !mb-2">Set up new environments</p>
<EnvironmentSelector <EnvironmentSelector
value={types} value={types}
onChange={setTypes} onChange={setTypes}
createEdgeDevice={createEdgeDevice}
options={newEnvironmentTypes} options={newEnvironmentTypes}
hiddenSpacingCount={ hiddenSpacingCount={
existingEnvironmentTypes.length - existingEnvironmentTypes.length -
@ -102,7 +96,6 @@ export function EnvironmentTypeSelectView() {
router.stateService.go('portainer.wizard.endpoints.create', { router.stateService.go('portainer.wizard.endpoints.create', {
envType: types, envType: types,
...(createEdgeDevice ? { edgeDevice: createEdgeDevice } : {}),
}); });
} }
} }

View File

@ -6,28 +6,18 @@ interface Props {
value: EnvironmentOptionValue[]; value: EnvironmentOptionValue[];
onChange(value: EnvironmentOptionValue[]): void; onChange(value: EnvironmentOptionValue[]): void;
options: EnvironmentOption[]; options: EnvironmentOption[];
createEdgeDevice?: boolean;
hiddenSpacingCount?: number; hiddenSpacingCount?: number;
} }
const hasEdge: EnvironmentOptionValue[] = [
'dockerStandalone',
'dockerSwarm',
'kubernetes',
];
export function EnvironmentSelector({ export function EnvironmentSelector({
value, value,
onChange, onChange,
createEdgeDevice,
options, options,
hiddenSpacingCount, hiddenSpacingCount,
}: Props) { }: Props) {
const filteredOptions = filterEdgeDevicesIfNeed(options, createEdgeDevice);
return ( return (
<BoxSelector <BoxSelector
options={filteredOptions} options={options}
isMulti isMulti
value={value} value={value}
onChange={onChange} onChange={onChange}
@ -36,14 +26,3 @@ export function EnvironmentSelector({
/> />
); );
} }
function filterEdgeDevicesIfNeed(
types: EnvironmentOption[],
createEdgeDevice?: boolean
) {
if (!createEdgeDevice) {
return [...types];
}
return [...types.filter((eType) => hasEdge.includes(eType.id))];
}

View File

@ -13,7 +13,6 @@ import { BadgeIcon } from '@@/BadgeIcon';
import { AnalyticsStateKey } from '../types'; import { AnalyticsStateKey } from '../types';
import { EdgeAgentTab } from '../shared/EdgeAgentTab'; import { EdgeAgentTab } from '../shared/EdgeAgentTab';
import { useFilterEdgeOptionsIfNeeded } from '../useOnlyEdgeOptions';
import { AgentTab } from './AgentTab'; import { AgentTab } from './AgentTab';
import { APITab } from './APITab'; import { APITab } from './APITab';
@ -24,7 +23,7 @@ interface Props {
isDockerStandalone?: boolean; isDockerStandalone?: boolean;
} }
const defaultOptions: BoxSelectorOption< const options: BoxSelectorOption<
'agent' | 'api' | 'socket' | 'edgeAgentStandard' | 'edgeAgentAsync' 'agent' | 'api' | 'socket' | 'edgeAgentStandard' | 'edgeAgentAsync'
>[] = _.compact([ >[] = _.compact([
{ {
@ -65,11 +64,6 @@ const defaultOptions: BoxSelectorOption<
]); ]);
export function WizardDocker({ onCreate, isDockerStandalone }: Props) { export function WizardDocker({ onCreate, isDockerStandalone }: Props) {
const options = useFilterEdgeOptionsIfNeeded(
defaultOptions,
'edgeAgentStandard'
);
const [creationType, setCreationType] = useState(options[0].value); const [creationType, setCreationType] = useState(options[0].value);
const tab = getTab(creationType); const tab = getTab(creationType);

View File

@ -15,7 +15,6 @@ import { BEFeatureIndicator } from '@@/BEFeatureIndicator';
import { AnalyticsStateKey } from '../types'; import { AnalyticsStateKey } from '../types';
import { EdgeAgentTab } from '../shared/EdgeAgentTab'; import { EdgeAgentTab } from '../shared/EdgeAgentTab';
import { useFilterEdgeOptionsIfNeeded } from '../useOnlyEdgeOptions';
import { AgentPanel } from './AgentPanel'; import { AgentPanel } from './AgentPanel';
import { KubeConfigTeaserForm } from './KubeConfigTeaserForm'; import { KubeConfigTeaserForm } from './KubeConfigTeaserForm';
@ -30,7 +29,7 @@ type CreationType =
| 'edgeAgentAsync' | 'edgeAgentAsync'
| 'kubeconfig'; | 'kubeconfig';
const defaultOptions: BoxSelectorOption<CreationType>[] = _.compact([ const options: BoxSelectorOption<CreationType>[] = _.compact([
{ {
id: 'agent_endpoint', id: 'agent_endpoint',
icon: Zap, icon: Zap,
@ -67,8 +66,6 @@ const defaultOptions: BoxSelectorOption<CreationType>[] = _.compact([
]); ]);
export function WizardKubernetes({ onCreate }: Props) { export function WizardKubernetes({ onCreate }: Props) {
const options = useFilterEdgeOptionsIfNeeded(defaultOptions, 'agent');
const [creationType, setCreationType] = useState(options[0].value); const [creationType, setCreationType] = useState(options[0].value);
const tab = getTab(creationType); const tab = getTab(creationType);

View File

@ -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<T>[], edgeValue: T) {
const createEdgeDevice = useCreateEdgeDeviceParam();
if (!createEdgeDevice) {
return options;
}
return options.filter((option) => option.value === edgeValue);
}

View File

@ -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;
}

View File

@ -19,7 +19,6 @@ export interface SystemInfoResponse {
platform: ContainerPlatform; platform: ContainerPlatform;
agents: number; agents: number;
edgeAgents: number; edgeAgents: number;
edgeDevices: number;
} }
async function getSystemInfo() { async function getSystemInfo() {

View File

@ -54,7 +54,6 @@ function UpgradeBEBanner() {
nodeCount: nodesCount, nodeCount: nodesCount,
platform: systemInfo.platform, platform: systemInfo.platform,
edgeAgents: systemInfo.edgeAgents, edgeAgents: systemInfo.edgeAgents,
edgeDevices: systemInfo.edgeDevices,
agents: systemInfo.agents, agents: systemInfo.agents,
}; };