volcano.sh/volcano@v1.9.0/pkg/kube/config.go (about)

     1  /*
     2  Copyright 2020 The Volcano Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package kube
    18  
    19  import (
    20  	"k8s.io/client-go/rest"
    21  	"k8s.io/client-go/tools/clientcmd"
    22  )
    23  
    24  // ClientOptions used to build kube rest config.
    25  type ClientOptions struct {
    26  	Master     string
    27  	KubeConfig string
    28  	QPS        float32
    29  	Burst      int
    30  }
    31  
    32  // BuildConfig builds kube rest config with the given options.
    33  func BuildConfig(opt ClientOptions) (*rest.Config, error) {
    34  	var cfg *rest.Config
    35  	var err error
    36  
    37  	master := opt.Master
    38  	kubeconfig := opt.KubeConfig
    39  	cfg, err = clientcmd.BuildConfigFromFlags(master, kubeconfig)
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  	cfg.QPS = opt.QPS
    44  	cfg.Burst = opt.Burst
    45  
    46  	return cfg, nil
    47  }