blob: 8d858086bbb48f64162c58498cba12a5eca27e0d [file] [log] [blame]
Scott Bakere702d122019-10-22 11:54:12 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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
17package afrouterd
18
19import (
Scott Bakerf579f132019-10-24 14:31:41 -070020 "github.com/opencord/voltha-lib-go/v2/pkg/log"
Scott Bakere702d122019-10-22 11:54:12 -070021 "k8s.io/client-go/kubernetes"
22 "k8s.io/client-go/rest"
23 "k8s.io/client-go/tools/clientcmd"
24)
25
26func K8sClientSet() *kubernetes.Clientset {
27 var config *rest.Config
28 if k8sApiServer != "" || k8sKubeConfigPath != "" {
29 // use combination of URL & local kube-config file
30 c, err := clientcmd.BuildConfigFromFlags(k8sApiServer, k8sKubeConfigPath)
31 if err != nil {
32 panic(err)
33 }
34 config = c
35 } else {
36 // use in-cluster config
37 c, err := rest.InClusterConfig()
38 if err != nil {
39 log.Errorf("Unable to load in-cluster config. Try setting K8S_API_SERVER and K8S_KUBE_CONFIG_PATH?")
40 panic(err)
41 }
42 config = c
43 }
44 // creates the clientset
45 clientset, err := kubernetes.NewForConfig(config)
46 if err != nil {
47 panic(err)
48 }
49
50 return clientset
51}