kubepile 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -13
- package/dist/package.json +1 -1
- package/dist/src/shell.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,6 +36,15 @@ Kubepile will never set a `current-context`, out of the design belief that
|
|
|
36
36
|
npm install -g kubepile
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
Kubepile also includes a small shell helper that you need to install once:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
kubepile install
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Once you've installed the shell helper, either start a new shell or re-source
|
|
46
|
+
your `.zshrc`/`.bashrc`/`.profile`/etc. Kubepile supports Zsh, Bash, and Fish.
|
|
47
|
+
|
|
39
48
|
## Compile
|
|
40
49
|
|
|
41
50
|
```sh
|
|
@@ -65,28 +74,35 @@ Running `kubepile` with no command prints help.
|
|
|
65
74
|
|
|
66
75
|
## Source
|
|
67
76
|
|
|
68
|
-
`kubepile source <context>` switches your current shell to
|
|
69
|
-
creating a temporary kubeconfig
|
|
70
|
-
`KUBECONFIG` to point at it.
|
|
71
|
-
name.
|
|
77
|
+
`kubepile source <context>` switches your current shell to use a specific
|
|
78
|
+
Kubernetes context by default by creating a temporary kubeconfig with that
|
|
79
|
+
context set as the current-context, and exporting `KUBECONFIG` to point at it.
|
|
80
|
+
It also prefixes your shell prompt with the context name.
|
|
72
81
|
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
```sh
|
|
83
|
+
kubepile source prod
|
|
84
|
+
# Your shell prompt is now:
|
|
85
|
+
# (prod) WHATEVER_YOUR_OLD_PROMPT_WAS
|
|
86
|
+
# All kubectl commands will use the prod context
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To switch to a different context, just run the `source` command with a new
|
|
90
|
+
context:
|
|
75
91
|
|
|
76
92
|
```sh
|
|
77
|
-
kubepile
|
|
93
|
+
kubepile source dev
|
|
78
94
|
```
|
|
79
95
|
|
|
80
|
-
|
|
96
|
+
Note that this requires installing the shell helpers listed in the
|
|
97
|
+
installation instructions. If you haven't installed them yet, install them
|
|
98
|
+
with:
|
|
81
99
|
|
|
82
100
|
```sh
|
|
83
|
-
kubepile
|
|
101
|
+
kubepile install
|
|
84
102
|
```
|
|
85
103
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
`kubepile` binary with `command kubepile`, so it follows whatever `kubepile` is
|
|
89
|
-
currently on your `PATH` after tools like `nvm` update it.
|
|
104
|
+
And re-source your main shell config (such as e.g. a `.zshrc`) or start a new
|
|
105
|
+
shell.
|
|
90
106
|
|
|
91
107
|
## Split
|
|
92
108
|
|
package/dist/package.json
CHANGED
package/dist/src/shell.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { defaultKubeConfigPath,
|
|
4
|
+
import { defaultKubeConfigPath, readKubeConfigFile, serializeKubeConfig, } from "./kubepile.js";
|
|
5
5
|
const SHELL_BLOCK_START = "# >>> kubepile shell integration >>>";
|
|
6
6
|
const SHELL_BLOCK_END = "# <<< kubepile shell integration <<<";
|
|
7
7
|
export async function generateShellCommand(contextName, options = {}) {
|
|
8
8
|
const sourcePath = options.sourcePath ?? defaultKubeConfigPath();
|
|
9
9
|
const shell = options.shell ?? "posix";
|
|
10
10
|
const sourceConfig = await readKubeConfigFile(sourcePath);
|
|
11
|
-
const contextConfig =
|
|
11
|
+
const contextConfig = {
|
|
12
|
+
...sourceConfig,
|
|
13
|
+
"current-context": contextName,
|
|
14
|
+
};
|
|
12
15
|
const tempRoot = await mkdtemp(path.join(options.tempDir ?? os.tmpdir(), "kubepile-source-"));
|
|
13
16
|
const kubeConfigPath = path.join(tempRoot, "config");
|
|
17
|
+
if (!sourceConfig.contexts?.some((context) => context.name === contextName)) {
|
|
18
|
+
throw new Error(`${sourcePath} does not contain context "${contextName}"`);
|
|
19
|
+
}
|
|
14
20
|
await writeFile(kubeConfigPath, serializeKubeConfig(contextConfig), {
|
|
15
21
|
encoding: "utf8",
|
|
16
22
|
mode: 0o600,
|