github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/kubernetes/client/client.go (about) 1 /* 2 Copyright 2019 The Skaffold 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 client 18 19 import ( 20 "fmt" 21 22 "k8s.io/client-go/dynamic" 23 "k8s.io/client-go/kubernetes" 24 _ "k8s.io/client-go/plugin/pkg/client/auth" 25 26 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" 27 ) 28 29 // for tests 30 var ( 31 Client = getClientset 32 DynamicClient = getDynamicClient 33 DefaultClient = getDefaultClientset 34 ) 35 36 func getClientset(kubeContext string) (kubernetes.Interface, error) { 37 config, err := context.GetRestClientConfig(kubeContext) 38 if err != nil { 39 return nil, fmt.Errorf("getting client config for Kubernetes client: %w", err) 40 } 41 return kubernetes.NewForConfig(config) 42 } 43 44 func getDynamicClient(kubeContext string) (dynamic.Interface, error) { 45 config, err := context.GetRestClientConfig(kubeContext) 46 if err != nil { 47 return nil, fmt.Errorf("getting client config for dynamic client: %w", err) 48 } 49 return dynamic.NewForConfig(config) 50 } 51 52 func getDefaultClientset() (kubernetes.Interface, error) { 53 config, err := context.GetDefaultRestClientConfig() 54 if err != nil { 55 return nil, fmt.Errorf("getting client config for Kubernetes client: %w", err) 56 } 57 return kubernetes.NewForConfig(config) 58 }