Skip to content

Commit 3b1db57

Browse files
Jayendra Parsaijgwest
authored andcommitted
Error reporting in DeploymentTarget/DeploymentTargetClaim.
1 parent 0914d0a commit 3b1db57

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

appstudio-controller/controllers/appstudio.redhat.com/deploymenttarget_controller.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func (r *DeploymentTargetReconciler) findDeploymentTargetsForSpaceRequests(sr cl
379379
}
380380

381381
// updateStatusConditionOfDeploymentTarget calls SetCondition() with DeploymentTarget conditions
382-
func updateStatusConditionOfDeploymentTarget(ctx context.Context, client client.Client,
382+
func updateStatusConditionOfDeploymentTarget(ctx context.Context, k8sClient client.Client,
383383
message string, deploymentTarget *applicationv1alpha1.DeploymentTarget, conditionType string,
384384
status metav1.ConditionStatus, reason string, log logr.Logger) error {
385385

@@ -390,12 +390,19 @@ func updateStatusConditionOfDeploymentTarget(ctx context.Context, client client.
390390
Reason: reason,
391391
}
392392

393-
changed, newConditions := insertOrUpdateConditionsInSlice(newCondition, deploymentTarget.Status.Conditions)
393+
dt := deploymentTarget
394+
395+
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dt), dt); err != nil {
396+
log.Error(err, "unable to fetch deploymentTargetClaim.")
397+
return nil
398+
}
399+
400+
changed, newConditions := insertOrUpdateConditionsInSlice(newCondition, dt.Status.Conditions)
394401

395402
if changed {
396-
deploymentTarget.Status.Conditions = newConditions
403+
dt.Status.Conditions = newConditions
397404

398-
if err := client.Status().Update(ctx, deploymentTarget); err != nil {
405+
if err := k8sClient.Status().Update(ctx, dt); err != nil {
399406
log.Error(err, "unable to update deploymentTarget status condition.")
400407
return err
401408
}

appstudio-controller/controllers/appstudio.redhat.com/deploymenttargetclaim_controller.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,17 +956,19 @@ func updateStatusConditionOfDeploymentTargetClaim(ctx context.Context, k8sClient
956956
Reason: reason,
957957
}
958958

959-
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(deploymentTargetClaim), deploymentTargetClaim); err != nil {
959+
dtc := deploymentTargetClaim
960+
961+
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dtc), dtc); err != nil {
960962
log.Error(err, "unable to fetch deploymentTargetClaim.")
961963
return nil
962964
}
963965

964-
changed, newConditions := insertOrUpdateConditionsInSlice(newCondition, deploymentTargetClaim.Status.Conditions)
966+
changed, newConditions := insertOrUpdateConditionsInSlice(newCondition, dtc.Status.Conditions)
965967

966968
if changed {
967-
deploymentTargetClaim.Status.Conditions = newConditions
969+
dtc.Status.Conditions = newConditions
968970

969-
if err := k8sClient.Status().Update(ctx, deploymentTargetClaim); err != nil {
971+
if err := k8sClient.Status().Update(ctx, dtc); err != nil {
970972
log.Error(err, "unable to update deploymentTargetClaim status condition.")
971973
return err
972974
}

tests-e2e/appstudio/deploymenttargetclaim_binder_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ var _ = Describe("DeploymentTargetClaim Binding controller tests", func() {
109109

110110
Eventually(dt, "5m", "1s").Should(
111111
dtfixture.HasStatusPhase(appstudiosharedv1.DeploymentTargetPhase_Bound))
112+
113+
Eventually(dtc, "3m", "1s").Should(dtcfixture.HaveDeploymentTargetClaimCondition(
114+
metav1.Condition{
115+
Type: appstudiocontrollers.DeploymentTargetConditionTypeErrorOccurred,
116+
Message: "",
117+
Status: metav1.ConditionTrue,
118+
Reason: appstudiocontrollers.DeploymentTargetReasonBound,
119+
}))
112120
})
113121

114122
It("should handle a DTC that targets a user created DT", func() {
@@ -137,6 +145,14 @@ var _ = Describe("DeploymentTargetClaim Binding controller tests", func() {
137145
dtfixture.HasStatusPhase(appstudiosharedv1.DeploymentTargetPhase_Bound))
138146

139147
Eventually(&dt).Should(k8s.HasFinalizers([]string{appstudiocontrollers.FinalizerDT}, k8sClient))
148+
149+
Eventually(dtc, "3m", "1s").Should(dtcfixture.HaveDeploymentTargetClaimCondition(
150+
metav1.Condition{
151+
Type: appstudiocontrollers.DeploymentTargetConditionTypeErrorOccurred,
152+
Message: "",
153+
Status: metav1.ConditionTrue,
154+
Reason: appstudiocontrollers.DeploymentTargetReasonBound,
155+
}))
140156
})
141157

142158
It("should bind with a best match DT in the absence of provisioner/user created DT", func() {
@@ -204,6 +220,14 @@ var _ = Describe("DeploymentTargetClaim Binding controller tests", func() {
204220

205221
Eventually(dt, "5m", "1s").Should(
206222
dtfixture.HasStatusPhase(appstudiosharedv1.DeploymentTargetPhase_Bound))
223+
224+
Eventually(dtc, "3m", "1s").Should(dtcfixture.HaveDeploymentTargetClaimCondition(
225+
metav1.Condition{
226+
Type: appstudiocontrollers.DeploymentTargetConditionTypeErrorOccurred,
227+
Message: "",
228+
Status: metav1.ConditionTrue,
229+
Reason: appstudiocontrollers.DeploymentTargetReasonBound,
230+
}))
207231
})
208232

209233
It("should handle deletion of DTC and release binded DT", func() {

tests-e2e/fixture/deploymenttarget/fixture.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
appstudiosharedv1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
1010
"github.com/redhat-appstudio/managed-gitops/tests-e2e/fixture"
1111
k8sFixture "github.com/redhat-appstudio/managed-gitops/tests-e2e/fixture/k8s"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1213
"sigs.k8s.io/controller-runtime/pkg/client"
1314
)
1415

@@ -38,3 +39,35 @@ func HasStatusPhase(phase appstudiosharedv1.DeploymentTargetPhase) matcher.Gomeg
3839
return true
3940
}, BeTrue())
4041
}
42+
43+
func HaveDeploymentTargetCondition(expected metav1.Condition) matcher.GomegaMatcher {
44+
return WithTransform(func(dt appstudiosharedv1.DeploymentTarget) bool {
45+
46+
config, err := fixture.GetE2ETestUserWorkspaceKubeConfig()
47+
Expect(err).ToNot(HaveOccurred())
48+
49+
k8sClient, err := fixture.GetKubeClient(config)
50+
if err != nil {
51+
fmt.Println(k8sFixture.K8sClientError, err)
52+
return false
53+
}
54+
55+
err = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(&dt), &dt)
56+
if err != nil {
57+
fmt.Println(k8sFixture.K8sClientError, err)
58+
return false
59+
}
60+
61+
if len(dt.Status.Conditions) == 0 {
62+
fmt.Println("HaveDeploymentTargetCondition: DeploymentTargetClaimCondition is nil")
63+
return false
64+
}
65+
actual := dt.Status.Conditions[0]
66+
fmt.Println("HaveDeploymentTargetCondition:", "expected: ", expected, "actual: ", actual)
67+
return actual.Type == expected.Type &&
68+
actual.Status == expected.Status &&
69+
actual.Reason == expected.Reason &&
70+
actual.Message == expected.Message
71+
72+
}, BeTrue())
73+
}

0 commit comments

Comments
 (0)