From 7c18ec915ca6ea7176f11a015f5945982b967949 Mon Sep 17 00:00:00 2001 From: Mat Kowalski Date: Thu, 11 Dec 2025 18:40:37 +0100 Subject: [PATCH] monitortest: fix empty value for machine phase I have discovered that at times it happens that I see `Machine is in ""` in the reported intervals. This is not correct and may be caused by the fact that phase is defined as an optional `Phase *string json:"phase,omitempty"` field so technically an empty value is correct one there. In any case, for constructing interval I would prefer to explicitly see "missing" message instead of empty value. --- pkg/monitortests/machines/watchmachines/machines.go | 4 ++-- pkg/monitortests/machines/watchmachines/monitortest.go | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/monitortests/machines/watchmachines/machines.go b/pkg/monitortests/machines/watchmachines/machines.go index 35fe2235084e..7a67ce075190 100644 --- a/pkg/monitortests/machines/watchmachines/machines.go +++ b/pkg/monitortests/machines/watchmachines/machines.go @@ -41,10 +41,10 @@ func startMachineMonitoring(ctx context.Context, m monitorapi.RecorderWriter, cl newHasPhase := machine != nil && machine.Status.Phase != nil oldPhase := "" newPhase := "" - if oldHasPhase { + if oldHasPhase && *oldMachine.Status.Phase != "" { oldPhase = *oldMachine.Status.Phase } - if newHasPhase { + if newHasPhase && *machine.Status.Phase != "" { newPhase = *machine.Status.Phase } diff --git a/pkg/monitortests/machines/watchmachines/monitortest.go b/pkg/monitortests/machines/watchmachines/monitortest.go index e6ca1adc9e66..1d1a5b9f4592 100644 --- a/pkg/monitortests/machines/watchmachines/monitortest.go +++ b/pkg/monitortests/machines/watchmachines/monitortest.go @@ -3,9 +3,10 @@ package watchmachines import ( "context" "fmt" - machineClient "github.com/openshift/client-go/machine/clientset/versioned" "time" + machineClient "github.com/openshift/client-go/machine/clientset/versioned" + "github.com/openshift/origin/pkg/monitortestframework" "github.com/openshift/origin/pkg/monitor/monitorapi" @@ -72,16 +73,16 @@ func (*machineWatcher) ConstructComputedIntervals(ctx context.Context, startingI return eventInterval.Message.Reason == monitorapi.MachinePhaseChanged }) for _, phaseChange := range phaseChanges { - previousPhase := phaseChange.Message.Annotations[monitorapi.AnnotationPreviousPhase] + newPhase := phaseChange.Message.Annotations[monitorapi.AnnotationPhase] nodeName := phaseChange.Message.Annotations[monitorapi.AnnotationNode] constructedIntervals = append(constructedIntervals, monitorapi.NewInterval(monitorapi.SourceMachine, monitorapi.Info). Locator(phaseChange.Locator). Message(monitorapi.NewMessage().Reason(monitorapi.MachinePhase). Constructed(monitorapi.ConstructionOwnerMachineLifecycle). - WithAnnotation(monitorapi.AnnotationPhase, previousPhase). + WithAnnotation(monitorapi.AnnotationPhase, newPhase). WithAnnotation(monitorapi.AnnotationNode, nodeName). - HumanMessage(fmt.Sprintf("Machine is in %q", previousPhase))). + HumanMessage(fmt.Sprintf("Machine is in %q", newPhase))). Display(). Build(previousChangeTime, phaseChange.From), )