Skip to content

Commit 9187702

Browse files
zejeanmipashagolub
andauthored
[+] add TLS support to patroni leader checker (#299)
Co-authored-by: Pavlo Golub <[email protected]>
1 parent 9351963 commit 9187702

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

checker/patroni_leader_checker.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,29 @@ 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+
tlsConfig, err := getTransport(conf)
24+
if err != nil {
25+
return nil, err
26+
}
27+
28+
transport := &http.Transport{
29+
TLSClientConfig: tlsConfig,
30+
}
31+
32+
client := &http.Client{
33+
Transport: transport,
34+
Timeout: time.Second,
35+
}
36+
37+
return &PatroniLeaderChecker{
38+
Config: conf,
39+
Client: client,
40+
}, nil
2341
}
2442

2543
// GetChangeNotificationStream checks the status in the loop
@@ -29,7 +47,7 @@ func (c *PatroniLeaderChecker) GetChangeNotificationStream(ctx context.Context,
2947
case <-ctx.Done():
3048
return nil
3149
case <-time.After(time.Duration(c.Interval) * time.Millisecond):
32-
r, err := http.Get(c.Endpoints[0] + c.TriggerKey)
50+
r, err := c.Client.Get(c.Endpoints[0] + c.TriggerKey)
3351
if err != nil {
3452
c.Logger.Sugar().Error("patroni REST API error:", err)
3553
continue

0 commit comments

Comments
 (0)