1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 13:59:40 +02:00

feat(edge): associate edge env to meta fields [EE-3209] (#8551)

* refactor(edge/groups): load edge groups in selector

fix(edge/stacks): remove double groups title

* feat(edge): supply meta fields to edge script [EE-5043]

* feat(edge): auto assign aeec envs to groups and tags [EE-5043]

fix [EE-5043]

fix(envs): fix global key test

* fix(edge/groups): save group type

* refactor(edge/devices): move loading of devices to table

* refactor(tags): select paramter for query

* feat(edge/devices): show meta fields

* refactor(home): simplify filter

* feat(edge/devices): filter by meta fields

* refactor(edge/devices): break filter and loading hook
This commit is contained in:
Chaim Lev-Ari 2023-03-06 22:25:04 +02:00 committed by GitHub
parent 03712966e4
commit 70710cfeb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 554 additions and 263 deletions

View file

@ -52,14 +52,6 @@ export const commandsTabs: Record<string, CommandTab> = {
},
} as const;
function buildDockerEnvVars(envVars: string, defaultVars: string[]) {
const vars = defaultVars.concat(
envVars.split(',').filter((s) => s.length > 0)
);
return vars.map((s) => `-e ${s}`).join(' \\\n ');
}
export function buildLinuxStandaloneCommand(
agentVersion: string,
edgeKey: string,
@ -70,16 +62,16 @@ export function buildLinuxStandaloneCommand(
) {
const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties;
const env = buildDockerEnvVars(
envVars,
buildDefaultEnvVars(
const env = buildDockerEnvVars(envVars, [
...buildDefaultDockerEnvVars(
edgeKey,
allowSelfSignedCertificates,
!edgeIdGenerator ? edgeId : undefined,
agentSecret,
useAsyncMode
)
);
),
...metaEnvVars(properties),
]);
return `${
edgeIdGenerator ? `PORTAINER_EDGE_ID=$(${edgeIdGenerator}) \n\n` : ''
@ -106,16 +98,16 @@ export function buildWindowsStandaloneCommand(
) {
const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties;
const env = buildDockerEnvVars(
envVars,
buildDefaultEnvVars(
const env = buildDockerEnvVars(envVars, [
...buildDefaultDockerEnvVars(
edgeKey,
allowSelfSignedCertificates,
edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId,
agentSecret,
useAsyncMode
)
);
),
...metaEnvVars(properties),
]);
return `${
edgeIdGenerator
@ -144,7 +136,7 @@ export function buildLinuxSwarmCommand(
const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties;
const env = buildDockerEnvVars(envVars, [
...buildDefaultEnvVars(
...buildDefaultDockerEnvVars(
edgeKey,
allowSelfSignedCertificates,
!edgeIdGenerator ? edgeId : undefined,
@ -152,6 +144,7 @@ export function buildLinuxSwarmCommand(
useAsyncMode
),
'AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent',
...metaEnvVars(properties),
]);
return `${
@ -186,7 +179,7 @@ export function buildWindowsSwarmCommand(
const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties;
const env = buildDockerEnvVars(envVars, [
...buildDefaultEnvVars(
...buildDefaultDockerEnvVars(
edgeKey,
allowSelfSignedCertificates,
edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId,
@ -194,6 +187,7 @@ export function buildWindowsSwarmCommand(
useAsyncMode
),
'AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent',
...metaEnvVars(properties),
]);
return `${
@ -229,17 +223,18 @@ export function buildLinuxKubernetesCommand(
const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties;
const agentShortVersion = getAgentShortVersion(agentVersion);
let envVarsTrimmed = envVars.trim();
if (useAsyncMode) {
envVarsTrimmed += `EDGE_ASYNC=1`;
}
const allEnvVars = buildEnvVars(
envVars,
_.compact([useAsyncMode && 'EDGE_ASYNC=1', ...metaEnvVars(properties)])
);
const idEnvVar = edgeIdGenerator
? `PORTAINER_EDGE_ID=$(${edgeIdGenerator}) \n\n`
: '';
const edgeIdVar = !edgeIdGenerator && edgeId ? edgeId : '$PORTAINER_EDGE_ID';
const selfSigned = allowSelfSignedCertificates ? '1' : '0';
return `${idEnvVar}curl https://downloads.portainer.io/ee${agentShortVersion}/portainer-edge-agent-setup.sh | bash -s -- "${edgeIdVar}" "${edgeKey}" "${selfSigned}" "${agentSecret}" "${envVarsTrimmed}"`;
return `${idEnvVar}curl https://downloads.portainer.io/ee${agentShortVersion}/portainer-edge-agent-setup.sh | bash -s -- "${edgeIdVar}" "${edgeKey}" "${selfSigned}" "${agentSecret}" "${allEnvVars}"`;
}
export function buildLinuxNomadCommand(
@ -259,10 +254,11 @@ export function buildLinuxNomadCommand(
} = properties;
const agentShortVersion = getAgentShortVersion(agentVersion);
let envVarsTrimmed = envVars.trim();
if (useAsyncMode) {
envVarsTrimmed += `EDGE_ASYNC=1`;
}
const allEnvVars = buildEnvVars(
envVars,
_.compact([useAsyncMode && 'EDGE_ASYNC=1', ...metaEnvVars(properties)])
);
const selfSigned = allowSelfSignedCertificates ? '1' : '0';
const idEnvVar = edgeIdGenerator
@ -270,10 +266,16 @@ export function buildLinuxNomadCommand(
: '';
const edgeIdVar = !edgeIdGenerator && edgeId ? edgeId : '$PORTAINER_EDGE_ID';
return `${idEnvVar}curl https://downloads.portainer.io/ee${agentShortVersion}/portainer-edge-agent-nomad-setup.sh | bash -s -- "${nomadToken}" "${edgeIdVar}" "${edgeKey}" "${selfSigned}" "${envVarsTrimmed}" "${agentSecret}" "${tlsEnabled}"`;
return `${idEnvVar}curl https://downloads.portainer.io/ee${agentShortVersion}/portainer-edge-agent-nomad-setup.sh | bash -s -- "${nomadToken}" "${edgeIdVar}" "${edgeKey}" "${selfSigned}" "${allEnvVars}" "${agentSecret}" "${tlsEnabled}"`;
}
function buildDefaultEnvVars(
function buildDockerEnvVars(envVars: string, moreVars: string[]) {
const vars = moreVars.concat(envVars.split(',').filter((s) => s.length > 0));
return vars.map((s) => `-e ${s}`).join(' \\\n ');
}
function buildDefaultDockerEnvVars(
edgeKey: string,
allowSelfSignedCerts: boolean,
edgeId = '$PORTAINER_EDGE_ID',
@ -289,3 +291,22 @@ function buildDefaultEnvVars(
useAsyncMode ? 'EDGE_ASYNC=1' : '',
]);
}
const ENV_VAR_SEPARATOR = ',';
const VAR_LIST_SEPARATOR = ':';
function buildEnvVars(envVars: string, moreVars: string[]) {
return _.compact([envVars.trim(), ...moreVars]).join(ENV_VAR_SEPARATOR);
}
function metaEnvVars({
edgeGroupsIds,
group,
tagsIds,
}: Pick<ScriptFormValues, 'edgeGroupsIds' | 'tagsIds' | 'group'>) {
return _.compact([
edgeGroupsIds.length &&
`EDGE_GROUPS=${edgeGroupsIds.join(VAR_LIST_SEPARATOR)}`,
group && `PORTAINER_GROUP=${group}`,
tagsIds.length && `PORTAINER_TAGS=${tagsIds.join(VAR_LIST_SEPARATOR)}`,
]);
}