@@ -26,9 +26,6 @@ import (
2626 "k8s.io/klog/v2"
2727 "k8s.io/utils/ptr"
2828
29- fleetnetworkingv1alpha1 "go.goms.io/fleet-networking/api/v1alpha1"
30- "go.goms.io/fleet-networking/pkg/common/objectmeta"
31-
3229 fleetv1beta1 "go.goms.io/fleet/apis/placement/v1beta1"
3330 "go.goms.io/fleet/pkg/utils"
3431 "go.goms.io/fleet/pkg/utils/parallelizer"
@@ -986,290 +983,6 @@ func TestTrackInMemberClusterObjAvailabilityByGVR(t *testing.T) {
986983 }
987984}
988985
989- func TestServiceExportAvailability (t * testing.T ) {
990- svcExportTemplate := & fleetnetworkingv1alpha1.ServiceExport {
991- ObjectMeta : metav1.ObjectMeta {
992- Name : "test-svcExport" ,
993- Namespace : nsName ,
994- Annotations : map [string ]string {},
995- Generation : 3 ,
996- },
997- }
998-
999- testCases := []struct {
1000- name string
1001- weight string
1002- status fleetnetworkingv1alpha1.ServiceExportStatus
1003- wantManifestProcessingAvailabilityResultType ManifestProcessingAvailabilityResultType
1004- }{
1005- {
1006- name : "available svcExport (annotation weight is 0)" ,
1007- weight : "0" ,
1008- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1009- Conditions : []metav1.Condition {
1010- {
1011- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1012- Status : metav1 .ConditionTrue ,
1013- Reason : "ServiceIsValid" ,
1014- ObservedGeneration : 3 ,
1015- },
1016- },
1017- },
1018- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1019- },
1020- {
1021- name : "unavailable svcExport (ServiceExportValid is false)" ,
1022- weight : "0" ,
1023- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1024- Conditions : []metav1.Condition {
1025- {
1026- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1027- Status : metav1 .ConditionFalse ,
1028- Reason : "ServiceNotFound" ,
1029- ObservedGeneration : 3 ,
1030- },
1031- },
1032- },
1033- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1034- },
1035- {
1036- name : "unavailable svcExport (different generation, annotation weight is 0)" ,
1037- weight : "0" ,
1038- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1039- Conditions : []metav1.Condition {
1040- {
1041- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1042- Status : metav1 .ConditionTrue ,
1043- Reason : "ServiceIsValid" ,
1044- ObservedGeneration : 2 ,
1045- },
1046- },
1047- },
1048- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1049- },
1050- {
1051- name : "available svcExport with no conflict (annotation weight is 1)" ,
1052- weight : "1" ,
1053- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1054- Conditions : []metav1.Condition {
1055- {
1056- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1057- Status : metav1 .ConditionTrue ,
1058- Reason : "ServiceIsValid" ,
1059- ObservedGeneration : 3 ,
1060- },
1061- {
1062- Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1063- Status : metav1 .ConditionFalse ,
1064- Reason : "NoConflictFound" ,
1065- ObservedGeneration : 3 ,
1066- },
1067- },
1068- },
1069- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1070- },
1071- {
1072- name : "unavailable svcExport with conflict (annotation weight is 1)" ,
1073- weight : "1" ,
1074- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1075- Conditions : []metav1.Condition {
1076- {
1077- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1078- Status : metav1 .ConditionTrue ,
1079- Reason : "ServiceIsValid" ,
1080- ObservedGeneration : 3 ,
1081- },
1082- {
1083- Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1084- Status : metav1 .ConditionTrue ,
1085- Reason : "ConflictFound" ,
1086- ObservedGeneration : 3 ,
1087- },
1088- },
1089- },
1090- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1091- },
1092- {
1093- name : "unavailable invalid svcExport (annotation weight is 1)" ,
1094- weight : "1" ,
1095- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1096- Conditions : []metav1.Condition {
1097- {
1098- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1099- Status : metav1 .ConditionFalse ,
1100- Reason : "ServiceIneligible" ,
1101- ObservedGeneration : 3 ,
1102- },
1103- },
1104- },
1105- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1106- },
1107- {
1108- name : "unavailable svcExport (different generation, annotation weight is 1)" ,
1109- weight : "1" ,
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 {
1168- Conditions : []metav1.Condition {
1169- {
1170- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1171- Status : metav1 .ConditionTrue ,
1172- Reason : "ServiceIsValid" ,
1173- ObservedGeneration : 3 ,
1174- },
1175- {
1176- Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1177- Status : metav1 .ConditionTrue ,
1178- 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" ,
1200- ObservedGeneration : 2 ,
1201- },
1202- },
1203- },
1204- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1205- },
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- },
1221- {
1222- name : "unavailable svcExport (invalid weight)" ,
1223- weight : "a" ,
1224- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1225- Conditions : []metav1.Condition {
1226- {
1227- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1228- Status : metav1 .ConditionTrue ,
1229- Reason : "ServiceIsValid" ,
1230- ObservedGeneration : 3 ,
1231- },
1232- },
1233- },
1234- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1235- },
1236- {
1237- name : "unavailable svcExport (out of range weight)" ,
1238- weight : "1002" ,
1239- status : fleetnetworkingv1alpha1.ServiceExportStatus {
1240- Conditions : []metav1.Condition {
1241- {
1242- Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1243- Status : metav1 .ConditionTrue ,
1244- Reason : "ServiceIsValid" ,
1245- ObservedGeneration : 3 ,
1246- },
1247- },
1248- },
1249- wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1250- },
1251- }
1252-
1253- for _ , tc := range testCases {
1254- t .Run (tc .name , func (t * testing.T ) {
1255- svcExport := svcExportTemplate .DeepCopy ()
1256- if tc .weight != "" {
1257- svcExport .Annotations [objectmeta .ServiceExportAnnotationWeight ] = tc .weight
1258- }
1259- svcExport .Status = tc .status
1260- gotResTyp , err := trackServiceExportAvailability (toUnstructured (t , svcExport ))
1261- if err != nil {
1262- t .Fatalf ("trackServiceExportAvailability() = %v, want no error" , err )
1263- }
1264-
1265- // Check the result type
1266- if gotResTyp != tc .wantManifestProcessingAvailabilityResultType {
1267- t .Errorf ("manifestProcessingAvailabilityResultType = %v, want %v" , gotResTyp , tc .wantManifestProcessingAvailabilityResultType )
1268- }
1269- })
1270- }
1271- }
1272-
1273986// TestTrackInMemberClusterObjAvailability tests the trackInMemberClusterObjAvailability method.
1274987func TestTrackInMemberClusterObjAvailability (t * testing.T ) {
1275988 ctx := context .Background ()
0 commit comments