Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use KUBECONFIG env for kuberenetes client if specified #7796

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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