Skip to content

Commit

Permalink
Merge pull request #666 from jskswamy/timeout-for-kubeclient
Browse files Browse the repository at this point in the history
Add Timeout for kubeclient
  • Loading branch information
sgotti authored Jun 6, 2019
2 parents 6003d65 + 2f4c21c commit 38a7ad0
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path/filepath"

"github.com/prometheus/client_golang/prometheus"
"github.com/sorintlab/stolon/internal/cluster"
"github.com/sorintlab/stolon/internal/common"
"github.com/sorintlab/stolon/internal/store"
"github.com/sorintlab/stolon/internal/util"
Expand Down Expand Up @@ -166,23 +167,7 @@ func NewStore(cfg *CommonConfig) (store.Store, error) {
}
s = store.NewKVBackedStore(kvstore, storePath)
case "kubernetes":
kubeClientConfig := util.NewKubeClientConfig(cfg.KubeConfig, cfg.KubeContext, cfg.KubeNamespace)
kubecfg, err := kubeClientConfig.ClientConfig()
if err != nil {
return nil, err
}
kubecli, err := kubernetes.NewForConfig(kubecfg)
if err != nil {
return nil, fmt.Errorf("cannot create kubernetes client: %v", err)
}
var podName string
if !cfg.IsStolonCtl {
podName, err = util.PodName()
if err != nil {
return nil, err
}
}
namespace, _, err := kubeClientConfig.Namespace()
kubecli, podName, namespace, err := getKubeValues(cfg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -212,23 +197,7 @@ func NewElection(cfg *CommonConfig, uid string) (store.Election, error) {
}
election = store.NewKVBackedElection(kvstore, filepath.Join(storePath, common.SentinelLeaderKey), uid)
case "kubernetes":
kubeClientConfig := util.NewKubeClientConfig(cfg.KubeConfig, cfg.KubeContext, cfg.KubeNamespace)
kubecfg, err := kubeClientConfig.ClientConfig()
if err != nil {
return nil, err
}
kubecli, err := kubernetes.NewForConfig(kubecfg)
if err != nil {
return nil, fmt.Errorf("cannot create kubernetes client: %v", err)
}
var podName string
if !cfg.IsStolonCtl {
podName, err = util.PodName()
if err != nil {
return nil, err
}
}
namespace, _, err := kubeClientConfig.Namespace()
kubecli, podName, namespace, err := getKubeValues(cfg)
if err != nil {
return nil, err
}
Expand All @@ -240,3 +209,28 @@ func NewElection(cfg *CommonConfig, uid string) (store.Election, error) {

return election, nil
}

func getKubeValues(cfg *CommonConfig) (*kubernetes.Clientset, string, string, error) {
kubeClientConfig := util.NewKubeClientConfig(cfg.KubeConfig, cfg.KubeContext, cfg.KubeNamespace)
kubecfg, err := kubeClientConfig.ClientConfig()
if err != nil {
return nil, "", "", err
}
kubecfg.Timeout = cluster.DefaultStoreTimeout
kubecli, err := kubernetes.NewForConfig(kubecfg)
if err != nil {
return nil, "", "", fmt.Errorf("cannot create kubernetes client: %v", err)
}
var podName string
if !cfg.IsStolonCtl {
podName, err = util.PodName()
if err != nil {
return nil, "", "", err
}
}
namespace, _, err := kubeClientConfig.Namespace()
if err != nil {
return nil, "", "", err
}
return kubecli, podName, namespace, nil
}

0 comments on commit 38a7ad0

Please sign in to comment.