@@ -26,7 +26,7 @@ import (
26
26
)
27
27
28
28
var _ = Describe ("SnapshotEnvironmentBinding Reconciler E2E tests" , func () {
29
-
29
+ const ErrorOccurred = "ErrorOccurred"
30
30
Context ("Testing SnapshotEnvironmentBinding Reconciler." , func () {
31
31
32
32
var environment appstudiosharedv1.Environment
@@ -1043,6 +1043,141 @@ var _ = Describe("SnapshotEnvironmentBinding Reconciler E2E tests", func() {
1043
1043
Expect (err ).ToNot (HaveOccurred ())
1044
1044
Eventually (gitopsDeployment , "2m" , "10s" ).ShouldNot (gitopsDeplFixture .HaveLabel ("appstudio.openshift.io" , "testing-update" ))
1045
1045
})
1046
+
1047
+ It ("test BindingConditions when GitOpsRepoConditions status is false" , func () {
1048
+ By ("Create SnapshotEnvironmentBindingResource" )
1049
+ binding := buildSnapshotEnvironmentBindingResource ("appa-staging-binding" , "new-demo-app" , "staging" , "my-snapshot" , 3 , []string {"component-a" })
1050
+ err = k8s .Create (& binding , k8sClient )
1051
+ Expect (err ).To (Succeed ())
1052
+
1053
+ By ("Update GitOpsRepoConditions" )
1054
+ binding .Status = appstudiosharedv1.SnapshotEnvironmentBindingStatus {
1055
+ GitOpsRepoConditions : []metav1.Condition {
1056
+ {
1057
+ Type : "GitOpsRepoNotReady" ,
1058
+ Status : metav1 .ConditionFalse ,
1059
+ Reason : "GitOpsRepoNotReady" ,
1060
+ Message : "Cannot Reconcile Binding '" + binding .Name + "', since GitOps Repo Conditions status is false." ,
1061
+ LastTransitionTime : metav1 .Now (),
1062
+ },
1063
+ },
1064
+ }
1065
+
1066
+ // Update the status field
1067
+ err = buildAndUpdateBindingStatusConditions (binding .Status , & binding )
1068
+ Expect (err ).To (Succeed ())
1069
+
1070
+ Eventually (binding , "3m" , "1s" ).Should (bindingFixture .HaveBindingConditions (
1071
+ metav1.Condition {
1072
+ Type : ErrorOccurred ,
1073
+ Status : metav1 .ConditionTrue ,
1074
+ Reason : ErrorOccurred ,
1075
+ Message : "Cannot Reconcile Binding '" + binding .Name + "', since GitOps Repo Conditions status is false." ,
1076
+ }))
1077
+
1078
+ })
1079
+
1080
+ It ("test BindingConditions when GitOpsRepoConditions status is true" , func () {
1081
+ By ("Create SnapshotEnvironmentBindingResource" )
1082
+ binding := buildSnapshotEnvironmentBindingResource ("appa-staging-binding" , "new-demo-app" , "staging" , "my-snapshot" , 3 , []string {"component-a" })
1083
+ err = k8s .Create (& binding , k8sClient )
1084
+ Expect (err ).To (Succeed ())
1085
+
1086
+ By ("Update GitOpsRepoConditions" )
1087
+ binding .Status = appstudiosharedv1.SnapshotEnvironmentBindingStatus {
1088
+ GitOpsRepoConditions : []metav1.Condition {
1089
+ {
1090
+ Type : "Reconciled" ,
1091
+ Status : metav1 .ConditionTrue ,
1092
+ Reason : "Reconciled" ,
1093
+ Message : "" ,
1094
+ LastTransitionTime : metav1 .Now (),
1095
+ },
1096
+ },
1097
+ }
1098
+
1099
+ // Update the status field
1100
+ err = buildAndUpdateBindingStatusConditions (binding .Status , & binding )
1101
+ Expect (err ).To (Succeed ())
1102
+
1103
+ Eventually (binding , "3m" , "1s" ).Should (bindingFixture .HaveBindingConditions (
1104
+ metav1.Condition {
1105
+ Type : ErrorOccurred ,
1106
+ Status : metav1 .ConditionFalse ,
1107
+ Reason : ErrorOccurred ,
1108
+ Message : "" ,
1109
+ }))
1110
+
1111
+ })
1112
+
1113
+ It ("test BindingConditions when Components is empty" , func () {
1114
+ By ("Create SnapshotEnvironmentBindingResource" )
1115
+ binding := buildSnapshotEnvironmentBindingResource ("appa-staging-binding" , "new-demo-app" , "staging" , "my-snapshot" , 3 , []string {"component-a" })
1116
+ err = k8s .Create (& binding , k8sClient )
1117
+ Expect (err ).To (Succeed ())
1118
+
1119
+ Eventually (binding , "3m" , "1s" ).Should (bindingFixture .HaveBindingConditions (
1120
+ metav1.Condition {
1121
+ Type : ErrorOccurred ,
1122
+ Status : metav1 .ConditionTrue ,
1123
+ Reason : ErrorOccurred ,
1124
+ Message : "SnapshotEventBinding Component status is required to " +
1125
+ "generate GitOps deployment, waiting for the Application Service controller to finish reconciling binding '" + binding .Name + "'" ,
1126
+ LastTransitionTime : metav1 .Now (),
1127
+ }))
1128
+
1129
+ })
1130
+
1131
+ It ("test BindingConditions when duplicate component keys are found" , func () {
1132
+ By ("Create SnapshotEnvironmentBindingResource" )
1133
+ binding := buildSnapshotEnvironmentBindingResource ("appa-staging-binding" , "new-demo-app" , "staging" , "my-snapshot" , 3 , []string {"component-a" , "component-a" })
1134
+
1135
+ err = k8s .Create (& binding , k8sClient )
1136
+ Expect (err ).To (Succeed ())
1137
+
1138
+ // Update Status field
1139
+ err = buildAndUpdateBindingStatus (binding .Spec .Components ,
1140
+ fixture .RepoURL , "main" , "adcda66" ,
1141
+ []string {"resources/test-data/component-based-gitops-repository/components/componentA/overlays/dev" , "resources/test-data/component-based-gitops-repository/components/componentB/overlays/dev" }, & binding )
1142
+ Expect (err ).To (Succeed ())
1143
+
1144
+ Eventually (binding , "3m" , "1s" ).Should (bindingFixture .HaveBindingConditions (
1145
+ metav1.Condition {
1146
+ Type : ErrorOccurred ,
1147
+ Status : metav1 .ConditionTrue ,
1148
+ Reason : ErrorOccurred ,
1149
+ Message : "duplicate component keys found in status field in component-a" ,
1150
+ }))
1151
+
1152
+ })
1153
+
1154
+ It ("test BindingConditions for userDev error where DTC referenced by Environment does not exist" , func () {
1155
+ By ("Create SnapshotEnvironmentBindingResource" )
1156
+ err = k8sClient .Get (context .Background (), client .ObjectKeyFromObject (& environment ), & environment )
1157
+ environment .Spec .Configuration .Target .DeploymentTargetClaim .ClaimName = "dtc-doesnt-exist"
1158
+
1159
+ err = k8s .Update (& environment , k8sClient )
1160
+ Expect (err ).To (Succeed ())
1161
+
1162
+ binding := buildSnapshotEnvironmentBindingResource ("appa-staging-binding" , "new-demo-app" , environment .Name , "my-snapshot" , 3 , []string {"component-a" , "component-b" })
1163
+
1164
+ err = k8s .Create (& binding , k8sClient )
1165
+ Expect (err ).To (Succeed ())
1166
+
1167
+ // Update Status field
1168
+ err = buildAndUpdateBindingStatus (binding .Spec .Components ,
1169
+ fixture .RepoURL , "main" , "adcda66" ,
1170
+ []string {"resources/test-data/component-based-gitops-repository/components/componentA/overlays/dev" , "resources/test-data/component-based-gitops-repository/components/componentB/overlays/dev" }, & binding )
1171
+ Expect (err ).To (Succeed ())
1172
+
1173
+ Eventually (binding , "3m" , "1s" ).Should (bindingFixture .HaveBindingConditions (
1174
+ metav1.Condition {
1175
+ Type : ErrorOccurred ,
1176
+ Status : metav1 .ConditionTrue ,
1177
+ Reason : ErrorOccurred ,
1178
+ Message : "DeploymentTargetClaim referenced by Environment does not exist." ,
1179
+ }))
1180
+ })
1046
1181
})
1047
1182
1048
1183
})
@@ -1062,6 +1197,18 @@ func buildAndUpdateBindingStatus(components []appstudiosharedv1.BindingComponent
1062
1197
})
1063
1198
}
1064
1199
1200
+ func buildAndUpdateBindingStatusConditions (status appstudiosharedv1.SnapshotEnvironmentBindingStatus , binding * appstudiosharedv1.SnapshotEnvironmentBinding ) error {
1201
+
1202
+ By ("updating Status field of SnapshotEnvironmentBindingResource" )
1203
+
1204
+ return bindingFixture .UpdateStatusWithFunction (binding , func (bindingStatus * appstudiosharedv1.SnapshotEnvironmentBindingStatus ) {
1205
+
1206
+ // Update the binding status
1207
+ * bindingStatus = status
1208
+
1209
+ })
1210
+ }
1211
+
1065
1212
// buildSnapshotEnvironmentBindingResource builds the SnapshotEnvironmentBinding CR
1066
1213
func buildSnapshotEnvironmentBindingResource (name , appName , envName , snapshotName string , replica int , componentNames []string ) appstudiosharedv1.SnapshotEnvironmentBinding {
1067
1214
// Create SnapshotEnvironmentBinding CR.
0 commit comments