mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Generic logs view with Pod selector (#1984)
* Adding LogTabStore Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding Pod selector in logs tab Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Refresh containers on pod change Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding <LogResourceSelector /> tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding LogTabStore tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Clearn getPodsByOwnerId method Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Extracting dummy pods into mock file Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Eliminating containers and initContainers from store Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Refreshing tab pods if pod amount is changed in store Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * A bit of cleaning up, fixing tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fix lint newline errors Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Return getPodsByOwner() method Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Rename log tab when pod changes Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
1 parent
724c6c3265
commit
a157eb03e6
25 files changed
+1359
-135
No files matched your search
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
import { render } from "@testing-library/react";
|
||||
import selectEvent from "react-select-event";
|
||||
|
||||
import { Pod } from "../../../api/endpoints";
|
||||
import { LogResourceSelector } from "../log-resource-selector";
|
||||
import { LogTabData } from "../log-tab.store";
|
||||
import { dockerPod, deploymentPod1 } from "./pod.mock";
|
||||
|
||||
const getComponent = (tabData: LogTabData) => {
|
||||
return (
|
||||
<LogResourceSelector
|
||||
tabId="tabId"
|
||||
tabData={tabData}
|
||||
save={jest.fn()}
|
||||
reload={jest.fn()}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const getOnePodTabData = (): LogTabData => {
|
||||
const selectedPod = new Pod(dockerPod);
|
||||
|
||||
return {
|
||||
pods: [] as Pod[],
|
||||
selectedPod,
|
||||
selectedContainer: selectedPod.getContainers()[0],
|
||||
};
|
||||
};
|
||||
|
||||
const getFewPodsTabData = (): LogTabData => {
|
||||
const selectedPod = new Pod(deploymentPod1);
|
||||
const anotherPod = new Pod(dockerPod);
|
||||
|
||||
return {
|
||||
pods: [anotherPod],
|
||||
selectedPod,
|
||||
selectedContainer: selectedPod.getContainers()[0],
|
||||
};
|
||||
};
|
||||
|
||||
describe("<LogResourceSelector />", () => {
|
||||
it("renders w/o errors", () => {
|
||||
const tabData = getOnePodTabData();
|
||||
const { container } = render(getComponent(tabData));
|
||||
|
||||
expect(container).toBeInstanceOf(HTMLElement);
|
||||
});
|
||||
|
||||
it("renders proper namespace", () => {
|
||||
const tabData = getOnePodTabData();
|
||||
const { getByTestId } = render(getComponent(tabData));
|
||||
const ns = getByTestId("namespace-badge");
|
||||
|
||||
expect(ns).toHaveTextContent("default");
|
||||
});
|
||||
|
||||
it("renders proper selected items within dropdowns", () => {
|
||||
const tabData = getOnePodTabData();
|
||||
const { getByText } = render(getComponent(tabData));
|
||||
|
||||
expect(getByText("dockerExporter")).toBeInTheDocument();
|
||||
expect(getByText("docker-exporter")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders sibling pods in dropdown", () => {
|
||||
const tabData = getFewPodsTabData();
|
||||
const { container, getByText } = render(getComponent(tabData));
|
||||
const podSelector: HTMLElement = container.querySelector(".pod-selector");
|
||||
|
||||
selectEvent.openMenu(podSelector);
|
||||
|
||||
expect(getByText("dockerExporter")).toBeInTheDocument();
|
||||
expect(getByText("deploymentPod1")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders sibling containers in dropdown", () => {
|
||||
const tabData = getFewPodsTabData();
|
||||
const { getByText, container } = render(getComponent(tabData));
|
||||
const containerSelector: HTMLElement = container.querySelector(".container-selector");
|
||||
|
||||
selectEvent.openMenu(containerSelector);
|
||||
|
||||
expect(getByText("node-exporter-1")).toBeInTheDocument();
|
||||
expect(getByText("init-node-exporter")).toBeInTheDocument();
|
||||
expect(getByText("init-node-exporter-1")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders pod owner as dropdown title", () => {
|
||||
const tabData = getFewPodsTabData();
|
||||
const { getByText, container } = render(getComponent(tabData));
|
||||
const podSelector: HTMLElement = container.querySelector(".pod-selector");
|
||||
|
||||
selectEvent.openMenu(podSelector);
|
||||
|
||||
expect(getByText("super-deployment")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
import { podsStore } from "../../+workloads-pods/pods.store";
|
||||
import { Pod } from "../../../api/endpoints";
|
||||
import { dockStore } from "../dock.store";
|
||||
import { logTabStore } from "../log-tab.store";
|
||||
import { deploymentPod1, deploymentPod2, deploymentPod3, dockerPod } from "./pod.mock";
|
||||
|
||||
|
||||
podsStore.items.push(new Pod(dockerPod));
|
||||
podsStore.items.push(new Pod(deploymentPod1));
|
||||
podsStore.items.push(new Pod(deploymentPod2));
|
||||
|
||||
describe("log tab store", () => {
|
||||
afterEach(() => {
|
||||
logTabStore.reset();
|
||||
dockStore.reset();
|
||||
});
|
||||
|
||||
it("creates log tab without sibling pods", () => {
|
||||
const selectedPod = new Pod(dockerPod);
|
||||
const selectedContainer = selectedPod.getAllContainers()[0];
|
||||
|
||||
logTabStore.createPodTab({
|
||||
selectedPod,
|
||||
selectedContainer
|
||||
});
|
||||
|
||||
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
||||
pods: [selectedPod],
|
||||
selectedPod,
|
||||
selectedContainer,
|
||||
showTimestamps: false,
|
||||
previous: false
|
||||
});
|
||||
});
|
||||
|
||||
it("creates log tab with sibling pods", () => {
|
||||
const selectedPod = new Pod(deploymentPod1);
|
||||
const siblingPod = new Pod(deploymentPod2);
|
||||
const selectedContainer = selectedPod.getInitContainers()[0];
|
||||
|
||||
logTabStore.createPodTab({
|
||||
selectedPod,
|
||||
selectedContainer
|
||||
});
|
||||
|
||||
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
||||
pods: [selectedPod, siblingPod],
|
||||
selectedPod,
|
||||
selectedContainer,
|
||||
showTimestamps: false,
|
||||
previous: false
|
||||
});
|
||||
});
|
||||
|
||||
it("removes item from pods list if pod deleted from store", () => {
|
||||
const selectedPod = new Pod(deploymentPod1);
|
||||
const selectedContainer = selectedPod.getInitContainers()[0];
|
||||
|
||||
logTabStore.createPodTab({
|
||||
selectedPod,
|
||||
selectedContainer
|
||||
});
|
||||
|
||||
podsStore.items.pop();
|
||||
|
||||
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
||||
pods: [selectedPod],
|
||||
selectedPod,
|
||||
selectedContainer,
|
||||
showTimestamps: false,
|
||||
previous: false
|
||||
});
|
||||
});
|
||||
|
||||
it("adds item into pods list if new sibling pod added to store", () => {
|
||||
const selectedPod = new Pod(deploymentPod1);
|
||||
const selectedContainer = selectedPod.getInitContainers()[0];
|
||||
|
||||
logTabStore.createPodTab({
|
||||
selectedPod,
|
||||
selectedContainer
|
||||
});
|
||||
|
||||
podsStore.items.push(new Pod(deploymentPod3));
|
||||
|
||||
expect(logTabStore.getData(dockStore.selectedTabId)).toEqual({
|
||||
pods: [selectedPod, deploymentPod3],
|
||||
selectedPod,
|
||||
selectedContainer,
|
||||
showTimestamps: false,
|
||||
previous: false
|
||||
});
|
||||
});
|
||||
|
||||
it("closes tab if no pods left in store", () => {
|
||||
const selectedPod = new Pod(deploymentPod1);
|
||||
const selectedContainer = selectedPod.getInitContainers()[0];
|
||||
|
||||
logTabStore.createPodTab({
|
||||
selectedPod,
|
||||
selectedContainer
|
||||
});
|
||||
|
||||
podsStore.items.clear();
|
||||
|
||||
expect(logTabStore.getData(dockStore.selectedTabId)).toBeUndefined();
|
||||
expect(dockStore.getTabById(dockStore.selectedTabId)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,203 @@
|
||||
export const dockerPod = {
|
||||
apiVersion: "v1",
|
||||
kind: "dummy",
|
||||
metadata: {
|
||||
uid: "dockerExporter",
|
||||
name: "dockerExporter",
|
||||
creationTimestamp: "dummy",
|
||||
resourceVersion: "dummy",
|
||||
namespace: "default"
|
||||
},
|
||||
spec: {
|
||||
initContainers: [] as any,
|
||||
containers: [
|
||||
{
|
||||
name: "docker-exporter",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
}
|
||||
],
|
||||
serviceAccountName: "dummy",
|
||||
serviceAccount: "dummy",
|
||||
},
|
||||
status: {
|
||||
phase: "Running",
|
||||
conditions: [{
|
||||
type: "Running",
|
||||
status: "Running",
|
||||
lastProbeTime: 1,
|
||||
lastTransitionTime: "Some time",
|
||||
}],
|
||||
hostIP: "dummy",
|
||||
podIP: "dummy",
|
||||
startTime: "dummy",
|
||||
}
|
||||
};
|
||||
|
||||
export const deploymentPod1 = {
|
||||
apiVersion: "v1",
|
||||
kind: "dummy",
|
||||
metadata: {
|
||||
uid: "deploymentPod1",
|
||||
name: "deploymentPod1",
|
||||
creationTimestamp: "dummy",
|
||||
resourceVersion: "dummy",
|
||||
namespace: "default",
|
||||
ownerReferences: [{
|
||||
apiVersion: "v1",
|
||||
kind: "Deployment",
|
||||
name: "super-deployment",
|
||||
uid: "uuid",
|
||||
controller: true,
|
||||
blockOwnerDeletion: true,
|
||||
}]
|
||||
},
|
||||
spec: {
|
||||
initContainers: [
|
||||
{
|
||||
name: "init-node-exporter",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
},
|
||||
{
|
||||
name: "init-node-exporter-1",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
}
|
||||
],
|
||||
containers: [
|
||||
{
|
||||
name: "node-exporter",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
},
|
||||
{
|
||||
name: "node-exporter-1",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
}
|
||||
],
|
||||
serviceAccountName: "dummy",
|
||||
serviceAccount: "dummy",
|
||||
},
|
||||
status: {
|
||||
phase: "Running",
|
||||
conditions: [{
|
||||
type: "Running",
|
||||
status: "Running",
|
||||
lastProbeTime: 1,
|
||||
lastTransitionTime: "Some time",
|
||||
}],
|
||||
hostIP: "dummy",
|
||||
podIP: "dummy",
|
||||
startTime: "dummy",
|
||||
}
|
||||
};
|
||||
|
||||
export const deploymentPod2 = {
|
||||
apiVersion: "v1",
|
||||
kind: "dummy",
|
||||
metadata: {
|
||||
uid: "deploymentPod2",
|
||||
name: "deploymentPod2",
|
||||
creationTimestamp: "dummy",
|
||||
resourceVersion: "dummy",
|
||||
namespace: "default",
|
||||
ownerReferences: [{
|
||||
apiVersion: "v1",
|
||||
kind: "Deployment",
|
||||
name: "super-deployment",
|
||||
uid: "uuid",
|
||||
controller: true,
|
||||
blockOwnerDeletion: true,
|
||||
}]
|
||||
},
|
||||
spec: {
|
||||
initContainers: [
|
||||
{
|
||||
name: "init-node-exporter",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
},
|
||||
{
|
||||
name: "init-node-exporter-1",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
}
|
||||
],
|
||||
containers: [
|
||||
{
|
||||
name: "node-exporter",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
},
|
||||
{
|
||||
name: "node-exporter-1",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
}
|
||||
],
|
||||
serviceAccountName: "dummy",
|
||||
serviceAccount: "dummy",
|
||||
},
|
||||
status: {
|
||||
phase: "Running",
|
||||
conditions: [{
|
||||
type: "Running",
|
||||
status: "Running",
|
||||
lastProbeTime: 1,
|
||||
lastTransitionTime: "Some time",
|
||||
}],
|
||||
hostIP: "dummy",
|
||||
podIP: "dummy",
|
||||
startTime: "dummy",
|
||||
}
|
||||
};
|
||||
|
||||
export const deploymentPod3 = {
|
||||
apiVersion: "v1",
|
||||
kind: "dummy",
|
||||
metadata: {
|
||||
uid: "deploymentPod3",
|
||||
name: "deploymentPod3",
|
||||
creationTimestamp: "dummy",
|
||||
resourceVersion: "dummy",
|
||||
namespace: "default",
|
||||
ownerReferences: [{
|
||||
apiVersion: "v1",
|
||||
kind: "Deployment",
|
||||
name: "super-deployment",
|
||||
uid: "uuid",
|
||||
controller: true,
|
||||
blockOwnerDeletion: true,
|
||||
}]
|
||||
},
|
||||
spec: {
|
||||
containers: [
|
||||
{
|
||||
name: "node-exporter",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
},
|
||||
{
|
||||
name: "node-exporter-1",
|
||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||
imagePullPolicy: "pull"
|
||||
}
|
||||
],
|
||||
serviceAccountName: "dummy",
|
||||
serviceAccount: "dummy",
|
||||
},
|
||||
status: {
|
||||
phase: "Running",
|
||||
conditions: [{
|
||||
type: "Running",
|
||||
status: "Running",
|
||||
lastProbeTime: 1,
|
||||
lastTransitionTime: "Some time",
|
||||
}],
|
||||
hostIP: "dummy",
|
||||
podIP: "dummy",
|
||||
startTime: "dummy",
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user