Skip to content

Commit

Permalink
Merge pull request #7796 from skmatti/master
Browse files Browse the repository at this point in the history
Use KUBECONFIG env for kuberenetes client if specified
  • Loading branch information
caseydavenport committed Jun 23, 2023
2 parents aff70be + 3d4eccf commit 8234b36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion node/pkg/cni/token_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func Run() {

for tu := range tokenChan {
logrus.Info("Update of CNI kubeconfig triggered based on elapsed time.")
cfg, err := rest.InClusterConfig()
cfg, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG"))
if err != nil {
logrus.WithError(err).Error("Error generating kube config.")
continue
Expand Down
4 changes: 2 additions & 2 deletions node/pkg/lifecycle/shutdown/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

"github.com/projectcalico/calico/node/pkg/lifecycle/utils"
)
Expand All @@ -43,7 +43,7 @@ func Run() {
var clientset *kubernetes.Clientset

// If running under kubernetes with secrets to call k8s API
if config, err := rest.InClusterConfig(); err == nil {
if config, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG")); err == nil {
// default timeout is 30 seconds, which isn't appropriate for this kind of
// shutdown action because network services, like kube-proxy might not be
// running and we don't want to block the full 30 seconds if they are just
Expand Down
5 changes: 3 additions & 2 deletions node/pkg/lifecycle/startup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

api "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
"github.com/projectcalico/api/pkg/lib/numorstring"
Expand Down Expand Up @@ -129,7 +130,7 @@ func Run() {
}

// If running under kubernetes with secrets to call k8s API
if config, err := rest.InClusterConfig(); err == nil {
if config, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG")); err == nil {
// default timeout is 30 seconds, which isn't appropriate for this kind of
// startup action because network services, like kube-proxy might not be
// running and we don't want to block the full 30 seconds if they are just
Expand Down Expand Up @@ -329,7 +330,7 @@ func MonitorIPAddressSubnets() {
if nodeRef := os.Getenv("CALICO_K8S_NODE_REF"); nodeRef != "" {
k8sNodeName = nodeRef
}
if config, err = rest.InClusterConfig(); err == nil {
if config, err = clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG")); err == nil {
// Create the k8s clientset.
clientset, err = kubernetes.NewForConfig(config)
if err != nil {
Expand Down

0 comments on commit 8234b36

Please sign in to comment.