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 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 one context by
69
- creating a temporary kubeconfig containing only that context and exporting
70
- `KUBECONFIG` to point at it. It also prefixes your shell prompt with the context
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
- Shells do not let child processes modify the parent shell environment, so this
74
- requires installing a small shell function first:
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 install
93
+ kubepile source dev
78
94
  ```
79
95
 
80
- Then start a new shell and run:
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 source prod
101
+ kubepile install
84
102
  ```
85
103
 
86
- `kubepile install` installs only for your current shell. It supports bash, zsh,
87
- and fish. The installed function proxies every normal command to the real
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubepile",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Compile and split kubeconfig files from ~/.config/kubepile.",
5
5
  "type": "module",
6
6
  "main": "./dist/src/kubepile.js",
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, extractContextConfig, readKubeConfigFile, serializeKubeConfig, } from "./kubepile.js";
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 = extractContextConfig(sourceConfig, contextName, sourcePath);
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubepile",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Compile and split kubeconfig files from ~/.config/kubepile.",
5
5
  "type": "module",
6
6
  "main": "./dist/src/kubepile.js",