Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.7] 🐛 CAPD: verify lb config after writing it #10461

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/infrastructure/docker/internal/docker/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ func (s *LoadBalancer) UpdateConfiguration(ctx context.Context, unsafeLoadBalanc
return errors.WithStack(err)
}

// Read back the load balancer configuration to ensure it got written before
// signaling haproxy to reload the config file.
// This is a workaround to fix https://github.com/kubernetes-sigs/cluster-api/issues/10356
readLoadBalancerConfig, err := s.container.ReadFile(ctx, loadbalancer.ConfigPath)
if err != nil {
return errors.WithStack(err)
}
if string(readLoadBalancerConfig) != loadBalancerConfig {
return fmt.Errorf("read load balancer configuration does not match written file")
}

return errors.WithStack(s.container.Kill(ctx, "SIGHUP"))
}

Expand Down
15 changes: 15 additions & 0 deletions test/infrastructure/docker/internal/docker/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ func (n *Node) Delete(ctx context.Context) error {
return nil
}

// ReadFile reads a file from a running container.
func (n *Node) ReadFile(ctx context.Context, dest string) ([]byte, error) {
command := n.Commander.Command("cp", dest, "/dev/stdout")
stdout := bytes.Buffer{}

command.SetStdout(&stdout)
// Also set stderr so it does not pollute stdout.
command.SetStderr(&bytes.Buffer{})

if err := command.Run(ctx); err != nil {
return nil, errors.Wrapf(err, "failed to read file %s", dest)
}
return stdout.Bytes(), nil
}

// WriteFile puts a file inside a running container.
func (n *Node) WriteFile(ctx context.Context, dest, content string) error {
// create destination directory
Expand Down