diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index c51c8515..b2788b06 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -29,6 +29,7 @@ import ( "strings" "time" + "github.com/imdario/mergo" k3drt "github.com/rancher/k3d/pkg/runtimes" "github.com/rancher/k3d/pkg/types" k3d "github.com/rancher/k3d/pkg/types" @@ -460,7 +461,22 @@ func GetCluster(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Cluster // append nodes for _, node := range nodes { - cluster.Nodes = append(cluster.Nodes, node) + + // check if there's already a node in the struct + overwroteExisting := false + for _, existingNode := range cluster.Nodes { + + // overwrite existing node + if existingNode.Name == node.Name { + mergo.MergeWithOverwrite(existingNode, node) + overwroteExisting = true + } + } + + // no existing node overwritten: append new node + if !overwroteExisting { + cluster.Nodes = append(cluster.Nodes, node) + } } if err := populateClusterFieldsFromLabels(cluster); err != nil { diff --git a/pkg/cluster/loadbalancer.go b/pkg/cluster/loadbalancer.go index aa670308..38c9fdb4 100644 --- a/pkg/cluster/loadbalancer.go +++ b/pkg/cluster/loadbalancer.go @@ -61,7 +61,10 @@ func UpdateLoadbalancerConfig(ctx context.Context, runtime runtimes.Runtime, clu command := fmt.Sprintf("SERVERS=%s %s", masterNodes, "confd -onetime -backend env && nginx -s reload") if err := runtime.ExecInNode(ctx, loadbalancer, []string{"sh", "-c", command}); err != nil { - log.Errorln("Failed to update loadbalancer configuration") + if strings.Contains(err.Error(), "host not found in upstream") { + log.Warnf("Loadbalancer configuration updated, but one or more k3d nodes seem to be down, check the logs:\n%s", err.Error()) + return nil + } return err }