Skip to content

Commit

Permalink
Merge pull request #11052 from k8s-infra-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-11049-to-release-1.8

[release-1.8] 🌱 Improve clusterctl client config logic & error message
  • Loading branch information
k8s-ci-robot authored Aug 13, 2024
2 parents cb13053 + 1d0078e commit 2d48211
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cmd/clusterctl/client/cluster/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -142,12 +143,10 @@ func (k *proxy) GetConfig() (*rest.Config, error) {
}
restConfig, err := clientcmd.NewDefaultClientConfig(*config, configOverrides).ClientConfig()
if err != nil {
if !strings.HasPrefix(err.Error(), "invalid configuration:") {
return nil, err
}
restConfig, err = rest.InClusterConfig()
if err != nil {
return nil, errors.New(strings.Replace(err.Error(), "invalid configuration:", "invalid kubeconfig file and failed to create inClusterConfig as well:", 1))
var inClusterErr error
restConfig, inClusterErr = rest.InClusterConfig()
if inClusterErr != nil {
return nil, errors.Wrapf(kerrors.NewAggregate([]error{err, inClusterErr}), "clusterctl requires either a valid kubeconfig or in cluster config to connect to the management cluster")
}
}
restConfig.UserAgent = fmt.Sprintf("clusterctl/%s (%s)", version.Get().GitVersion, version.Get().Platform)
Expand Down

0 comments on commit 2d48211

Please sign in to comment.