Skip to content

Commit

Permalink
Merge pull request #17 from edenlabllc/release/v0.42.3
Browse files Browse the repository at this point in the history
Release/v0.42.3
  • Loading branch information
apanasiuk-el authored Jun 24, 2024
2 parents 89eab14 + cbbf8a1 commit 3de344d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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.

0 comments on commit 3de344d

Please sign in to comment.