Skip to content

Commit

Permalink
feat: added setting for manually specifying namespaces for clusters
Browse files Browse the repository at this point in the history
resolves #8
  • Loading branch information
Jeroen Nijhuis committed Mar 23, 2024
1 parent 525a07e commit a4eb8fb
Show file tree
Hide file tree
Showing 19 changed files with 442 additions and 78 deletions.
164 changes: 113 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"monaco-editor": "^0.45.0",
"monaco-languageclient": "^7.3.0",
"pluralize": "^8.0.0",
"radix-vue": "^1.2.7",
"radix-vue": "^1.5.3",
"tailwind-merge": "^2.1.0",
"tailwindcss-animate": "^1.0.7",
"vee-validate": "^4.12.5",
Expand Down
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CommandPaletteProvider from "./providers/CommandPaletteProvider";
import TabProvider from "./providers/TabProvider";
import DialogProvider from "./providers/DialogProvider";
import DialogHandler from "./components/DialogHandler.vue";
import Settings from "./views/Settings.vue";
</script>

<template>
Expand Down
1 change: 1 addition & 0 deletions src/assets/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 42 additions & 8 deletions src/components/ContextSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
} from "@/providers/KubeContextProvider";
import { KubeContextStateKey } from "@/providers/KubeContextProvider";
import { Kubernetes } from "@/services/Kubernetes";
import { SettingsContextStateKey } from "@/providers/SettingsContextProvider";
const showSingleCommand = injectStrict(ShowSingleCommandKey);
const registerCommand = injectStrict(RegisterCommandStateKey);
const { context, namespace } = injectStrict(KubeContextStateKey);
const setContext = injectStrict(KubeContextSetContextKey);
const setNamespace = injectStrict(KubeContextSetNamespaceKey);
const { settings } = injectStrict(SettingsContextStateKey);
onMounted(() => {
registerCommand({
Expand All @@ -32,7 +34,23 @@ onMounted(() => {
name: context,
description: "Switch to " + context,
commands: async (): Promise<Command[]> => {
const namespaces = await Kubernetes.getNamespaces(context);
const clusterSettings = settings.value.contextSettings.find(
(c) => c.context === context
);
let namespaces = [];
if (
clusterSettings &&
clusterSettings.namespaces &&
clusterSettings.namespaces.length > 0
) {
namespaces = clusterSettings.namespaces;
} else {
namespaces = await (
await Kubernetes.getNamespaces(context)
).map((ns) => ns.metadata?.name || "");
}
return [
{
Expand All @@ -46,12 +64,12 @@ onMounted(() => {
} as Command,
].concat(
namespaces.map((namespace) => ({
id: namespace.metadata?.name || "",
name: namespace.metadata?.name || "",
id: namespace || "",
name: namespace || "",
description: "Switch to " + namespace,
execute: () => {
setContext(context);
setNamespace(namespace.metadata?.name || "");
setNamespace(namespace || "");
},
}))
);
Expand All @@ -66,7 +84,23 @@ onMounted(() => {
id: "switch-namespace",
keywords: ["ns", "namespace"],
commands: async (): Promise<Command[]> => {
const namespaces = await Kubernetes.getNamespaces(context.value);
const clusterSettings = settings.value.contextSettings.find(
(c) => c.context === context.value
);
let namespaces = [];
if (
clusterSettings &&
clusterSettings.namespaces &&
clusterSettings.namespaces.length > 0
) {
namespaces = clusterSettings.namespaces;
} else {
namespaces = await (
await Kubernetes.getNamespaces(context.value)
).map((ns) => ns.metadata?.name || "");
}
return [
{
Expand All @@ -79,11 +113,11 @@ onMounted(() => {
} as Command,
].concat(
namespaces.map((namespace) => ({
id: namespace.metadata?.name || "",
name: namespace.metadata?.name || "",
id: namespace || "",
name: namespace || "",
description: "Switch to " + namespace,
execute: () => {
setNamespace(namespace.metadata?.name || "");
setNamespace(namespace || "");
},
}))
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/RouterViewport.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { KubeContextStateKey } from "@/providers/KubeContextProvider";
import { injectStrict } from '@/lib/utils';
import { injectStrict } from "@/lib/utils";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import TabOrchestrator from "@/components/TabOrchestrator.vue";
import { useRoute } from "vue-router";
import NoContext from "@/views/NoContext.vue";
const { context } = injectStrict(KubeContextStateKey);
const route = useRoute();
</script>
<template>
<div class="flex flex-col max-h-screen relative router-viewport">
Expand Down
1 change: 1 addition & 0 deletions src/components/settings/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import NavigationItem from "@/components/settings/NavigationItem.vue";
<template>
<nav class="flex flex-col space-y-1">
<NavigationItem :to="{ name: 'SettingsGeneral' }" title="General" />
<NavigationItem :to="{ name: 'SettingsClusters' }" title="Clusters" />
</nav>
</template>
Loading

0 comments on commit a4eb8fb

Please sign in to comment.