Skip to content

Commit

Permalink
fix(config-cache): use netip.Addr to unify the IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-kokoszka committed Feb 25, 2025
1 parent 6b27b40 commit 8e47f59
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/service/configcache/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package configcache

import (
"context"
"net/netip"
"sync"
"time"

Expand Down Expand Up @@ -80,7 +81,12 @@ func (svc *Service) Read(clusterID uuid.UUID, host string) (NodeConfig, error) {
return emptyConfig, err
}

rawHostConfig, ok := clusterConfig.Load(host)
hostKey := host
if addr, err := netip.ParseAddr(host); err == nil {
hostKey = addr.String()
}

rawHostConfig, ok := clusterConfig.Load(hostKey)
if !ok {
return emptyConfig, ErrNoHostConfig
}
Expand Down Expand Up @@ -192,17 +198,23 @@ func (svc *Service) updateSingle(ctx context.Context, c *cluster.Cluster) bool {

for _, host := range client.Config().Hosts {
hostsWg.Add(1)
hostKey := host

parsedIP, err := netip.ParseAddr(host)
if err == nil {
hostKey = parsedIP.String()
}

perHostLogger := logger.Named("Cluster host config update").With("host", host)
perHostLogger := logger.Named("Cluster host config update").With("host", host, "hostKey", hostKey)
go func() {
defer hostsWg.Done()

config, err := svc.retrieveNodeConfig(ctx, host, client, c)
config, err := svc.retrieveNodeConfig(ctx, hostKey, client, c)
if err != nil {
perHostLogger.Error(ctx, "Couldn't read cluster host config", "error", err)
return
}
clusterConfig.Store(host, config)
clusterConfig.Store(hostKey, config)
}()
}
hostsWg.Wait()
Expand Down

0 comments on commit 8e47f59

Please sign in to comment.