Skip to content

Commit dc17184

Browse files
authored
Merge pull request kubernetes-sigs#10453 from chrischdi/pr-fix-capd-haproxy-config-read
🐛 CAPD: verify lb config after writing it
2 parents 13c565f + 7dab089 commit dc17184

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

test/infrastructure/docker/internal/docker/loadbalancer.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ func (s *LoadBalancer) UpdateConfiguration(ctx context.Context, unsafeLoadBalanc
191191
return errors.WithStack(err)
192192
}
193193

194+
// Read back the load balancer configuration to ensure it got written before
195+
// signaling haproxy to reload the config file.
196+
// This is a workaround to fix https://github.com/kubernetes-sigs/cluster-api/issues/10356
197+
readLoadBalancerConfig, err := s.container.ReadFile(ctx, loadbalancer.ConfigPath)
198+
if err != nil {
199+
return errors.WithStack(err)
200+
}
201+
if string(readLoadBalancerConfig) != loadBalancerConfig {
202+
return fmt.Errorf("read load balancer configuration does not match written file")
203+
}
204+
194205
return errors.WithStack(s.container.Kill(ctx, "SIGHUP"))
195206
}
196207

test/infrastructure/docker/internal/docker/types/node.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ func (n *Node) Delete(ctx context.Context) error {
120120
return nil
121121
}
122122

123+
// ReadFile reads a file from a running container.
124+
func (n *Node) ReadFile(ctx context.Context, dest string) ([]byte, error) {
125+
command := n.Commander.Command("cp", dest, "/dev/stdout")
126+
stdout := bytes.Buffer{}
127+
128+
command.SetStdout(&stdout)
129+
// Also set stderr so it does not pollute stdout.
130+
command.SetStderr(&bytes.Buffer{})
131+
132+
if err := command.Run(ctx); err != nil {
133+
return nil, errors.Wrapf(err, "failed to read file %s", dest)
134+
}
135+
return stdout.Bytes(), nil
136+
}
137+
123138
// WriteFile puts a file inside a running container.
124139
func (n *Node) WriteFile(ctx context.Context, dest, content string) error {
125140
// create destination directory

0 commit comments

Comments
 (0)