Skip to content

Commit 08f3f09

Browse files
author
Mikhail Podtserkovskiy
committed
QA-7710: move hardcode to config
1 parent 97d134c commit 08f3f09

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

pool/strategy/kubernetes/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,33 @@ import (
44
"encoding/json"
55
"errors"
66
"github.com/qa-dev/jsonwire-grid/config"
7+
"time"
8+
"fmt"
79
)
810

911
type strategyParams struct {
12+
Namespace string
13+
PodCreationTimeout time.Duration
14+
}
15+
16+
func (sp *strategyParams) UnmarshalJSON(b []byte) error {
17+
tempStruct := struct{
18+
Namespace string `json:"namespace"`
19+
PodCreationTimeout string `json:"pod_creation_timeout"`
20+
} {
21+
"default",
22+
"1m",
23+
}
24+
if err := json.Unmarshal(b, &tempStruct); err != nil {
25+
return err
26+
}
27+
podCreationTimeout, err := time.ParseDuration(tempStruct.PodCreationTimeout)
28+
if err != nil {
29+
return fmt.Errorf("invalid value strategy.pod_creation_timeout in config, given: %v", tempStruct.PodCreationTimeout)
30+
}
31+
sp.Namespace = tempStruct.Namespace
32+
sp.PodCreationTimeout = podCreationTimeout
33+
return nil
1034
}
1135

1236
type strategyConfig struct {

pool/strategy/kubernetes/factory.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/qa-dev/jsonwire-grid/pool/capabilities"
99
"k8s.io/client-go/kubernetes"
1010
"k8s.io/client-go/rest"
11+
log "github.com/Sirupsen/logrus"
1112
)
1213

1314
type StrategyFactory struct {
@@ -31,6 +32,8 @@ func (f *StrategyFactory) Create(
3132
}
3233
}
3334

35+
log.Debugf("strategy kubernetes config, %+v", strategyConfig)
36+
3437
//todo: выпилить этот говноклиент, когда будет работать нормальный
3538
kubConfig, err := rest.InClusterConfig()
3639
if err != nil {
@@ -44,7 +47,8 @@ func (f *StrategyFactory) Create(
4447

4548
provider := &kubDnsProvider{
4649
clientset: clientset,
47-
namespace: "default", //todo: брать из конфига !!!
50+
namespace: strategyConfig.Params.Namespace,
51+
podCreationTimeout: strategyConfig.Params.PodCreationTimeout,
4852
clientFactory: clientFactory,
4953
}
5054

pool/strategy/kubernetes/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type kubernetesProviderInterface interface {
2222
type kubDnsProvider struct {
2323
clientset *kubernetes.Clientset
2424
namespace string
25+
podCreationTimeout time.Duration
2526
clientFactory jsonwire.ClientFactoryInterface
2627
}
2728

@@ -44,13 +45,13 @@ func (p *kubDnsProvider) Create(podName string, nodeParams nodeParams) (nodeAddr
4445
return "", errors.New("send command pod/create to k8s, " + err.Error())
4546
}
4647

47-
stopWaitIP := time.After(40 * time.Second)
48+
stop := time.After(p.podCreationTimeout)
4849
log.Debugf("start waiting pod ip")
4950
var createdPodIP string
5051
LoopWaitIP:
5152
for {
5253
select {
53-
case <-stopWaitIP:
54+
case <-stop:
5455
return "", fmt.Errorf("wait podIP stopped by timeout, %v", podName)
5556
default:
5657
time.Sleep(time.Second)
@@ -71,7 +72,6 @@ LoopWaitIP:
7172
// todo: пока так ожидаем поднятие ноды, так как не понятно что конкретно означают статусы возвращаемые через апи
7273
nodeAddress = net.JoinHostPort(createdPodIP, nodeParams.Port)
7374
client := p.clientFactory.Create(nodeAddress)
74-
stop := time.After(40 * time.Second)
7575
log.Debugln("start waiting selenium")
7676
LoopWaitSelenium:
7777
for {

0 commit comments

Comments
 (0)