Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38a7ad0

Browse files
authored
Merge pull requestsorintlab#666 from jskswamy/timeout-for-kubeclient
Add Timeout for kubeclient
2 parents6003d65 +2f4c21c commit38a7ad0

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

‎cmd/common.go

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path/filepath"
2121

2222
"github.com/prometheus/client_golang/prometheus"
23+
"github.com/sorintlab/stolon/internal/cluster"
2324
"github.com/sorintlab/stolon/internal/common"
2425
"github.com/sorintlab/stolon/internal/store"
2526
"github.com/sorintlab/stolon/internal/util"
@@ -166,23 +167,7 @@ func NewStore(cfg *CommonConfig) (store.Store, error) {
166167
}
167168
s=store.NewKVBackedStore(kvstore,storePath)
168169
case"kubernetes":
169-
kubeClientConfig:=util.NewKubeClientConfig(cfg.KubeConfig,cfg.KubeContext,cfg.KubeNamespace)
170-
kubecfg,err:=kubeClientConfig.ClientConfig()
171-
iferr!=nil {
172-
returnnil,err
173-
}
174-
kubecli,err:=kubernetes.NewForConfig(kubecfg)
175-
iferr!=nil {
176-
returnnil,fmt.Errorf("cannot create kubernetes client: %v",err)
177-
}
178-
varpodNamestring
179-
if!cfg.IsStolonCtl {
180-
podName,err=util.PodName()
181-
iferr!=nil {
182-
returnnil,err
183-
}
184-
}
185-
namespace,_,err:=kubeClientConfig.Namespace()
170+
kubecli,podName,namespace,err:=getKubeValues(cfg)
186171
iferr!=nil {
187172
returnnil,err
188173
}
@@ -212,23 +197,7 @@ func NewElection(cfg *CommonConfig, uid string) (store.Election, error) {
212197
}
213198
election=store.NewKVBackedElection(kvstore,filepath.Join(storePath,common.SentinelLeaderKey),uid)
214199
case"kubernetes":
215-
kubeClientConfig:=util.NewKubeClientConfig(cfg.KubeConfig,cfg.KubeContext,cfg.KubeNamespace)
216-
kubecfg,err:=kubeClientConfig.ClientConfig()
217-
iferr!=nil {
218-
returnnil,err
219-
}
220-
kubecli,err:=kubernetes.NewForConfig(kubecfg)
221-
iferr!=nil {
222-
returnnil,fmt.Errorf("cannot create kubernetes client: %v",err)
223-
}
224-
varpodNamestring
225-
if!cfg.IsStolonCtl {
226-
podName,err=util.PodName()
227-
iferr!=nil {
228-
returnnil,err
229-
}
230-
}
231-
namespace,_,err:=kubeClientConfig.Namespace()
200+
kubecli,podName,namespace,err:=getKubeValues(cfg)
232201
iferr!=nil {
233202
returnnil,err
234203
}
@@ -240,3 +209,28 @@ func NewElection(cfg *CommonConfig, uid string) (store.Election, error) {
240209

241210
returnelection,nil
242211
}
212+
213+
funcgetKubeValues(cfg*CommonConfig) (*kubernetes.Clientset,string,string,error) {
214+
kubeClientConfig:=util.NewKubeClientConfig(cfg.KubeConfig,cfg.KubeContext,cfg.KubeNamespace)
215+
kubecfg,err:=kubeClientConfig.ClientConfig()
216+
iferr!=nil {
217+
returnnil,"","",err
218+
}
219+
kubecfg.Timeout=cluster.DefaultStoreTimeout
220+
kubecli,err:=kubernetes.NewForConfig(kubecfg)
221+
iferr!=nil {
222+
returnnil,"","",fmt.Errorf("cannot create kubernetes client: %v",err)
223+
}
224+
varpodNamestring
225+
if!cfg.IsStolonCtl {
226+
podName,err=util.PodName()
227+
iferr!=nil {
228+
returnnil,"","",err
229+
}
230+
}
231+
namespace,_,err:=kubeClientConfig.Namespace()
232+
iferr!=nil {
233+
returnnil,"","",err
234+
}
235+
returnkubecli,podName,namespace,nil
236+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp