mirror of https://github.com/portainer/portainer
Revert "fix(kube): configmaps and secrets from envFrom in the app detail screen [EE-6282] (#10741)" (#10785)
This reverts commit ce4b6dc586
.
pull/10788/head
parent
d8480a0db6
commit
5761342069
|
@ -1,4 +1,4 @@
|
||||||
import { Pod } from 'kubernetes-types/core/v1';
|
import { EnvVar, Pod } from 'kubernetes-types/core/v1';
|
||||||
import { Asterisk, File, FileCode, Key, Lock } from 'lucide-react';
|
import { Asterisk, File, FileCode, Key, Lock } from 'lucide-react';
|
||||||
|
|
||||||
import { Icon } from '@@/Icon';
|
import { Icon } from '@@/Icon';
|
||||||
|
@ -44,7 +44,7 @@ export function ApplicationEnvVarsTable({ namespace, app }: Props) {
|
||||||
{envVar.isInitContainer && (
|
{envVar.isInitContainer && (
|
||||||
<span>
|
<span>
|
||||||
<Icon icon={Asterisk} className="!ml-1" />
|
<Icon icon={Asterisk} className="!ml-1" />
|
||||||
{envVar.fieldPath} (
|
{envVar.valueFrom?.fieldRef?.fieldPath} (
|
||||||
<a
|
<a
|
||||||
href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/"
|
href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
@ -56,13 +56,13 @@ export function ApplicationEnvVarsTable({ namespace, app }: Props) {
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td data-cy="k8sAppDetail-envVarName">{envVar.key || '-'}</td>
|
<td data-cy="k8sAppDetail-envVarName">{envVar.name}</td>
|
||||||
<td data-cy="k8sAppDetail-envVarValue">
|
<td data-cy="k8sAppDetail-envVarValue">
|
||||||
{envVar.value && <span>{envVar.value}</span>}
|
{envVar.value && <span>{envVar.value}</span>}
|
||||||
{envVar.fieldPath && (
|
{envVar.valueFrom?.fieldRef?.fieldPath && (
|
||||||
<span>
|
<span>
|
||||||
<Icon icon={Asterisk} className="!ml-1" />
|
<Icon icon={Asterisk} className="!ml-1" />
|
||||||
{envVar.fieldPath} (
|
{envVar.valueFrom.fieldRef.fieldPath} (
|
||||||
<a
|
<a
|
||||||
href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/"
|
href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
@ -73,36 +73,50 @@ export function ApplicationEnvVarsTable({ namespace, app }: Props) {
|
||||||
)
|
)
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{envVar.key ? (
|
{envVar.valueFrom?.secretKeyRef?.key && (
|
||||||
<span className="flex items-center">
|
<span className="flex items-center">
|
||||||
<Icon icon={Key} className="!mr-1" />
|
<Icon icon={Key} className="!mr-1" />
|
||||||
{envVar.key}
|
{envVar.valueFrom.secretKeyRef.key}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
|
||||||
'-'
|
|
||||||
)}
|
)}
|
||||||
|
{envVar.valueFrom?.configMapKeyRef?.key && (
|
||||||
|
<span className="flex items-center">
|
||||||
|
<Icon icon={Key} className="!mr-1" />
|
||||||
|
{envVar.valueFrom.configMapKeyRef.key}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{!envVar.value && !envVar.valueFrom && <span>-</span>}
|
||||||
</td>
|
</td>
|
||||||
<td data-cy="k8sAppDetail-configName">
|
<td data-cy="k8sAppDetail-configName">
|
||||||
{!envVar.resourseName && <span>-</span>}
|
{!envVar.valueFrom?.configMapKeyRef?.name &&
|
||||||
{envVar.resourseName && (
|
!envVar.valueFrom?.secretKeyRef?.name && <span>-</span>}
|
||||||
|
{envVar.valueFrom?.configMapKeyRef && (
|
||||||
<span>
|
<span>
|
||||||
<Link
|
<Link
|
||||||
to={
|
to="kubernetes.configmaps.configmap"
|
||||||
envVar.type === 'configMap'
|
|
||||||
? 'kubernetes.configmaps.configmap'
|
|
||||||
: 'kubernetes.secrets.secret'
|
|
||||||
}
|
|
||||||
params={{
|
params={{
|
||||||
name: envVar.resourseName,
|
name: envVar.valueFrom.configMapKeyRef.name,
|
||||||
namespace,
|
namespace,
|
||||||
}}
|
}}
|
||||||
className="flex items-center"
|
className="flex items-center"
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon icon={FileCode} className="!mr-1" />
|
||||||
icon={envVar.type === 'configMap' ? FileCode : Lock}
|
{envVar.valueFrom.configMapKeyRef.name}
|
||||||
className="!mr-1"
|
</Link>
|
||||||
/>
|
</span>
|
||||||
{envVar.resourseName}
|
)}
|
||||||
|
{envVar.valueFrom?.secretKeyRef && (
|
||||||
|
<span>
|
||||||
|
<Link
|
||||||
|
to="kubernetes.secrets.secret"
|
||||||
|
params={{
|
||||||
|
name: envVar.valueFrom.secretKeyRef.name,
|
||||||
|
namespace,
|
||||||
|
}}
|
||||||
|
className="flex items-center"
|
||||||
|
>
|
||||||
|
<Icon icon={Lock} className="!mr-1" />
|
||||||
|
{envVar.valueFrom.secretKeyRef.name}
|
||||||
</Link>
|
</Link>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
@ -116,14 +130,9 @@ export function ApplicationEnvVarsTable({ namespace, app }: Props) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContainerEnvVar {
|
interface ContainerEnvVar extends EnvVar {
|
||||||
key?: string;
|
|
||||||
value?: string;
|
|
||||||
fieldPath?: string;
|
|
||||||
containerName: string;
|
containerName: string;
|
||||||
isInitContainer: boolean;
|
isInitContainer: boolean;
|
||||||
type: 'configMap' | 'secret';
|
|
||||||
resourseName: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getApplicationEnvironmentVariables(
|
function getApplicationEnvironmentVariables(
|
||||||
|
@ -141,60 +150,23 @@ function getApplicationEnvironmentVariables(
|
||||||
|
|
||||||
// get all the environment variables for each container
|
// get all the environment variables for each container
|
||||||
const appContainersEnvVars =
|
const appContainersEnvVars =
|
||||||
appContainers?.flatMap((container) => {
|
appContainers?.flatMap(
|
||||||
const containerEnvVars: ContainerEnvVar[] =
|
(container) =>
|
||||||
container?.env?.map((envVar) => ({
|
container?.env?.map((envVar) => ({
|
||||||
key: envVar?.name,
|
...envVar,
|
||||||
fieldPath: envVar?.valueFrom?.fieldRef?.fieldPath,
|
|
||||||
containerName: container.name,
|
containerName: container.name,
|
||||||
isInitContainer: false,
|
isInitContainer: false,
|
||||||
type: envVar?.valueFrom?.configMapKeyRef ? 'configMap' : 'secret',
|
})) || []
|
||||||
resourseName:
|
) || [];
|
||||||
envVar?.valueFrom?.configMapKeyRef?.name ||
|
|
||||||
envVar?.valueFrom?.secretKeyRef?.name ||
|
|
||||||
'',
|
|
||||||
})) || [];
|
|
||||||
|
|
||||||
const containerEnvFroms: ContainerEnvVar[] =
|
|
||||||
container?.envFrom?.map((envFrom) => ({
|
|
||||||
name: '',
|
|
||||||
resourseName:
|
|
||||||
envFrom?.configMapRef?.name || envFrom?.secretRef?.name || '',
|
|
||||||
containerName: container.name,
|
|
||||||
isInitContainer: false,
|
|
||||||
type: envFrom?.configMapRef ? 'configMap' : 'secret',
|
|
||||||
})) || [];
|
|
||||||
|
|
||||||
return [...containerEnvVars, ...containerEnvFroms];
|
|
||||||
}) || [];
|
|
||||||
|
|
||||||
const appInitContainersEnvVars =
|
const appInitContainersEnvVars =
|
||||||
appInitContainers?.flatMap((container) => {
|
appInitContainers?.flatMap(
|
||||||
const containerEnvVars: ContainerEnvVar[] =
|
(container) =>
|
||||||
container?.env?.map((envVar) => ({
|
container?.env?.map((envVar) => ({
|
||||||
key: envVar?.name,
|
...envVar,
|
||||||
fieldPath: envVar?.valueFrom?.fieldRef?.fieldPath,
|
|
||||||
containerName: container.name,
|
containerName: container.name,
|
||||||
isInitContainer: false,
|
isInitContainer: true,
|
||||||
type: envVar?.valueFrom?.configMapKeyRef ? 'configMap' : 'secret',
|
})) || []
|
||||||
resourseName:
|
) || [];
|
||||||
envVar?.valueFrom?.configMapKeyRef?.name ||
|
|
||||||
envVar?.valueFrom?.secretKeyRef?.name ||
|
|
||||||
'',
|
|
||||||
})) || [];
|
|
||||||
|
|
||||||
const containerEnvFroms: ContainerEnvVar[] =
|
|
||||||
container?.envFrom?.map((envFrom) => ({
|
|
||||||
name: '',
|
|
||||||
resourseName:
|
|
||||||
envFrom?.configMapRef?.name || envFrom?.secretRef?.name || '',
|
|
||||||
containerName: container.name,
|
|
||||||
isInitContainer: false,
|
|
||||||
type: envFrom?.configMapRef ? 'configMap' : 'secret',
|
|
||||||
})) || [];
|
|
||||||
|
|
||||||
return [...containerEnvVars, ...containerEnvFroms];
|
|
||||||
}) || [];
|
|
||||||
|
|
||||||
return [...appContainersEnvVars, ...appInitContainersEnvVars];
|
return [...appContainersEnvVars, ...appInitContainersEnvVars];
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,12 +250,7 @@ async function getApplicationsByKind<T extends ApplicationList>(
|
||||||
const { data } = await axios.get<T>(
|
const { data } = await axios.get<T>(
|
||||||
buildUrl(environmentId, namespace, `${appKind}s`)
|
buildUrl(environmentId, namespace, `${appKind}s`)
|
||||||
);
|
);
|
||||||
const items = (data.items || []).map((app) => ({
|
return data.items as T['items'];
|
||||||
...app,
|
|
||||||
kind: appKind,
|
|
||||||
apiVersion: data.apiVersion,
|
|
||||||
}));
|
|
||||||
return items as T['items'];
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw parseAxiosError(e as Error, `Unable to retrieve ${appKind}s`);
|
throw parseAxiosError(e as Error, `Unable to retrieve ${appKind}s`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,7 @@ export async function getNamespacePods(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const items = (data.items || []).map(
|
return data.items;
|
||||||
(pod) =>
|
|
||||||
<Pod>{
|
|
||||||
...pod,
|
|
||||||
kind: 'Pod',
|
|
||||||
apiVersion: data.apiVersion,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return items;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw parseAxiosError(e as Error, 'Unable to retrieve pods');
|
throw parseAxiosError(e as Error, 'Unable to retrieve pods');
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,12 @@ export function getIsConfigMapInUse(
|
||||||
? app?.spec
|
? app?.spec
|
||||||
: app?.spec?.template?.spec;
|
: app?.spec?.template?.spec;
|
||||||
|
|
||||||
const hasEnvVarReference = appSpec?.containers.some((container) => {
|
const hasEnvVarReference = appSpec?.containers.some((container) =>
|
||||||
const valueFromEnv = container.env?.some(
|
container.env?.some(
|
||||||
(envVar) =>
|
(envVar) =>
|
||||||
envVar.valueFrom?.configMapKeyRef?.name === configMap.metadata?.name
|
envVar.valueFrom?.configMapKeyRef?.name === configMap.metadata?.name
|
||||||
|
)
|
||||||
);
|
);
|
||||||
const envFromEnv = container.envFrom?.some(
|
|
||||||
(envVar) => envVar.configMapRef?.name === configMap.metadata?.name
|
|
||||||
);
|
|
||||||
return valueFromEnv || envFromEnv;
|
|
||||||
});
|
|
||||||
const hasVolumeReference = appSpec?.volumes?.some(
|
const hasVolumeReference = appSpec?.volumes?.some(
|
||||||
(volume) => volume.configMap?.name === configMap.metadata?.name
|
(volume) => volume.configMap?.name === configMap.metadata?.name
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,16 +11,12 @@ export function getIsSecretInUse(secret: Secret, applications: Application[]) {
|
||||||
? app?.spec
|
? app?.spec
|
||||||
: app?.spec?.template?.spec;
|
: app?.spec?.template?.spec;
|
||||||
|
|
||||||
const hasEnvVarReference = appSpec?.containers.some((container) => {
|
const hasEnvVarReference = appSpec?.containers.some((container) =>
|
||||||
const valueFromEnv = container.env?.some(
|
container.env?.some(
|
||||||
(envVar) =>
|
(envVar) =>
|
||||||
envVar.valueFrom?.secretKeyRef?.name === secret.metadata?.name
|
envVar.valueFrom?.secretKeyRef?.name === secret.metadata?.name
|
||||||
|
)
|
||||||
);
|
);
|
||||||
const envFromEnv = container.envFrom?.some(
|
|
||||||
(envVar) => envVar.secretRef?.name === secret.metadata?.name
|
|
||||||
);
|
|
||||||
return valueFromEnv || envFromEnv;
|
|
||||||
});
|
|
||||||
const hasVolumeReference = appSpec?.volumes?.some(
|
const hasVolumeReference = appSpec?.volumes?.some(
|
||||||
(volume) => volume.secret?.secretName === secret.metadata?.name
|
(volume) => volume.secret?.secretName === secret.metadata?.name
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue