From 2586f130db1ca7e5f232a0a63af1e0a921ed1cea Mon Sep 17 00:00:00 2001 From: Bella Khizgiyaev Date: Sun, 3 Dec 2023 23:57:15 +0200 Subject: [PATCH] Add new phases for OVA provider creation Signed-off-by: Bella Khizgiyaev --- pkg/controller/provider/controller.go | 45 ++++++++++++++++++++++++--- pkg/controller/provider/validation.go | 10 +++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/pkg/controller/provider/controller.go b/pkg/controller/provider/controller.go index 3178e11f3..8e0218df6 100644 --- a/pkg/controller/provider/controller.go +++ b/pkg/controller/provider/controller.go @@ -22,6 +22,7 @@ import ( "os" "path/filepath" "sync" + "time" api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1" "github.com/konveyor/forklift-controller/pkg/controller/base" @@ -52,7 +53,8 @@ import ( const ( // Name. - Name = "provider" + Name = "provider" + OvaTimeout = 10 ) // Package logger. @@ -196,11 +198,46 @@ func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (r deployment) // If the deployment does not exist - if k8serr.IsNotFound(err) { - r.CreateOVAServerDeployment(provider, ctx) - } else if err != nil { + if err != nil { + if k8serr.IsNotFound(err) { + r.CreateOVAServerDeployment(provider, ctx) + provider.Status.Phase = initializing + provider.Status.SetCondition( + libcnd.Condition{ + Type: initializing, + Status: True, + Category: Required, + Message: "The OVA server being inizialized.", + }) + err = r.Status().Update(context.TODO(), provider.DeepCopy()) + if err != nil { + return + } + result.RequeueAfter = 5 * time.Second + return + } return } + + // The ova server pod is not running yet + if deployment.Status.AvailableReplicas == 0 { + if time.Since(provider.CreationTimestamp.Time).Minutes() <= OvaTimeout { + result.RequeueAfter = 5 * time.Second + return + } else { + // Timeout reached + provider.Status.Phase = ServerCreationFailed + provider.Status.SetCondition( + libcnd.Condition{ + Type: ServerCreationFailed, + Status: True, + Category: Critical, + Message: "The OVA provider server creation failed.", + }) + err = r.Status().Update(context.TODO(), provider.DeepCopy()) + return + } + } } // Begin staging conditions. diff --git a/pkg/controller/provider/validation.go b/pkg/controller/provider/validation.go index 655658513..9588828dc 100644 --- a/pkg/controller/provider/validation.go +++ b/pkg/controller/provider/validation.go @@ -58,10 +58,12 @@ const ( // Phases const ( - ValidationFailed = "ValidationFailed" - ConnectionFailed = "ConnectionFailed" - Ready = "Ready" - Staging = "Staging" + ValidationFailed = "ValidationFailed" + ConnectionFailed = "ConnectionFailed" + Ready = "Ready" + Staging = "Staging" + initializing = "initializing" + ServerCreationFailed = "ServerCreationFailed" ) // Statuses