UpdateLoadbalancerConfig: deduplicate and warn if node is down
- getCluster: now deduplicates the node list (i.e. overwrites existing nodes in the list with "fresh" nodes and appends new ones) - UpdateLoadbalancerConfig: print warning if "host not found in upstream" returned by nginx after updating the config, as it's not a failure per se, but shouldn't be ignored
This commit is contained in:
parent
f0d3389a1f
commit
b28f93d207
@ -29,6 +29,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/imdario/mergo"
|
||||||
k3drt "github.com/rancher/k3d/pkg/runtimes"
|
k3drt "github.com/rancher/k3d/pkg/runtimes"
|
||||||
"github.com/rancher/k3d/pkg/types"
|
"github.com/rancher/k3d/pkg/types"
|
||||||
k3d "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
|
// append nodes
|
||||||
for _, node := range 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 {
|
if err := populateClusterFieldsFromLabels(cluster); err != nil {
|
||||||
|
@ -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")
|
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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user