Skip to content

Commit

Permalink
Merge pull request #10461 from k8s-infra-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-10453-to-release-1.7

[release-1.7] 🐛 CAPD: verify lb config after writing it
  • Loading branch information
k8s-ci-robot committed Apr 18, 2024
2 parents 3604dae + 7bb2eab commit f17bb25
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 f17bb25

Please sign in to comment.