Skip to content

Commit

Permalink
Merge pull request #46 from GDATASoftwareAG/improve-error-handling-fa…
Browse files Browse the repository at this point in the history
…iloverGroup

improve error handling failoverGroup
  • Loading branch information
farodin91 authored Nov 22, 2023
2 parents 0568cf0 + 79deff7 commit 1208e39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/controller/ionoscloudmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
goctx "context"
b64 "encoding/base64"
"fmt"
"go.uber.org/multierr"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -422,14 +423,15 @@ func (r *IONOSCloudMachineReconciler) reconcileServer(ctx *context.MachineContex

err = r.reconcileFailoverGroups(ctx, server)
if err != nil {
ctx.Logger.Info("failoverGroup not yet correct assigned", "err", err.Error())
ctx.Logger.Error(err, "failoverGroup not yet correct assigned")
return &reconcile.Result{RequeueAfter: defaultMachineRetryIntervalOnBusy}, nil
}

return nil, nil
}

func (r *IONOSCloudMachineReconciler) reconcileFailoverGroups(ctx *context.MachineContext, server ionoscloud.Server) error {
var errors error
for i := range ctx.IONOSCloudCluster.Spec.Lans {
lanSpec := &ctx.IONOSCloudCluster.Spec.Lans[i]
serverNic := serverNicByLan(server, lanSpec)
Expand All @@ -439,25 +441,25 @@ func (r *IONOSCloudMachineReconciler) reconcileFailoverGroups(ctx *context.Machi
for k := range lanSpec.FailoverGroups {
group := &lanSpec.FailoverGroups[k]
ctx.Logger.Info("Reconciling failover group " + group.ID)

block, _, err := ctx.IONOSClient.GetIPBlock(ctx, group.ID)
if err != nil {
return err
errors = multierr.Append(errors, err)
continue
}
ips := *block.Properties.Ips
err = ctx.IONOSClient.EnsureAdditionalIPsOnNic(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, ctx.IONOSCloudMachine.Spec.ProviderID, *serverNic.Id, ips)
if err != nil {
errors = multierr.Append(errors, err)
}
//TODO: only once per cluster and change if machine gets delete
lanId := fmt.Sprint(*lanSpec.LanID)
err = ctx.IONOSClient.EnsureFailoverIPsOnLan(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, lanId, *serverNic.Id, ips)
if err != nil {
return err
}
err = ctx.IONOSClient.EnsureAdditionalIPsOnNic(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, ctx.IONOSCloudMachine.Spec.ProviderID, *serverNic.Id, ips)
if err != nil {
return err
errors = multierr.Append(errors, err)
}
}
}
return nil
return errors
}

func (r *IONOSCloudMachineReconciler) reconcileLoadBalancerForwardingRule(ctx *context.MachineContext) (*reconcile.Result, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/ionos/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (c *APIClient) EnsureFailoverIPsOnLan(ctx context.Context, datacenterId, la
})
}
}
fmt.Printf("requireRegister %t, failovers %d", requireRegister, len(failovers))
if !requireRegister {
return nil
}
Expand Down

0 comments on commit 1208e39

Please sign in to comment.