operator: fix gRPC dialing over UDS (#3201)

* operator: add test for gRPC connection over UDS
This commit is contained in:
Markus Rudy 2024-06-25 10:11:57 +02:00 committed by GitHub
parent e0c5acf2f3
commit 3db3db3bf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 73 additions and 7 deletions

View file

@ -21,24 +21,25 @@ import (
// Client is a client for the upgrade agent.
type Client struct {
addr string
dialer Dialer
}
// NewClient creates a new upgrade agent client.
// NewClient creates a new upgrade agent client connecting to the default upgrade-agent Unix socket.
func NewClient() *Client {
return newClientWithAddress(mainconstants.UpgradeAgentMountPath)
}
func newClientWithAddress(addr string) *Client {
return &Client{
addr: "unix:" + addr,
dialer: &net.Dialer{},
}
}
// Upgrade upgrades the Constellation node to the given Kubernetes version.
func (c *Client) Upgrade(ctx context.Context, kubernetesComponents components.Components, WantedKubernetesVersion string) error {
conn, err := grpc.NewClient(mainconstants.UpgradeAgentMountPath, grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(
func(ctx context.Context, addr string) (net.Conn, error) {
return c.dialer.DialContext(ctx, "unix", addr)
},
))
conn, err := grpc.NewClient(c.addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("failed to dial: %w", err)
}