Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#10453 from chrischdi/pr-fix-capd-h…
Browse files Browse the repository at this point in the history
…aproxy-config-read

🐛 CAPD: verify lb config after writing it
  • Loading branch information
k8s-ci-robot authored Apr 18, 2024
2 parents 13c565f + 7dab089 commit dc17184
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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

0 comments on commit dc17184

Please sign in to comment.