Skip to content

Commit 5f2ea9a

Browse files
committed
speed up /etc/hosts injection
1 parent 53bdbec commit 5f2ea9a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pkg/client/cluster.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,21 @@ func prepInjectHostIP(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.C
10161016
l.Log().Tracef("Not injecting hostIP as clusternetwork is 'host'")
10171017
return nil
10181018
}
1019-
l.Log().Infoln("Trying to get IP of the docker host and inject it into the cluster as 'host.k3d.internal' for easy access")
1019+
10201020
hostIP := clusterStartOpts.EnvironmentInfo.HostGateway
10211021
hostsEntry := fmt.Sprintf("%s %s", hostIP.String(), k3d.DefaultK3dInternalHostRecord)
1022-
l.Log().Debugf("Adding extra host entry '%s'...", hostsEntry)
1022+
l.Log().Infof("Injecting record '%s'...", hostsEntry)
1023+
1024+
// entry in /etc/hosts
1025+
errgrp, errgrpctx := errgroup.WithContext(ctx)
10231026
for _, node := range cluster.Nodes {
1024-
if err := runtime.ExecInNode(ctx, node, []string{"sh", "-c", fmt.Sprintf("echo '%s' >> /etc/hosts", hostsEntry)}); err != nil {
1025-
return fmt.Errorf("failed to add extra entry '%s' to /etc/hosts in node '%s': %w", hostsEntry, node.Name, err)
1026-
}
1027+
n := node
1028+
errgrp.Go(func() error {
1029+
return runtime.ExecInNode(errgrpctx, n, []string{"sh", "-c", fmt.Sprintf("echo '%s' >> /etc/hosts", hostsEntry)})
1030+
})
1031+
}
1032+
if err := errgrp.Wait(); err != nil {
1033+
return fmt.Errorf("failed to add hosts entry %s: %w", hostsEntry, err)
10271034
}
10281035
l.Log().Debugf("Successfully added host record \"%s\" to /etc/hosts in all nodes", hostsEntry)
10291036

0 commit comments

Comments
 (0)