Skip to content

Commit

Permalink
Log every 5 mins
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Morales committed Jan 23, 2025
1 parent 231e2a6 commit 8f5d519
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions internal/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"log"
"time"

"github.com/spf13/pflag"
k8scorev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -162,16 +163,23 @@ func (rc *Runner) WaitForVirtualMachineInstance(ctx context.Context) {
defer watch.Stop()

lastPhase := ""
lastTimeChecked := time.Now()

for event := range watch.ResultChan() {
vmi, ok := event.Object.(*v1.VirtualMachineInstance)
if ok && vmi.Name == rc.virtualMachineInstance && vmi.Status.Phase != v1.VirtualMachineInstancePhase(lastPhase) {
lastPhase = string(vmi.Status.Phase)
log.Printf("%s has transitioned to %s phase \n", rc.virtualMachineInstance, lastPhase)

switch lastPhase {
case "Succeeded", "Failed":
return
if ok && vmi.Name == rc.virtualMachineInstance {
if vmi.Status.Phase != v1.VirtualMachineInstancePhase(lastPhase) {
lastPhase = string(vmi.Status.Phase)
log.Printf("%s has transitioned to %s phase \n", rc.virtualMachineInstance, lastPhase)
lastTimeChecked = time.Now()

switch lastPhase {
case "Succeeded", "Failed":
return
}
} else if time.Since(lastTimeChecked).Minutes() > 5.0 {
log.Printf("%s is in %s phase \n", rc.virtualMachineInstance, lastPhase)
lastTimeChecked = time.Now()
}
}
}
Expand Down

0 comments on commit 8f5d519

Please sign in to comment.