diff --git a/src/renderer/components/+workloads-pods/__tests__/__snapshots__/pod-container-env.test.tsx.snap b/src/renderer/components/+workloads-pods/__tests__/__snapshots__/pod-container-env.test.tsx.snap
new file mode 100644
index 0000000000..1183ce4309
--- /dev/null
+++ b/src/renderer/components/+workloads-pods/__tests__/__snapshots__/pod-container-env.test.tsx.snap
@@ -0,0 +1,182 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[` renders both env and configMapRef envFrom 1`] = `
+
+
+
+
+ Environment
+
+
+
+
+ foobar
+
+ :
+ https://localhost:12345
+
+
+
+ configFoo
+
+ :
+ configBar
+
+
+
+
+
+`;
+
+exports[` renders env 1`] = `
+
+
+
+
+ Environment
+
+
+
+
+ foobar
+
+ :
+ https://localhost:12345
+
+
+
+
+
+`;
+
+exports[` renders env 2`] = `
+
+
+
+
+ Environment
+
+
+
+
+ foobar
+
+ :
+ https://localhost:12345
+
+
+
+
+
+`;
+
+exports[` renders envFrom when given a configMapRef 1`] = `
+
+
+
+
+ Environment
+
+
+
+
+ configFoo
+
+ :
+ configBar
+
+
+
+
+
+`;
+
+exports[` renders envFrom when given a secretRef 1`] = `
+
+
+
+
+ Environment
+
+
+
+
+ bar
+
+ :
+ secretKeyRef(my-secret.bar)
+
+
+
+ visibility
+
+
+
+ Show
+
+
+
+
+
+
+`;
diff --git a/src/renderer/components/+workloads-pods/__tests__/pod-container-env.test.tsx b/src/renderer/components/+workloads-pods/__tests__/pod-container-env.test.tsx
new file mode 100644
index 0000000000..bb85aee1ec
--- /dev/null
+++ b/src/renderer/components/+workloads-pods/__tests__/pod-container-env.test.tsx
@@ -0,0 +1,252 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+
+import React from "react";
+import type { ConfigMapStore } from "../../+config-maps/store";
+import configMapStoreInjectable from "../../+config-maps/store.injectable";
+import type { SecretStore } from "../../+config-secrets/store";
+import secretStoreInjectable from "../../+config-secrets/store.injectable";
+import type { Container } from "../../../../common/k8s-api/endpoints";
+import { Secret, ConfigMap, Pod, SecretType } from "../../../../common/k8s-api/endpoints";
+import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
+import type { DiRender } from "../../test-utils/renderFor";
+import { renderFor } from "../../test-utils/renderFor";
+import { ContainerEnvironment } from "../pod-container-env";
+
+describe("", () => {
+ let render: DiRender;
+ let secretStore: jest.Mocked>;
+ let configMapStore: jest.Mocked>;
+
+ beforeEach(() => {
+ const di = getDiForUnitTesting({ doGeneralOverrides: true });
+
+ secretStore = ({
+ load: jest.fn().mockImplementation(async () => {
+ return {} as Secret;
+ }),
+ getByName: jest.fn(),
+ });
+ configMapStore = ({
+ load: jest.fn().mockImplementation(async () => {
+ return {} as ConfigMap;
+ }),
+ getByName: jest.fn(),
+ });
+
+ di.override(secretStoreInjectable, () => secretStore as jest.Mocked);
+ di.override(configMapStoreInjectable, () => configMapStore as jest.Mocked);
+
+ render = renderFor(di);
+ });
+
+ it("renders env", () => {
+ const container: Container = {
+ image: "my-image",
+ name: "my-first-container",
+ env: [{
+ name: "foobar",
+ value: "https://localhost:12345",
+ }],
+ };
+ const pod = new Pod({
+ apiVersion: "v1",
+ kind: "Pod",
+ metadata: {
+ name: "my-pod",
+ namespace: "default",
+ resourceVersion: "1",
+ selfLink: "/api/v1/pods/default/my-pod",
+ uid: "1234",
+ },
+ spec: {
+ containers: [container],
+ },
+ });
+ const result = render();
+
+ expect(result.baseElement).toMatchSnapshot();
+ });
+
+ it("renders envFrom when given a configMapRef", () => {
+ configMapStore.getByName.mockImplementation((name, namespace) => {
+ expect(name).toBe("my-config-map");
+ expect(namespace).toBe("default");
+
+ return new ConfigMap({
+ apiVersion: "v1",
+ kind: "ConfigMap",
+ metadata: {
+ name: "my-config-map",
+ namespace: "default",
+ resourceVersion: "2",
+ selfLink: "/api/v1/configmaps/default/my-config-map",
+ uid: "456",
+ },
+ data: {
+ configFoo: "configBar",
+ },
+ });
+ });
+
+ const container: Container = {
+ image: "my-image",
+ name: "my-first-container",
+ envFrom: [{
+ configMapRef: {
+ name: "my-config-map",
+ },
+ }],
+ };
+ const pod = new Pod({
+ apiVersion: "v1",
+ kind: "Pod",
+ metadata: {
+ name: "my-pod",
+ namespace: "default",
+ resourceVersion: "1",
+ selfLink: "/api/v1/pods/default/my-pod",
+ uid: "1234",
+ },
+ spec: {
+ containers: [container],
+ },
+ });
+ const result = render();
+
+ expect(result.baseElement).toMatchSnapshot();
+ });
+
+ it("renders envFrom when given a secretRef", () => {
+ secretStore.getByName.mockImplementation((name, namespace) => {
+ expect(name).toBe("my-secret");
+ expect(namespace).toBe("default");
+
+ return new Secret({
+ apiVersion: "v1",
+ kind: "Secret",
+ metadata: {
+ name: "my-secret",
+ namespace: "default",
+ resourceVersion: "3",
+ selfLink: "/api/v1/secrets/default/my-secret",
+ uid: "237",
+ },
+ type: SecretType.BasicAuth,
+ data: {
+ bar: "bat",
+ },
+ });
+ });
+
+ const container: Container = {
+ image: "my-image",
+ name: "my-first-container",
+ envFrom: [{
+ secretRef: {
+ name: "my-secret",
+ },
+ }],
+ };
+ const pod = new Pod({
+ apiVersion: "v1",
+ kind: "Pod",
+ metadata: {
+ name: "my-pod",
+ namespace: "default",
+ resourceVersion: "1",
+ selfLink: "/api/v1/pods/default/my-pod",
+ uid: "1234",
+ },
+ spec: {
+ containers: [container],
+ },
+ });
+ const result = render();
+
+ expect(result.baseElement).toMatchSnapshot();
+ });
+
+ it("renders env", () => {
+ const container: Container = {
+ image: "my-image",
+ name: "my-first-container",
+ env: [{
+ name: "foobar",
+ value: "https://localhost:12345",
+ }],
+ };
+ const pod = new Pod({
+ apiVersion: "v1",
+ kind: "Pod",
+ metadata: {
+ name: "my-pod",
+ namespace: "default",
+ resourceVersion: "1",
+ selfLink: "/api/v1/pods/default/my-pod",
+ uid: "1234",
+ },
+ spec: {
+ containers: [container],
+ },
+ });
+ const result = render();
+
+ expect(result.baseElement).toMatchSnapshot();
+ });
+
+ it("renders both env and configMapRef envFrom", () => {
+ configMapStore.getByName.mockImplementation((name, namespace) => {
+ expect(name).toBe("my-config-map");
+ expect(namespace).toBe("default");
+
+ return new ConfigMap({
+ apiVersion: "v1",
+ kind: "ConfigMap",
+ metadata: {
+ name: "my-config-map",
+ namespace: "default",
+ resourceVersion: "2",
+ selfLink: "/api/v1/configmaps/default/my-config-map",
+ uid: "456",
+ },
+ data: {
+ configFoo: "configBar",
+ },
+ });
+ });
+
+ const container: Container = {
+ image: "my-image",
+ name: "my-first-container",
+ envFrom: [{
+ configMapRef: {
+ name: "my-config-map",
+ },
+ }],
+ env: [{
+ name: "foobar",
+ value: "https://localhost:12345",
+ }],
+ };
+ const pod = new Pod({
+ apiVersion: "v1",
+ kind: "Pod",
+ metadata: {
+ name: "my-pod",
+ namespace: "default",
+ resourceVersion: "1",
+ selfLink: "/api/v1/pods/default/my-pod",
+ uid: "1234",
+ },
+ spec: {
+ containers: [container],
+ },
+ });
+ const result = render();
+
+ expect(result.baseElement).toMatchSnapshot();
+ });
+});
diff --git a/src/renderer/components/+workloads-pods/pod-container-env.tsx b/src/renderer/components/+workloads-pods/pod-container-env.tsx
index 494c4464d4..88a7667e6b 100644
--- a/src/renderer/components/+workloads-pods/pod-container-env.tsx
+++ b/src/renderer/components/+workloads-pods/pod-container-env.tsx
@@ -83,16 +83,16 @@ const NonInjectedContainerEnvironment = observer((props: Dependencies & Containe
const { name, key } = configMapKeyRef;
const configMap = configMapStore.getByName(name, namespace);
- secretValue = configMap ?
- configMap.data[key] :
- `configMapKeyRef(${name}${key})`;
+ secretValue = configMap
+ ? configMap.data[key]
+ : `configMapKeyRef(${name}${key})`;
}
}
return (
{name}
- :
+ {` : `}
{secretValue}
);
@@ -126,7 +126,7 @@ const NonInjectedContainerEnvironment = observer((props: Dependencies & Containe
{prefix}
{name}
- :
+ {` : `}
{value}
));
@@ -144,14 +144,15 @@ const NonInjectedContainerEnvironment = observer((props: Dependencies & Containe
{prefix}
{key}
- :
+ {` : `}
+ secretStore={secretStore}
+ />
));
};