Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context configs: context directory created under wrong cluster after context switch #3162

Closed
rocketraman opened this issue Feb 28, 2025 · 7 comments
Labels
bug Something isn't working in-progress Mark issue as being worked on

Comments

@rocketraman
Copy link

rocketraman commented Feb 28, 2025




Describe the bug
Say we have 2 contexts, context-1 and context-2. Each of these points to a different cluster, cluster-1 and cluster-2 respectively.

If we now start k9s with context-1 active, at the top-left k9s shows:

Context: context-1
Cluster: cluster-1

As expected, a context-specific configuration is created in the "Context Configs" with the following directory name:

clusters/cluster-1/context-1/

Now, in k9s use the ctx switcher to switch to context-2. Now, k9s shows at the top-left the expected values:

Context: context-2
Cluster: cluster-2

However, a context-specific configuration is created in the "Context Configs" with the following unexpected directory, where the cluster matches the initial cluster k9s was started with:

clusters/cluster-1/context-2/

The content of that directory appears to be a copy of clusters/cluster-2/context-2/ (assuming it already existed previously).

Expected behavior
I would expect each cluster-n directory to only include the relevant context-n directory.

Versions (please complete the following information):

  • OS: Linux 6.12.11-200.fc41.x86_64
  • K9s: v0.40.5
  • K8s: v1.30.8-gke.1261000
@rocketraman rocketraman changed the title Context configs: context shown under wrong cluster after context switch Context configs: context directory created under wrong cluster after context switch Feb 28, 2025
@derailed
Copy link
Owner

derailed commented Mar 1, 2025

@rocketraman Weird?? I can't seem to repro this. The config seems to be written correctly to the right cluster/context after the ctx switch. Perhaps including the logs will shine some insight...

@derailed derailed added question Further information is requested no-repro labels Mar 1, 2025
@uozalp
Copy link
Contributor

uozalp commented Mar 2, 2025

I have also experienced this.

@uozalp
Copy link
Contributor

uozalp commented Mar 3, 2025

I added some additional debug
d695978

11:41AM DBG K9s latest rev: "v0.40.5"
11:41AM DBG No custom skin found. Using stock skin
11:42AM DBG Switching context "ctx1"
11:42AM DBG Context config not found! Generating... "/home/uoza/.local/share/k9s/cluster1/cluster1/ctx1/config.yaml"
11:42AM DBG Generated context config "/home/uoza/.local/share/k9s/clusters/cluster1/ctx1/config.yaml"
11:42AM DBG ClusterInfo updater canceled!
11:42AM DBG Saving context config "/home/uoza/.local/share/k9s/clusters/cluster1/ctx1/config.yaml"
11:42AM DBG Saving context config "/home/uoza/.local/share/k9s/clusters/cluster1/ctx/config.yaml"
11:42AM DBG Saved context config for: "ctx1"
11:42AM DBG Factory START with ns "default"
11:42AM DBG --> Switching Context "ctx1" -- "default" -- "po"
11:42AM DBG No custom skin found. Using stock skin
11:42AM DBG Switching context "ctx2"
11:42AM DBG Context config not found! Generating... "/home/uoza/.local/share/k9s/clusters/cluster2/ctx2/config.yaml"
11:42AM DBG Generated context config "/home/uoza/.local/share/k9s/clusters/cluster2/ctx2/config.yaml"
11:42AM DBG ClusterInfo updater canceled!
11:42AM DBG Saving context config "/home/uoza/.local/share/k9s/clusters/cluster2/ctx2/config.yaml"
11:42AM DBG Saving context config "/home/uoza/.local/share/k9s/clusters/cluster1/ctx2/config.yaml" # <---- This line
11:42AM DBG Saved context config for: "ctx2"
11:42AM DBG Factory START with ns "default"
11:42AM DBG --> Switching Context "ctx2" -- "default" -- "po"
11:42AM DBG No custom skin found. Using stock skin

@rocketraman
Copy link
Author

rocketraman commented Mar 3, 2025

@derailed Here are the logs (not including the additional debug added by @uozalp ):

8:03AM INF 🐶 K9s starting up...
8:03AM DBG Context config not found! Generating... "/home/raman/.local/share/k9s/clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/config.yaml"
8:03AM DBG Active Context "gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1"
8:03AM INF ✅ Kubernetes connectivity
8:03AM DBG [Skin] Loading global skin ("monokai")
8:03AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"
8:03AM DBG Factory START with ns "default"
8:03AM DBG Fetching latest k9s rev...
8:03AM DBG K9s latest rev: "v0.40.5"
8:03AM DBG [Skin] Loading global skin ("monokai")
8:03AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"
8:03AM DBG SWITCH CTX "contexts"--"gke_redock-prod"
8:03AM DBG Switching context "gke_redock-prod"
8:03AM DBG Context config not found! Generating... "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/config.yaml"
8:03AM DBG ClusterInfo updater canceled!
8:03AM DBG Saved context config for: "gke_redock-prod"
8:03AM DBG Factory START with ns "default"
8:03AM DBG --> Switching Context "gke_redock-prod" -- "default" -- "po"
8:03AM DBG [Skin] Loading global skin ("monokai")
8:03AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"
8:03AM DBG SWITCH CTX "contexts"--"gke_redock-prod-us"
8:03AM DBG Switching context "gke_redock-prod-us"
8:03AM DBG Context config not found! Generating... "/home/raman/.local/share/k9s/clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/config.yaml"
8:03AM DBG ClusterInfo updater canceled!
8:03AM DBG Saved context config for: "gke_redock-prod-us"
8:03AM DBG Factory START with ns "default"
8:03AM DBG --> Switching Context "gke_redock-prod-us" -- "default" -- "po"
8:03AM DBG [Skin] Loading global skin ("monokai")
8:03AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"

The reproduction was slightly different than I stated in my OP:

  1. Open k9s at the currently selected context gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1.

  2. Switch to context/cluster gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod.

  3. Switch to context/cluster gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us.

The end result of the clusters directory contained a copy of the 3rd cluster inside the 2nd context:

clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/
clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/
clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/benchmarks.yaml
clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/config.yaml
clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/
clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/
clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/config.yaml
clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/
clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/
clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/benchmarks.yaml
clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/config.yaml
clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/
clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/benchmarks.yaml
clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/config.yaml

The diffs between the two are almost the same except the cluster identifier:

Only in clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/: benchmarks.yaml
diff -u clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/config.yaml clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/config.yaml
--- clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/config.yaml	2025-03-03 08:25:44.085372096 -0500
+++ clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/config.yaml	2025-03-03 08:25:46.121412131 -0500
@@ -1,5 +1,5 @@
 k9s:
-  cluster: gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4
+  cluster: gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1
   namespace:
     active: default
     lockFavorites: false

@rocketraman
Copy link
Author

Here are the logs with the debug commit from @uozalp:

8:54AM INF 🐶 K9s starting up...
8:54AM DBG Context config not found! Generating... "/home/raman/.local/share/k9s/clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/config.yaml"
8:54AM DBG Generated context config "/home/raman/.local/share/k9s/clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/config.yaml"
8:54AM DBG Saving context config "/home/raman/.local/share/k9s/clusters/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1/config.yaml"
8:54AM DBG Active Context "gke_redock-dev-test_northamerica-northeast1-b_redock-k8s-devtest-na-ne-1"
8:54AM INF ✅ Kubernetes connectivity
8:54AM DBG [Skin] Loading global skin ("monokai")
8:54AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"
8:54AM DBG Factory START with ns "default"
8:54AM DBG Fetching latest k9s rev...
8:54AM DBG K9s latest rev: "v0.40.5"
8:54AM DBG [Skin] Loading global skin ("monokai")
8:54AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"
8:54AM DBG SWITCH CTX "contexts"--"gke_redock-prod"
8:54AM DBG Switching context "gke_redock-prod"
8:54AM DBG Context config not found! Generating... "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/config.yaml"
8:54AM DBG Generated context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/config.yaml"
8:54AM DBG ClusterInfo updater canceled!
8:54AM DBG Saving context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/config.yaml"
8:54AM DBG Saving context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod/config.yaml"
8:54AM DBG Saved context config for: "gke_redock-prod"
8:54AM DBG Factory START with ns "default"
8:54AM DBG --> Switching Context "gke_redock-prod" -- "default" -- "po"
8:54AM DBG [Skin] Loading global skin ("monokai")
8:54AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"
8:54AM DBG SWITCH CTX "contexts"--"gke_redock-prod-us"
8:54AM DBG Switching context "gke_redock-prod-us"
8:54AM DBG Context config not found! Generating... "/home/raman/.local/share/k9s/clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/config.yaml"
8:54AM DBG Generated context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/config.yaml"
8:54AM DBG ClusterInfo updater canceled!
8:54AM DBG Saving context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod-us_us-east4-b_redock-k8s-prod-us-us-e4/gke_redock-prod-us/config.yaml"
8:54AM DBG Saving context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/config.yaml"
8:54AM DBG Saved context config for: "gke_redock-prod-us"
8:54AM DBG Factory START with ns "default"
8:54AM DBG --> Switching Context "gke_redock-prod-us" -- "default" -- "po"
8:54AM DBG [Skin] Loading global skin ("monokai")
8:54AM DBG Loading skin file: "/home/raman/.config/k9s/skins/monokai.yaml"
8:54AM DBG Saving context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/config.yaml"
8:54AM DBG Saving context config "/home/raman/.local/share/k9s/clusters/gke_redock-prod_northamerica-northeast1-b_redock-k8s-prod-ca-na-ne1/gke_redock-prod-us/config.yaml"

@derailed
Copy link
Owner

derailed commented Mar 7, 2025

@uozalp @rocketraman Thank you both for the additional details!

@derailed derailed added bug Something isn't working in-progress Mark issue as being worked on and removed no-repro question Further information is requested labels Mar 7, 2025
@derailed derailed mentioned this issue Mar 9, 2025
@derailed
Copy link
Owner

derailed commented Mar 9, 2025

Fixed v0.40.6

@derailed derailed closed this as completed Mar 9, 2025
tmeijn pushed a commit to tmeijn/dotfiles that referenced this issue Mar 10, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [derailed/k9s](https://github.com/derailed/k9s) | patch | `v0.40.5` -> `v0.40.6` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>derailed/k9s (derailed/k9s)</summary>

### [`v0.40.6`](https://github.com/derailed/k9s/releases/tag/v0.40.6)

[Compare Source](derailed/k9s@v0.40.5...v0.40.6)

<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/k9s.png" align="center" width="800" height="auto"/>

### Release v0.40.6
#### Notes

Thank you to all that contributed with flushing out issues and enhancements for K9s!
I'll try to mark some of these issues as fixed. But if you don't mind grab the latest rev
and see if we're happier with some of the fixes!
If you've filed an issue please help me verify and close.

Your support, kindness and awesome suggestions to make K9s better are, as ever, very much noted and appreciated!
Also big thanks to all that have allocated their own time to help others on both slack and on this repo!!

As you may know, K9s is not pimped out by corps with deep pockets, thus if you feel K9s is helping your Kubernetes journey,
please consider joining our [sponsorship program](https://github.com/sponsors/derailed) and/or make some noise on social! [@&#8203;kitesurfer](https://twitter.com/kitesurfer)

On Slack? Please join us [K9slackers](https://join.slack.com/t/k9sers/shared_invite/enQtOTA5MDEyNzI5MTU0LWQ1ZGI3MzliYzZhZWEyNzYxYzA3NjE0YTk1YmFmNzViZjIyNzhkZGI0MmJjYzhlNjdlMGJhYzE2ZGU1NjkyNTM)

#### Maintenance Release!

##### Breaking change

Moved `portForwardAddress` out of clusterXXX/contextYYY/config.yaml and into the main K9s config file.
This is a global preference based on your setup vs a cluster/context specific attribute.
K9s will nag you in the logs if a specific context config still contains this attribute but should not prevent the configuration load.

##### Column Blow Reloaded!

We've added another property to the custom view. You can now also specify namespace specific column definition for a given resource.
For instance, view pods in any namespace using one configuration and view pods in `fred` namespace using an alternate configuration.

```yaml

### views.yaml
views:

### Using this for all pods...
  v1/pods:
    columns:
      - AGE
      - NAMESPACE|WR                                     # => 🌚 Specifies the NAMESPACE column to be right aligned and only visible while in wide mode
      - ZORG:.metadata.labels.fred\.io\.kubernetes\.blee # => 🌚 extract fred.io.kubernetes.blee label into it's own column
      - BLEE:.metadata.annotations.blee|R                # => 🌚 extract annotation blee into it's own column and right align it
      - NAME
      - IP
      - NODE
      - STATUS
      - READY
      - MEM/RL|S                                         # => 🌚 Overrides std resource default wide attribute via `S` for `Show`
      - '%MEM/R|'                                        # => NOTE! column names with non alpha names need to be quoted as columns must be strings!

### Use this instead for pods in namespace `fred`
   v1/pods@fred:                                         # => 🌚 New v0.40.6! Customize columns for a given resource and namespace!
    columns:
      - AGE
      - NAMESPACE|WR
```

Additionally, we've added a new column attribute aka `Show` -> `S`. This allows you to now override the default resource column `wide` attribute when set.

***

#### Videos Are In The Can!

Please dial [K9s Channel](https://www.youtube.com/channel/UC897uwPygni4QIjkPCpgjmw) for up coming content...

-   [K9s v0.40.0 -Column Blow- Sneak peek](https://youtu.be/iy6RDozAM4A)
-   [K9s v0.31.0 Configs+Sneak peek](https://youtu.be/X3444KfjguE)
-   [K9s v0.30.0 Sneak peek](https://youtu.be/mVBc1XneRJ4)
-   [Vulnerability Scans](https://youtu.be/ULkl0MsaidU)

***

#### Resolved Issues

-   [#&#8203;3179](derailed/k9s#3179) Resource name with full api or group displayed (somewhere and sometimes)
-   [#&#8203;3178](derailed/k9s#3178) Cronjobs with the same name in different namespaces appear together
-   [#&#8203;3176](derailed/k9s#3176) Trigger all marked cronjobs
-   [#&#8203;3162](derailed/k9s#3162) Context configs: context directory created under wrong cluster after context switch
-   [#&#8203;3161](derailed/k9s#3161) Force wide-only columns to appear outside of wide view
-   [#&#8203;3147](derailed/k9s#3147) Prompt style is overriden by body
-   [#&#8203;3139](derailed/k9s#3139) CPU/R:L and MEM/R:L columns invalid in views.yaml
-   [#&#8203;3138](derailed/k9s#3138) Subresources are not shown correctly in the RBAC view

***

#### Contributed MRs

Please be sure to give `Big Thanks!` and `ATTA Girls/Boys!` to all the fine contributors for making K9s better for all of us!!

-   [#&#8203;3182](derailed/k9s#3182) fix: Use the latest version when downloading the Ubuntu deb file
-   [#&#8203;3168](derailed/k9s#3168) fix(history): handle cases where special commands add their command their command to the history
-   [#&#8203;3159](derailed/k9s#3159) Added hard contrast gruvbox skins
-   [#&#8203;3149](derailed/k9s#3149) fix: Pass grv on gotoResource as a String to fix non-default apiGroup list
-   [#&#8203;3149](derailed/k9s#3149) Add externalsecrets plugin
-   [#&#8203;3140](derailed/k9s#3140) fix: Avoid false positive matches in enableRegion ([#&#8203;3093](derailed/k9s#3093))

<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/imhotep_logo.png" width="32" height="auto"/> © 2025 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xOTAuMSIsInVwZGF0ZWRJblZlciI6IjM5LjE5MC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in-progress Mark issue as being worked on
Projects
None yet
Development

No branches or pull requests

3 participants