Skip to content

Commit 853f4e3

Browse files
committed
tls for patroni leader checker
1 parent 9351963 commit 853f4e3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

checker/patroni_leader_checker.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,31 @@ import (
1515
// --trigger-value is used to specify the HTTP code to expect, e.g. 200.
1616
type PatroniLeaderChecker struct {
1717
*vipconfig.Config
18+
*http.Client
1819
}
1920

2021
// NewPatroniLeaderChecker returns a new instance
2122
func NewPatroniLeaderChecker(conf *vipconfig.Config) (*PatroniLeaderChecker, error) {
22-
return &PatroniLeaderChecker{conf}, nil
23+
24+
tlsConfig, err := getTransport(conf)
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
transport := &http.Transport{}
30+
if tlsConfig != nil {
31+
transport.TLSClientConfig = tlsConfig
32+
}
33+
34+
client := &http.Client{
35+
Transport: transport,
36+
Timeout: time.Second,
37+
}
38+
39+
return &PatroniLeaderChecker{
40+
Config: conf,
41+
Client: client,
42+
}, nil
2343
}
2444

2545
// GetChangeNotificationStream checks the status in the loop
@@ -29,7 +49,7 @@ func (c *PatroniLeaderChecker) GetChangeNotificationStream(ctx context.Context,
2949
case <-ctx.Done():
3050
return nil
3151
case <-time.After(time.Duration(c.Interval) * time.Millisecond):
32-
r, err := http.Get(c.Endpoints[0] + c.TriggerKey)
52+
r, err := c.Client.Get(c.Endpoints[0] + c.TriggerKey)
3353
if err != nil {
3454
c.Logger.Sugar().Error("patroni REST API error:", err)
3555
continue

0 commit comments

Comments
 (0)