Skip to content

Commit

Permalink
Ensure VCAP_SERVICES are in deterministic order and fix flakey tests
Browse files Browse the repository at this point in the history
[Issue #462]

Co-authored-by: Matt Royal <mroyal@vmware.com>
Co-authored-by: Akira Wong <wakira@vmware.com>
  • Loading branch information
matt-royal and gnovv committed Jan 27, 2022
1 parent 2d5888a commit 79b96ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 7 additions & 1 deletion controllers/controllers/workloads/cfprocess_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

workloadsv1alpha1 "code.cloudfoundry.org/cf-k8s-controllers/controllers/apis/workloads/v1alpha1"
eiriniv1 "code.cloudfoundry.org/eirini-controller/pkg/apis/eirini/v1"

workloadsv1alpha1 "code.cloudfoundry.org/cf-k8s-controllers/controllers/apis/workloads/v1alpha1"
)

// CFProcessReconciler reconciles a CFProcess object
Expand Down Expand Up @@ -422,6 +423,11 @@ func servicesToVCAPValue(services []serviceInfo) (string, error) {
UserProvided: make([]serviceDetails, 0, len(services)),
}

// Ensure that the order is deterministic
sort.Slice(services, func(i, j int) bool {
return services[i].binding.Name < services[j].binding.Name
})

for _, service := range services {
var serviceName string
var bindingName *string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() {
k8sClient.Create(ctx, cfApp),
).To(Succeed())
})

It("eventually reconciles to set owner references on CFProcess", func() {
Eventually(func() []metav1.OwnerReference {
var createdCFProcess workloadsv1alpha1.CFProcess
Expand All @@ -121,7 +122,7 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() {
})

When("the CFApp desired state is STARTED", func() {
BeforeEach(func() {
JustBeforeEach(func() {
ctx := context.Background()
cfApp.Spec.DesiredState = workloadsv1alpha1.StartedState
Expect(
Expand Down Expand Up @@ -179,7 +180,7 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() {
})

When("a CFApp desired state is updated to STOPPED", func() {
BeforeEach(func() {
JustBeforeEach(func() {
ctx := context.Background()

// Wait for LRP to exist before updating CFApp
Expand Down Expand Up @@ -374,7 +375,11 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() {
}

return nil
}, 5*time.Second).Should(HaveKeyWithValue("VCAP_SERVICES", Not(Equal("{}"))), fmt.Sprintf("Timed out waiting for LRP/%s in namespace %s to get VCAP_SERVICES env vars", testProcessGUID, testNamespace))
}, 5*time.Second).Should(
HaveKeyWithValue("VCAP_SERVICES",
SatisfyAll(ContainSubstring(serviceBinding1.Spec.Name), ContainSubstring(serviceBinding2.Spec.Name)),
), fmt.Sprintf("Timed out waiting for LRP/%s in namespace %s to get VCAP_SERVICES env vars", testProcessGUID, testNamespace))

Expect(lrp.Spec.Env["VCAP_SERVICES"]).To(MatchJSON(fmt.Sprintf(`{
"user-provided":[
{
Expand Down

0 comments on commit 79b96ef

Please sign in to comment.