@@ -28,6 +28,7 @@ import (
2828
2929 fleetnetworkingv1alpha1 "go.goms.io/fleet-networking/api/v1alpha1"
3030 "go.goms.io/fleet-networking/pkg/common/objectmeta"
31+
3132 fleetv1beta1 "go.goms.io/fleet/apis/placement/v1beta1"
3233 "go.goms.io/fleet/pkg/utils"
3334 "go.goms.io/fleet/pkg/utils/parallelizer"
@@ -988,25 +989,23 @@ func TestTrackInMemberClusterObjAvailabilityByGVR(t *testing.T) {
988989func TestServiceExportAvailability (t * testing.T ) {
989990 svcExportTemplate := & fleetnetworkingv1alpha1.ServiceExport {
990991 ObjectMeta : metav1.ObjectMeta {
991- Name : "test-svcExport" ,
992- Namespace : nsName ,
993- Annotations : map [string ]string {
994- objectmeta .ServiceExportAnnotationWeight : "0" ,
995- },
996- Generation : 3 ,
992+ Name : "test-svcExport" ,
993+ Namespace : nsName ,
994+ Annotations : map [string ]string {},
995+ Generation : 3 ,
997996 },
998997 }
999998
1000999 testCases := []struct {
10011000 name string
10021001 weight string
1003- status * fleetnetworkingv1alpha1.ServiceExportStatus
1002+ status fleetnetworkingv1alpha1.ServiceExportStatus
10041003 wantManifestProcessingAvailabilityResultType ManifestProcessingAvailabilityResultType
10051004 }{
10061005 {
10071006 name : "available svcExport (annotation weight is 0)" ,
10081007 weight : "0" ,
1009- status : & fleetnetworkingv1alpha1.ServiceExportStatus {
1008+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
10101009 Conditions : []metav1.Condition {
10111010 {
10121011 Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
@@ -1021,7 +1020,7 @@ func TestServiceExportAvailability(t *testing.T) {
10211020 {
10221021 name : "unavailable svcExport (ServiceExportValid is false)" ,
10231022 weight : "0" ,
1024- status : & fleetnetworkingv1alpha1.ServiceExportStatus {
1023+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
10251024 Conditions : []metav1.Condition {
10261025 {
10271026 Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
@@ -1036,7 +1035,7 @@ func TestServiceExportAvailability(t *testing.T) {
10361035 {
10371036 name : "unavailable svcExport (different generation, annotation weight is 0)" ,
10381037 weight : "0" ,
1039- status : & fleetnetworkingv1alpha1.ServiceExportStatus {
1038+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
10401039 Conditions : []metav1.Condition {
10411040 {
10421041 Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
@@ -1051,7 +1050,7 @@ func TestServiceExportAvailability(t *testing.T) {
10511050 {
10521051 name : "available svcExport with no conflict (annotation weight is 1)" ,
10531052 weight : "1" ,
1054- status : & fleetnetworkingv1alpha1.ServiceExportStatus {
1053+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
10551054 Conditions : []metav1.Condition {
10561055 {
10571056 Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
@@ -1072,7 +1071,7 @@ func TestServiceExportAvailability(t *testing.T) {
10721071 {
10731072 name : "unavailable svcExport with conflict (annotation weight is 1)" ,
10741073 weight : "1" ,
1075- status : & fleetnetworkingv1alpha1.ServiceExportStatus {
1074+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
10761075 Conditions : []metav1.Condition {
10771076 {
10781077 Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
@@ -1093,12 +1092,13 @@ func TestServiceExportAvailability(t *testing.T) {
10931092 {
10941093 name : "unavailable invalid svcExport (annotation weight is 1)" ,
10951094 weight : "1" ,
1096- status : & fleetnetworkingv1alpha1.ServiceExportStatus {
1095+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
10971096 Conditions : []metav1.Condition {
10981097 {
1099- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1100- Status : metav1 .ConditionFalse ,
1101- Reason : "ServiceIneligible" ,
1098+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1099+ Status : metav1 .ConditionFalse ,
1100+ Reason : "ServiceIneligible" ,
1101+ ObservedGeneration : 3 ,
11021102 },
11031103 },
11041104 },
@@ -1107,7 +1107,64 @@ func TestServiceExportAvailability(t *testing.T) {
11071107 {
11081108 name : "unavailable svcExport (different generation, annotation weight is 1)" ,
11091109 weight : "1" ,
1110- status : & fleetnetworkingv1alpha1.ServiceExportStatus {
1110+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
1111+ Conditions : []metav1.Condition {
1112+ {
1113+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1114+ Status : metav1 .ConditionTrue ,
1115+ Reason : "ServiceIsValid" ,
1116+ ObservedGeneration : 3 ,
1117+ },
1118+ {
1119+ Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1120+ Status : metav1 .ConditionTrue ,
1121+ Reason : "ConflictFound" ,
1122+ ObservedGeneration : 2 ,
1123+ },
1124+ },
1125+ },
1126+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1127+ },
1128+ {
1129+ name : "unavailable svcExport (no annotation weight, no conflict condition)" ,
1130+ weight : "" ,
1131+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
1132+ Conditions : []metav1.Condition {
1133+ {
1134+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1135+ Status : metav1 .ConditionTrue ,
1136+ Reason : "ServiceIsValid" ,
1137+ ObservedGeneration : 3 ,
1138+ },
1139+ },
1140+ },
1141+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1142+ },
1143+ {
1144+ name : "available svcExport (no annotation weight)" ,
1145+ weight : "" ,
1146+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
1147+ Conditions : []metav1.Condition {
1148+ {
1149+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1150+ Status : metav1 .ConditionTrue ,
1151+ Reason : "ServiceIsValid" ,
1152+ ObservedGeneration : 3 ,
1153+ },
1154+ {
1155+ Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1156+ Status : metav1 .ConditionFalse ,
1157+ Reason : "NoConflictFound" ,
1158+ ObservedGeneration : 3 ,
1159+ },
1160+ },
1161+ },
1162+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1163+ },
1164+ {
1165+ name : "unavailable svcExport (no annotation weight with conflict)" ,
1166+ weight : "" ,
1167+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
11111168 Conditions : []metav1.Condition {
11121169 {
11131170 Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
@@ -1119,19 +1176,57 @@ func TestServiceExportAvailability(t *testing.T) {
11191176 Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
11201177 Status : metav1 .ConditionTrue ,
11211178 Reason : "ConflictFound" ,
1179+ ObservedGeneration : 3 ,
1180+ },
1181+ },
1182+ },
1183+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1184+ },
1185+ {
1186+ name : "unavailable svcExport (no annotation weight, different generation)" ,
1187+ weight : "" ,
1188+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
1189+ Conditions : []metav1.Condition {
1190+ {
1191+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1192+ Status : metav1 .ConditionTrue ,
1193+ Reason : "ServiceIsValid" ,
1194+ ObservedGeneration : 3 ,
1195+ },
1196+ {
1197+ Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1198+ Status : metav1 .ConditionFalse ,
1199+ Reason : "NoConflictFound" ,
11221200 ObservedGeneration : 2 ,
11231201 },
11241202 },
11251203 },
11261204 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
11271205 },
1206+ {
1207+ name : "unavailable svcExport (no annotation weight, invalid service export)" ,
1208+ weight : "" ,
1209+ status : fleetnetworkingv1alpha1.ServiceExportStatus {
1210+ Conditions : []metav1.Condition {
1211+ {
1212+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1213+ Status : metav1 .ConditionFalse ,
1214+ Reason : "ServiceIsNotValid" ,
1215+ ObservedGeneration : 3 ,
1216+ },
1217+ },
1218+ },
1219+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1220+ },
11281221 }
11291222
11301223 for _ , tc := range testCases {
11311224 t .Run (tc .name , func (t * testing.T ) {
11321225 svcExport := svcExportTemplate .DeepCopy ()
1133- svcExport .Annotations [objectmeta .ServiceExportAnnotationWeight ] = tc .weight
1134- svcExport .Status = * tc .status
1226+ if tc .weight != "" {
1227+ svcExport .Annotations [objectmeta .ServiceExportAnnotationWeight ] = tc .weight
1228+ }
1229+ svcExport .Status = tc .status
11351230 gotResTyp , err := trackServiceExportAvailability (toUnstructured (t , svcExport ))
11361231 if err != nil {
11371232 t .Fatalf ("trackServiceExportAvailability() = %v, want no error" , err )
0 commit comments