From ff4d08a0595a7c436faace38b02bbc7c95a7fda1 Mon Sep 17 00:00:00 2001 From: Danail Branekov Date: Tue, 7 Jan 2025 15:49:49 +0000 Subject: [PATCH] An app is staged when it has current droplet set Checking for the ready condition on the app to determine whether the app is staged does not make sense as during an app restart, the app becomes unready (but remains staged as it references a valid droplet) Co-authored-by: Georgi Sabev --- api/repositories/app_repository.go | 3 +- api/repositories/app_repository_test.go | 43 +++---------------------- 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/api/repositories/app_repository.go b/api/repositories/app_repository.go index fee36d561..feb5d223e 100644 --- a/api/repositories/app_repository.go +++ b/api/repositories/app_repository.go @@ -22,7 +22,6 @@ import ( "github.com/BooleanCat/go-functional/v2/it/itx" "github.com/google/uuid" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -670,7 +669,7 @@ func cfAppToAppRecord(cfApp korifiv1alpha1.CFApp) AppRecord { CreatedAt: cfApp.CreationTimestamp.Time, UpdatedAt: getLastUpdatedTime(&cfApp), DeletedAt: golangTime(cfApp.DeletionTimestamp), - IsStaged: meta.IsStatusConditionTrue(cfApp.Status.Conditions, korifiv1alpha1.StatusConditionReady), + IsStaged: cfApp.Spec.CurrentDropletRef.Name != "", envSecretName: cfApp.Spec.EnvSecretName, vcapServiceSecretName: cfApp.Status.VCAPServicesSecretName, vcapAppSecretName: cfApp.Status.VCAPApplicationSecretName, diff --git a/api/repositories/app_repository_test.go b/api/repositories/app_repository_test.go index 2e8c061d1..e3455e1a6 100644 --- a/api/repositories/app_repository_test.go +++ b/api/repositories/app_repository_test.go @@ -23,7 +23,6 @@ import ( . "github.com/onsi/gomega/gstruct" gomega_types "github.com/onsi/gomega/types" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -109,7 +108,7 @@ var _ = Describe("AppRepository", func() { Stack: cfApp.Spec.Lifecycle.Data.Stack, }, })) - Expect(app.IsStaged).To(BeFalse()) + Expect(app.IsStaged).To(BeTrue()) Expect(app.DeletedAt).To(BeNil()) Expect(app.Relationships()).To(Equal(map[string]string{ @@ -117,43 +116,11 @@ var _ = Describe("AppRepository", func() { })) }) - When("the app has staged condition true", func() { + When("the app has no current droplet set", func() { BeforeEach(func() { - cfApp.Status.Conditions = []metav1.Condition{{ - Type: korifiv1alpha1.StatusConditionReady, - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: "staged", - Message: "staged", - }} - Expect(k8sClient.Status().Update(ctx, cfApp)).To(Succeed()) - Eventually(func(g Gomega) { - app := korifiv1alpha1.CFApp{} - g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(cfApp), &app)).To(Succeed()) - g.Expect(app.Status.Conditions).NotTo(BeEmpty()) - }).Should(Succeed()) - }) - - It("sets IsStaged to true", func() { - Expect(getErr).ToNot(HaveOccurred()) - Expect(app.IsStaged).To(BeTrue()) - }) - }) - - When("the app has staged condition false", func() { - BeforeEach(func() { - meta.SetStatusCondition(&cfApp.Status.Conditions, metav1.Condition{ - Type: korifiv1alpha1.StatusConditionReady, - Status: metav1.ConditionFalse, - Reason: "appStaged", - Message: "", - }) - Expect(k8sClient.Status().Update(ctx, cfApp)).To(Succeed()) - Eventually(func(g Gomega) { - app := korifiv1alpha1.CFApp{} - g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(cfApp), &app)).To(Succeed()) - g.Expect(meta.IsStatusConditionFalse(app.Status.Conditions, korifiv1alpha1.StatusConditionReady)).To(BeTrue()) - }).Should(Succeed()) + Expect(k8s.PatchResource(ctx, k8sClient, cfApp, func() { + cfApp.Spec.CurrentDropletRef.Name = "" + })).To(Succeed()) }) It("sets IsStaged to false", func() {