Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: serverlb should be created before using and restarted unless stopped #948

Merged
merged 4 commits into from
Jan 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,13 @@ ClusterCreatOpts:
if !clusterCreateOpts.DisableLoadBalancer {
if cluster.ServerLoadBalancer == nil {
l.Log().Infof("No loadbalancer specified, creating a default one...")
lbNode, err := LoadbalancerPrepare(ctx, runtime, cluster, &k3d.LoadbalancerCreateOpts{Labels: clusterCreateOpts.GlobalLabels})
cluster.ServerLoadBalancer = k3d.NewLoadbalancer()
var err error
cluster.ServerLoadBalancer.Node, err = LoadbalancerPrepare(ctx, runtime, cluster, &k3d.LoadbalancerCreateOpts{Labels: clusterCreateOpts.GlobalLabels})
if err != nil {
return fmt.Errorf("failed to prepare loadbalancer: %w", err)
}
cluster.Nodes = append(cluster.Nodes, lbNode) // append lbNode to list of cluster nodes, so it will be considered during rollback
cluster.Nodes = append(cluster.Nodes, cluster.ServerLoadBalancer.Node) // append lbNode to list of cluster nodes, so it will be considered during rollback
}

if len(cluster.ServerLoadBalancer.Config.Ports) == 0 {
Expand All @@ -525,8 +527,6 @@ ClusterCreatOpts:
cluster.ServerLoadBalancer.Config = &lbConfig
}

cluster.ServerLoadBalancer.Node.RuntimeLabels = clusterCreateOpts.GlobalLabels

// prepare to write config to lb container
configyaml, err := yaml.Marshal(cluster.ServerLoadBalancer.Config)
if err != nil {
Expand All @@ -545,6 +545,7 @@ ClusterCreatOpts:
}

cluster.ServerLoadBalancer.Node.HookActions = append(cluster.ServerLoadBalancer.Node.HookActions, writeLbConfigAction)
cluster.ServerLoadBalancer.Node.Restart = true

l.Log().Infof("Creating LoadBalancer '%s'", cluster.ServerLoadBalancer.Node.Name)
if err := NodeCreate(ctx, runtime, cluster.ServerLoadBalancer.Node, k3d.NodeCreateOpts{}); err != nil {
Expand Down