Move Cluster.apiUrl to seperate injectable (#7354)

* Refactor out Cluster.apiUrl to direct reading

- Should help prevent using stale data

- Removes some uses of synchronous FS operations

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Rename helper function to better communicate intent

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Improve prometheus handler tests to override less things

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-31 15:28:14 -04:00
1 parent 18d660ea77
commit fe2fd4c1fd
53 files changed
+472 -640

No files matched your search

@@ -53,8 +53,6 @@ describe("<HpaDetails/>", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
render = renderFor(di);
@@ -31,8 +31,6 @@ describe("SecretDetails tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
const secret = new Secret({
@@ -62,8 +62,6 @@ describe("<NamespaceSelectFilter />", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
namespaceStore = di.inject(namespaceStoreInjectable);
@@ -115,8 +115,6 @@ describe("NamespaceStore", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
namespaceStore = di.inject(namespaceStoreInjectable);
@@ -40,8 +40,6 @@ describe("ClusterRoleBindingDialog tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
render = renderFor(di);
@@ -36,8 +36,6 @@ describe("RoleBindingDialog tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
render = renderFor(di);
@@ -131,8 +131,6 @@ describe("CronJob Store tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
cronJobStore = di.inject(cronJobStoreInjectable);
@@ -148,8 +148,6 @@ describe("DaemonSet Store tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
const podStore = di.inject(podStoreInjectable);
@@ -220,8 +220,6 @@ describe("Deployment Store tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
const podStore = di.inject(podStoreInjectable);
@@ -185,8 +185,6 @@ describe("Job Store tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
jobStore = di.inject(jobStoreInjectable);
@@ -131,8 +131,6 @@ describe("Pod Store tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
podStore = di.inject(podStoreInjectable);
@@ -148,8 +148,6 @@ describe("ReplicaSet Store tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
const podStore = di.inject(podStoreInjectable);
@@ -148,8 +148,6 @@ describe("StatefulSet Store tests", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
statefulSetStore = di.inject(statefulSetStoreInjectable);
@@ -55,8 +55,6 @@ describe("ClusterLocalTerminalSettings", () => {
terminalCWD: "/foobar",
defaultNamespace: "kube-system",
},
}, {
clusterServerUrl: "https://localhost:12345",
});
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
@@ -76,8 +74,6 @@ describe("ClusterLocalTerminalSettings", () => {
preferences: {
terminalCWD: "/foobar",
},
}, {
clusterServerUrl: "https://localhost:12345",
});
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
@@ -98,8 +94,6 @@ describe("ClusterLocalTerminalSettings", () => {
preferences: {
terminalCWD: "/foobar",
},
}, {
clusterServerUrl: "https://localhost:12345",
});
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
@@ -129,8 +123,6 @@ describe("ClusterLocalTerminalSettings", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some/path",
}, {
clusterServerUrl: "https://localhost:12345",
});
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
@@ -161,8 +153,6 @@ describe("ClusterLocalTerminalSettings", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some/path",
}, {
clusterServerUrl: "https://localhost:12345",
});
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
@@ -17,32 +17,6 @@ import { clusterIconSettingsComponentInjectionToken, clusterIconSettingsMenuInje
import { runInAction } from "mobx";
import { getInjectable, type DiContainer } from "@ogre-tools/injectable";
const cluster = new Cluster({
contextName: "some-context",
id: "some-id",
kubeConfigPath: "/some/path/to/kubeconfig",
preferences: {
clusterName: "some-cluster-name",
},
}, {
clusterServerUrl: "https://localhost:9999",
});
const clusterEntity = new KubernetesCluster({
metadata: {
labels: {},
name: "some-kubernetes-cluster",
uid: "some-entity-id",
},
spec: {
kubeconfigContext: "some-context",
kubeconfigPath: "/some/path/to/kubeconfig",
},
status: {
phase: "connecting",
},
});
const newMenuItem = getInjectable({
id: "cluster-icon-settings-menu-test-item",
@@ -67,7 +41,7 @@ function CustomSettingsComponent(props: ClusterIconSettingComponentProps) {
</span>
</div>
);
}
}
const newSettingsReactComponent = getInjectable({
id: "cluster-icon-settings-react-component",
@@ -86,8 +60,31 @@ describe("Icon settings", () => {
beforeEach(() => {
di = getDiForUnitTesting();
const render = renderFor(di);
const cluster = new Cluster({
contextName: "some-context",
id: "some-id",
kubeConfigPath: "/some/path/to/kubeconfig",
preferences: {
clusterName: "some-cluster-name",
},
});
const clusterEntity = new KubernetesCluster({
metadata: {
labels: {},
name: "some-kubernetes-cluster",
uid: "some-entity-id",
},
spec: {
kubeconfigContext: "some-context",
kubeconfigPath: "/some/path/to/kubeconfig",
},
status: {
phase: "connecting",
},
});
rendered = render(
<ClusterIconSetting cluster={cluster} entity={clusterEntity} />,
@@ -38,8 +38,6 @@ describe("kube-object-list-layout", () => {
contextName: "some-context-name",
id: "some-cluster-id",
kubeConfigPath: "/some-path-to-a-kubeconfig",
}, {
clusterServerUrl: "https://localhost:8080",
}));
render = renderFor(di);
@@ -528,8 +528,6 @@ export const getApplicationBuilder = () => {
id: "some-cluster-id",
contextName: "some-context-name",
kubeConfigPath: "/some-path-to-kube-config",
}, {
clusterServerUrl: "https://localhost:12345",
});
windowDi.override(activeKubernetesClusterInjectable, () =>
@@ -48,16 +48,11 @@ describe("<ClusterFrame />", () => {
testUsingFakeTime("2000-01-01 12:00:00am");
cluster = new Cluster(
{
contextName: "my-cluster",
id: "123456",
kubeConfigPath: "/irrelavent",
},
{
clusterServerUrl: "https://localhost",
},
);
cluster = new Cluster({
contextName: "my-cluster",
id: "123456",
kubeConfigPath: "/irrelavent",
});
di.override(hostedClusterInjectable, () => cluster);
di.override(hostedClusterIdInjectable, () => cluster.id);