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

Release/v0.42.3 #17

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions commands/release_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ func (rc *ReleaseCommands) releaseHelmfile(args ...string) error {
}

func (rc *ReleaseCommands) getKubeContext() (string, string, error) {
var contextNames []string
var (
contextNames []string
contextName string
)

kubeConfig := &KubeConfig{}

rc.SpecCMD = rc.kubeConfig()
Expand All @@ -287,17 +291,22 @@ func (rc *ReleaseCommands) getKubeContext() (string, string, error) {
}
}

if len(contextNames) > 1 {
switch {
case len(contextNames) > 1:
return "", "",
fmt.Errorf("detected more than one Kubernetes context with names %s leading to conflict, "+
"please delete or rename all contexts except one", strings.Join(contextNames, ", "))
case len(contextNames) > 0:
contextName = contextNames[0]
default:
contextName = ""
}

if rc.K3DCluster && len(contextNames) == 1 && !strings.Contains(contextNames[0], system.K3DConfigPrefix) {
return "", "", fmt.Errorf("remote Kubernetes context already exists %s for this branch", contextNames[0])
if rc.K3DCluster && len(contextName) > 0 && !strings.Contains(contextName, system.K3DConfigPrefix) {
return "", "", fmt.Errorf("remote Kubernetes context already exists %s for this branch", contextName)
}

return contextNames[0], kubeConfig.CurrentContext, nil
return contextName, kubeConfig.CurrentContext, nil
}

func (rc *ReleaseCommands) releaseKubeContext() error {
Expand All @@ -317,6 +326,10 @@ func (rc *ReleaseCommands) releaseKubeContext() error {
return nil
}

if strings.Contains(contextName, system.K3DConfigPrefix) && rc.UpdateContext {
return fmt.Errorf("current context %s already used for K3D cluster, --force flag cannot be used", contextName)
}

cc := &ClusterCommands{
Conf: rc.Conf,
Ctx: rc.Ctx,
Expand Down
2 changes: 1 addition & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- #12 - Implemented logic for strict selection of Kubernetes contexts to prevent conflicts during context selection.
- #12 - Fixed a "panic" log output that occurred when the Kubernetes context was not created before.
Loading