WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
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
19 changes: 13 additions & 6 deletions internal/cmd/ske/kubeconfig/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"k8s.io/client-go/rest"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client"
Expand Down Expand Up @@ -149,20 +151,25 @@ func parseClusterConfig(p *print.Printer, cmd *cobra.Command) (*clusterConfig, e
if execCredential == nil || execCredential.Spec.Cluster == nil {
return nil, fmt.Errorf("ExecCredential contains not all needed fields")
}
config := &clusterConfig{}
err = json.Unmarshal(execCredential.Spec.Cluster.Config.Raw, config)
clusterConfig := &clusterConfig{}
err = json.Unmarshal(execCredential.Spec.Cluster.Config.Raw, clusterConfig)
if err != nil {
return nil, fmt.Errorf("unmarshal: %w", err)
}

config.cacheKey = fmt.Sprintf("ske-login-%x", sha256.Sum256([]byte(execCredential.Spec.Cluster.Server)))
profile, err := config.GetProfile()
if err != nil {
return nil, fmt.Errorf("error getting profile: %w", err)
}

clusterConfig.cacheKey = fmt.Sprintf("ske-login-%x", sha256.Sum256([]byte(execCredential.Spec.Cluster.Server+auth.GetProfileEmail(profile))))

// NOTE: Fallback if region is not set in the kubeconfig (this was the case in the past)
if config.Region == "" {
config.Region = globalflags.Parse(p, cmd).Region
if clusterConfig.Region == "" {
clusterConfig.Region = globalflags.Parse(p, cmd).Region
}

return config, nil
return clusterConfig, nil
}

func getCachedKubeConfig(key string) *rest.Config {
Expand Down
Loading