github.com/latiif/helm@v2.15.0+incompatible/pkg/kube/config.go (about)

     1  /*
     2  Copyright The Helm 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 // import "k8s.io/helm/pkg/kube"
    18  
    19  import (
    20  	"k8s.io/client-go/tools/clientcmd"
    21  )
    22  
    23  // GetConfig returns a Kubernetes client config for a given context.
    24  func GetConfig(context string, kubeconfig string) clientcmd.ClientConfig {
    25  	rules := clientcmd.NewDefaultClientConfigLoadingRules()
    26  	rules.DefaultClientConfig = &clientcmd.DefaultClientConfig
    27  
    28  	overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmd.ClusterDefaults}
    29  
    30  	if context != "" {
    31  		overrides.CurrentContext = context
    32  	}
    33  
    34  	if kubeconfig != "" {
    35  		rules.ExplicitPath = kubeconfig
    36  	}
    37  
    38  	return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides)
    39  }