Skip to content

Commit

Permalink
Merge pull request #45 from GDATASoftwareAG/reduce-some-errors
Browse files Browse the repository at this point in the history
reduce some errors
  • Loading branch information
farodin91 authored Nov 22, 2023
2 parents 4421db0 + 4ea1947 commit 0568cf0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions internal/controller/ionoscloudmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var defaultMachineRetryIntervalOnBusy = time.Second * 30

// IONOSCloudMachineReconciler reconciles a IONOSCloudMachine object
type IONOSCloudMachineReconciler struct {
*context.ControllerContext
Expand Down Expand Up @@ -391,7 +393,8 @@ func (r *IONOSCloudMachineReconciler) reconcileServer(ctx *context.MachineContex
}

if resp.StatusCode == http.StatusNotFound || (server.Metadata != nil && *server.Metadata.State == STATE_BUSY) {
return &reconcile.Result{RequeueAfter: defaultRetryIntervalOnBusy}, errors.New("server not yet created")
ctx.Logger.Info("server not yet created")
return &reconcile.Result{RequeueAfter: defaultMachineRetryIntervalOnBusy}, nil
}
ipObtained := false
nics := *server.Entities.Nics.Items
Expand All @@ -411,16 +414,18 @@ func (r *IONOSCloudMachineReconciler) reconcileServer(ctx *context.MachineContex
}

if !ipObtained {
return &reconcile.Result{RequeueAfter: defaultRetryIntervalOnBusy}, errors.New("server does not have an ip yet")
ctx.Logger.Info("server does not have an ip yet")
return &reconcile.Result{RequeueAfter: defaultMachineRetryIntervalOnBusy}, nil
}

conditions.MarkTrue(ctx.IONOSCloudMachine, v1alpha1.ServerCreatedCondition)

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

conditions.MarkTrue(ctx.IONOSCloudMachine, v1alpha1.ServerCreatedCondition)

return nil, nil
}

Expand All @@ -440,13 +445,13 @@ func (r *IONOSCloudMachineReconciler) reconcileFailoverGroups(ctx *context.Machi
return err
}
ips := *block.Properties.Ips
err = ctx.IONOSClient.EnsureAdditionalIPsOnNic(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, ctx.IONOSCloudMachine.Spec.ProviderID, *serverNic.Id, ips)
//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
}
//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)
err = ctx.IONOSClient.EnsureAdditionalIPsOnNic(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, ctx.IONOSCloudMachine.Spec.ProviderID, *serverNic.Id, ips)
if err != nil {
return err
}
Expand Down

0 comments on commit 0568cf0

Please sign in to comment.