Skip to content

Commit

Permalink
Merge pull request #7156 from Duke0404/master
Browse files Browse the repository at this point in the history
Support using in-cluster kubeconfig
  • Loading branch information
k8s-ci-robot authored Aug 20, 2024
2 parents 51c7719 + 351748c commit 7fc6faa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cluster-autoscaler/utils/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import (
)

const (
failedToBuildConfigErr = "Failed to build config"
failedToParseK8sUrlErr = "Failed to parse Kubernetes url"
failedToBuildClientConfigErr = "Failed to build Kubernetes client configuration"
failedToBuildConfigErr = "Failed to build config"
failedToParseK8sUrlErr = "Failed to parse Kubernetes url"
failedToBuildClientConfigErr = "Failed to build Kubernetes client configuration"
failedToFindInClusterConfigErr = "Failed to find in-cluster config"
)

// CreateKubeClient creates kube client based on AutoscalingOptions.KubeClientOptions
Expand All @@ -50,7 +51,7 @@ func GetKubeConfig(opts config.KubeClientOptions) *rest.Config {
if err != nil {
klog.Fatalf("%v: %v", failedToBuildConfigErr, err)
}
} else {
} else if opts.Master != "" {
url, err := url.Parse(opts.Master)
if err != nil {
klog.Fatalf("%v: %v", failedToParseK8sUrlErr, err)
Expand All @@ -60,8 +61,12 @@ func GetKubeConfig(opts config.KubeClientOptions) *rest.Config {
if err != nil {
klog.Fatalf("%v: %v", failedToBuildClientConfigErr, err)
}
} else {
kubeConfig, err = rest.InClusterConfig()
if err != nil {
klog.Fatalf("%v: %v", failedToFindInClusterConfigErr, err)
}
}

kubeConfig.QPS = opts.KubeClientQPS
kubeConfig.Burst = opts.KubeClientBurst
kubeConfig.ContentType = opts.APIContentType
Expand Down

0 comments on commit 7fc6faa

Please sign in to comment.