edenlabllc / rmk

RMK CLI - Reduced Management for Kubernetes by Edenlab LLC.
https://edenlabllc.github.io/rmk/latest/
Apache License 2.0
52 stars 1 forks source link

`rmk cluster switch` K8S context selection logic should be more strict #12

Closed anovikov-el closed 3 months ago

anovikov-el commented 4 months ago

Description

When running rmk cluster switch to select an already existing K8S context, there might be a collision for the cases, when a project name includes a name of another project.

For example, the following K8S contexts will conflict:

project1-develop-cluster
myproject1-develop-cluster

This is because the regex doesn't have "\b" in the beginning. Actual regex:

<project_name>-<environment>\b

Expected regex:

\b<project_name>-<environment>\b

In the cases, when there are 2 contexts that match the regex, an error should be thrown to clearly indicate an error condition:

project1-develop-cluster
new-project1-develop-cluster

Steps to reproduce

Create 2 similar contexts, e.g.:

project1-develop-cluster
myproject1-develop-cluster

Run rmk cluster switch from within the both projects. Run rmk release list to verify a wrong context has been selected.

System info

RMK: v0.42.1 OS: macOS Sonoma 14.4.1 Shell: zsh 5.9 (x86_64-apple-darwin23.0) Terminal: iTerm2 3.4.23

anovikov-el commented 3 months ago

Detected "panic", when no context match found.