Skip to content

[DO-NOT-MERGE] Add some debug logs to verify deletion #1625

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions controllers/hcloudmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type HCloudMachineReconciler struct {
// Reconcile manages the lifecycle of an HCloud machine object.
func (r *HCloudMachineReconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, reterr error) {
log := ctrl.LoggerFrom(ctx)

log.V(1).Info("Start reconciling HCloudMachine")
// Fetch the HCloudMachine instance.
hcloudMachine := &infrav1.HCloudMachine{}
err := r.Get(ctx, req.NamespacedName, hcloudMachine)
Expand Down Expand Up @@ -165,9 +165,11 @@ func (r *HCloudMachineReconciler) Reconcile(ctx context.Context, req reconcile.R
}

if !hcloudMachine.ObjectMeta.DeletionTimestamp.IsZero() {
log.V(1).Info("Reconciling HCloudMachine - delete")
return r.reconcileDelete(ctx, machineScope)
}

log.V(1).Info("Reconciling HCloudMachine - normal")
return r.reconcileNormal(ctx, machineScope)
}

Expand Down Expand Up @@ -468,11 +470,14 @@ func IgnoreInsignificantHCloudMachineStatusUpdates(logger logr.Logger) predicate
return false
}

log.V(1).Info("HCloudMachine event")
log.V(1).Info("HCloudMachine update event received")
return true
},
CreateFunc: func(_ event.CreateEvent) bool { return true },
DeleteFunc: func(_ event.DeleteEvent) bool {
logger.V(1).Info("HCloudMachine delete event received")
return true
},
CreateFunc: func(_ event.CreateEvent) bool { return true },
DeleteFunc: func(_ event.DeleteEvent) bool { return true },
GenericFunc: func(_ event.GenericEvent) bool { return true },
}
}
13 changes: 13 additions & 0 deletions pkg/services/hcloud/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ func (s *Service) Delete(ctx context.Context) (res reconcile.Result, err error)
return res, nil
}

s.scope.V(1).Info("HcloudMachine reconcile delete - server found")

// control planes have to be deleted as targets of server
if s.scope.IsControlPlane() && s.scope.HetznerCluster.Spec.ControlPlaneLoadBalancer.Enabled {
for _, target := range s.scope.HetznerCluster.Status.ControlPlaneLoadBalancer.Target {
Expand All @@ -235,6 +237,8 @@ func (s *Service) Delete(ctx context.Context) (res reconcile.Result, err error)
}
}

s.scope.V(1).Info("HcloudMachine reconcile delete", "server status", server.Status)

// first shut the server down, then delete it
switch server.Status {
case hcloud.ServerStatusRunning:
Expand All @@ -243,6 +247,7 @@ func (s *Service) Delete(ctx context.Context) (res reconcile.Result, err error)
return s.handleDeleteServerStatusOff(ctx, server)
}

s.scope.V(1).Info("Requeue for five seconds - unknown state")
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil
}

Expand Down Expand Up @@ -621,6 +626,7 @@ func (s *Service) handleDeleteServerStatusRunning(ctx context.Context, server *h
// Shut down the server if one of the two conditions apply:
// 1. The server has not yet been tried to shut down and still is marked as "ready".
// 2. The server has been tried to shut down without an effect and the timeout is not reached yet.
s.scope.V(1).Info("Handle server status running")

if s.scope.HasServerAvailableCondition() {
if err := s.scope.HCloudClient.ShutdownServer(ctx, server); err != nil {
Expand All @@ -634,26 +640,33 @@ func (s *Service) handleDeleteServerStatusRunning(ctx context.Context, server *h
"Instance has been shut down",
)

s.scope.V(1).Info("Shut down server - requeue for 30 seconds")
return reconcile.Result{RequeueAfter: 30 * time.Second}, nil
}

s.scope.V(1).Info("Delete server")

// timeout for shutdown has been reached - delete server
if err := s.scope.HCloudClient.DeleteServer(ctx, server); err != nil {
record.Warnf(s.scope.HCloudMachine, "FailedDeleteHCloudServer", "Failed to delete HCloud server %s", s.scope.Name())
return reconcile.Result{}, handleRateLimit(s.scope.HCloudMachine, err, "DeleteServer", "failed to delete server")
}

s.scope.V(1).Info("Server deleted")
record.Eventf(s.scope.HCloudMachine, "HCloudServerDeleted", "HCloud server %s deleted", s.scope.Name())
return res, nil
}

func (s *Service) handleDeleteServerStatusOff(ctx context.Context, server *hcloud.Server) (res reconcile.Result, err error) {
// server is off and can be deleted
s.scope.V(1).Info("Handle server status off")

if err := s.scope.HCloudClient.DeleteServer(ctx, server); err != nil {
record.Warnf(s.scope.HCloudMachine, "FailedDeleteHCloudServer", "Failed to delete HCloud server %s", s.scope.Name())
return reconcile.Result{}, handleRateLimit(s.scope.HCloudMachine, err, "DeleteServer", "failed to delete server")
}

s.scope.V(1).Info("Server deleted after server status off")
record.Eventf(s.scope.HCloudMachine, "HCloudServerDeleted", "HCloud server %s deleted", s.scope.Name())
return res, nil
}
Expand Down
Loading