Skip to content

Commit

Permalink
Use the ready condition builder in relevant controllers
Browse files Browse the repository at this point in the history
Korifi custom resources that have their `Ready` condition set by
controllers now utilise the ready condition builder pattern we recently
came up with. The afffected resources are:

* CFPackage
* CFOrg
* CFSpace
* CFProcess
* AppWorkload

While being here, take the opportunity to slightly improve their tests

fixes #3237

wip

* Address added TODOs

wip
  • Loading branch information
danail-branekov committed May 27, 2024
1 parent bb95278 commit a45820d
Show file tree
Hide file tree
Showing 25 changed files with 459 additions and 507 deletions.
7 changes: 4 additions & 3 deletions api/repositories/buildpack_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

. "code.cloudfoundry.org/korifi/api/repositories"
"code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -96,7 +97,7 @@ var _ = Describe("BuildpackRepository", func() {
When("there is a ready condition with a message", func() {
BeforeEach(func() {
meta.SetStatusCondition(&builderInfo.Status.Conditions, metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionFalse,
Reason: "testing",
Message: "this is a test",
Expand All @@ -113,7 +114,7 @@ var _ = Describe("BuildpackRepository", func() {
When("there is a ready condition with an empty message", func() {
BeforeEach(func() {
meta.SetStatusCondition(&builderInfo.Status.Conditions, metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionFalse,
Reason: "testing",
Message: "",
Expand Down Expand Up @@ -168,7 +169,7 @@ func createBuilderInfoWithCleanup(ctx context.Context, name, stack string, build
}

meta.SetStatusCondition(&builderInfo.Status.Conditions, metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionTrue,
Reason: "testing",
})
Expand Down
6 changes: 3 additions & 3 deletions api/repositories/org_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var _ = Describe("OrgRepository", func() {
Expect(k8s.Patch(ctx, k8sClient, cfOrg, func() {
cfOrg.Status.GUID = cfOrg.Name
meta.SetStatusCondition(&cfOrg.Status.Conditions, metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: conditionStatus,
Reason: "blah",
Message: conditionMessage,
Expand Down Expand Up @@ -199,15 +199,15 @@ var _ = Describe("OrgRepository", func() {
When("the org is not ready", func() {
BeforeEach(func() {
meta.SetStatusCondition(&(cfOrg1.Status.Conditions), metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionFalse,
Reason: "because",
Message: "because",
})
Expect(k8sClient.Status().Update(ctx, cfOrg1)).To(Succeed())

meta.SetStatusCondition(&(cfOrg2.Status.Conditions), metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionUnknown,
Reason: "because",
Message: "because",
Expand Down
8 changes: 4 additions & 4 deletions api/repositories/package_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ var _ = Describe("PackageRepository", func() {
BeforeEach(func() {
Expect(k8s.Patch(ctx, k8sClient, cfPackage, func() {
meta.SetStatusCondition(&cfPackage.Status.Conditions, metav1.Condition{
Type: "Ready",
Status: "True",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionTrue,
Reason: "Ready",
ObservedGeneration: cfPackage.Generation,
})
Expand Down Expand Up @@ -507,8 +507,8 @@ var _ = Describe("PackageRepository", func() {
Expect(k8sClient.Create(ctx, cfPackage)).To(Succeed())
Expect(k8s.Patch(ctx, k8sClient, cfPackage, func() {
meta.SetStatusCondition(&cfPackage.Status.Conditions, metav1.Condition{
Type: "Ready",
Status: "True",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionTrue,
Reason: "Ready",
ObservedGeneration: cfPackage.Generation,
})
Expand Down
4 changes: 2 additions & 2 deletions api/repositories/repositories_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func createOrgWithCleanup(ctx context.Context, displayName string) *korifiv1alph
Expect(k8sClient.Create(ctx, cfOrg)).To(Succeed())

meta.SetStatusCondition(&(cfOrg.Status.Conditions), metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionTrue,
Reason: "cus",
Message: "cus",
Expand Down Expand Up @@ -191,7 +191,7 @@ func createSpaceWithCleanup(ctx context.Context, orgGUID, name string) *korifiv1

cfSpace.Status.GUID = cfSpace.Name
meta.SetStatusCondition(&(cfSpace.Status.Conditions), metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionTrue,
Reason: "cus",
Message: "cus",
Expand Down
4 changes: 2 additions & 2 deletions api/repositories/space_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var _ = Describe("SpaceRepository", func() {
Expect(k8s.Patch(ctx, k8sClient, cfSpace, func() {
cfSpace.Status.GUID = cfSpace.Name
meta.SetStatusCondition(&cfSpace.Status.Conditions, metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: conditionStatus,
Reason: "blah",
Message: conditionMessage,
Expand Down Expand Up @@ -227,7 +227,7 @@ var _ = Describe("SpaceRepository", func() {
When("the space anchor is not ready", func() {
BeforeEach(func() {
meta.SetStatusCondition(&(space11.Status.Conditions), metav1.Condition{
Type: "Ready",
Type: korifiv1alpha1.StatusConditionReady,
Status: metav1.ConditionFalse,
Reason: "cus",
Message: "cus",
Expand Down
Loading

0 comments on commit a45820d

Please sign in to comment.