From f3bd1e6e948512d073e1b3c9aed24c073c202b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Gerrit=20G=C3=B6bel?= Date: Thu, 23 Jan 2025 10:27:53 +0100 Subject: [PATCH 1/3] Fix VM Execution Comparison --- v3/services/terraformsvc/internal/controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/v3/services/terraformsvc/internal/controller.go b/v3/services/terraformsvc/internal/controller.go index 1a7977d7..2c2fe045 100644 --- a/v3/services/terraformsvc/internal/controller.go +++ b/v3/services/terraformsvc/internal/controller.go @@ -395,17 +395,17 @@ func (v *VMController) handleProvision(vm *vmpb.VM) (error, bool) { tfExecs := tfExecsList.GetExecutions() - var newestTimestamp int32 + var newestTimestamp time.Time var tfExec *terraformpb.Execution if len(tfExecs) == 0 { return fmt.Errorf("no executions found for terraform state"), true } - newestTimestamp = tfExecs[0].GetCreationTimestamp().GetNanos() + newestTimestamp = tfExecs[0].GetCreationTimestamp().AsTime() tfExec = tfExecs[0] for _, e := range tfExecs { - if newestTimestamp < e.GetCreationTimestamp().GetNanos() { - newestTimestamp = e.GetCreationTimestamp().GetNanos() + if newestTimestamp.Before(e.GetCreationTimestamp().AsTime()) { + newestTimestamp = e.GetCreationTimestamp().AsTime() tfExec = e } } From dc59c8a67cffd7153bbd066f450fd3326369a404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Gerrit=20G=C3=B6bel?= Date: Thu, 23 Jan 2025 12:19:27 +0100 Subject: [PATCH 2/3] Take the execution with the valid output --- .../terraformsvc/internal/controller.go | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/v3/services/terraformsvc/internal/controller.go b/v3/services/terraformsvc/internal/controller.go index 2c2fe045..82743c11 100644 --- a/v3/services/terraformsvc/internal/controller.go +++ b/v3/services/terraformsvc/internal/controller.go @@ -395,34 +395,21 @@ func (v *VMController) handleProvision(vm *vmpb.VM) (error, bool) { tfExecs := tfExecsList.GetExecutions() - var newestTimestamp time.Time var tfExec *terraformpb.Execution if len(tfExecs) == 0 { return fmt.Errorf("no executions found for terraform state"), true } - newestTimestamp = tfExecs[0].GetCreationTimestamp().AsTime() + hasValidExec := false tfExec = tfExecs[0] for _, e := range tfExecs { - if newestTimestamp.Before(e.GetCreationTimestamp().AsTime()) { - newestTimestamp = e.GetCreationTimestamp().AsTime() + if e.GetStatus().GetOutputs() != "" { tfExec = e + hasValidExec = true } } - // END TEMPORARY WORKAROUND - - //executionName := tfState.Status.ExecutionName - /* - tfExec, err := t.tfeLister.Executions(util.GetReleaseNamespace()).Get(executionName) - if err != nil { - //glog.Error(err) - if apierrors.IsNotFound(err) { - return fmt.Errorf("execution not found") - } - return nil - } - */ - if tfExec.GetStatus().GetOutputs() == "" { + + if !hasValidExec { return nil, true } From 3b4258f39217a88408edbb989aa3965a28d9d113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Gerrit=20G=C3=B6bel?= Date: Thu, 23 Jan 2025 12:20:37 +0100 Subject: [PATCH 3/3] remove comment about workaround --- v3/services/terraformsvc/internal/controller.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/v3/services/terraformsvc/internal/controller.go b/v3/services/terraformsvc/internal/controller.go index 82743c11..a0b78d69 100644 --- a/v3/services/terraformsvc/internal/controller.go +++ b/v3/services/terraformsvc/internal/controller.go @@ -370,16 +370,6 @@ func (v *VMController) handleProvision(vm *vmpb.VM) (error, bool) { return nil, false } else if vm.Status.Status == string(hfv1.VmStatusProvisioned) { - // let's check the status of our tf provision - /*tfState, err := t.tfsLister.States(util.GetReleaseNamespace()).Get(vm.Status.TFState) - if err != nil { - if apierrors.IsNotFound(err) { - return fmt.Errorf("execution not found") - } - return nil - } */ - // TEMPORARY WORKAROUND UNTIL WE FIGURE OUT A BETTER WAY TO DO THIS - if vm.GetStatus().GetTfstate() == "" { return fmt.Errorf("tf state was blank in object"), true }