Skip to content

Commit

Permalink
An app is staged when it has current droplet set
Browse files Browse the repository at this point in the history
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 <georgethebeatle@gmail.com>
  • Loading branch information
danail-branekov and georgethebeatle committed Jan 7, 2025
1 parent 84ae579 commit ebf3242
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 40 deletions.
3 changes: 1 addition & 2 deletions api/repositories/app_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
43 changes: 5 additions & 38 deletions api/repositories/app_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -109,51 +108,19 @@ 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{
"space": app.SpaceGUID,
}))
})

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() {
Expand Down

0 comments on commit ebf3242

Please sign in to comment.