@@ -26,6 +26,8 @@ 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"
2931 fleetv1beta1 "go.goms.io/fleet/apis/placement/v1beta1"
3032 "go.goms.io/fleet/pkg/utils"
3133 "go.goms.io/fleet/pkg/utils/parallelizer"
@@ -157,6 +159,16 @@ var (
157159 MinAvailable : & minAvailable ,
158160 },
159161 }
162+
163+ svcExportTemplate = & fleetnetworkingv1alpha1.ServiceExport {
164+ ObjectMeta : metav1.ObjectMeta {
165+ Name : "test-svcExport" ,
166+ Namespace : nsName ,
167+ Annotations : map [string ]string {
168+ objectmeta .ServiceExportAnnotationWeight : "0" ,
169+ },
170+ },
171+ }
160172)
161173
162174// TestTrackDeploymentAvailability tests the trackDeploymentAvailability function.
@@ -983,6 +995,125 @@ func TestTrackInMemberClusterObjAvailabilityByGVR(t *testing.T) {
983995 }
984996}
985997
998+ func TestServiceExportAvailability (t * testing.T ) {
999+ availableValidSvcExport := svcExportTemplate .DeepCopy ()
1000+ availableValidSvcExport .Status = fleetnetworkingv1alpha1.ServiceExportStatus {
1001+ Conditions : []metav1.Condition {
1002+ {
1003+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1004+ Status : metav1 .ConditionTrue ,
1005+ Reason : "ServiceIsValid" ,
1006+ },
1007+ },
1008+ }
1009+
1010+ unavailableInvalidSvcExport := svcExportTemplate .DeepCopy ()
1011+ unavailableInvalidSvcExport .Status = fleetnetworkingv1alpha1.ServiceExportStatus {
1012+ Conditions : []metav1.Condition {
1013+ {
1014+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1015+ Status : metav1 .ConditionFalse ,
1016+ Reason : "ServiceNotFound" ,
1017+ },
1018+ },
1019+ }
1020+
1021+ availableNoConflictSvcExport := svcExportTemplate .DeepCopy ()
1022+ availableNoConflictSvcExport .Annotations ["networking.fleet.azure.com/weight" ] = "1"
1023+ availableNoConflictSvcExport .Status = fleetnetworkingv1alpha1.ServiceExportStatus {
1024+ Conditions : []metav1.Condition {
1025+ {
1026+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1027+ Status : metav1 .ConditionTrue ,
1028+ Reason : "ServiceIsValid" ,
1029+ },
1030+ {
1031+ Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1032+ Status : metav1 .ConditionFalse ,
1033+ Reason : "NoConflictFound" ,
1034+ },
1035+ },
1036+ }
1037+
1038+ unavailableHasConflictSvcExport := svcExportTemplate .DeepCopy ()
1039+ unavailableHasConflictSvcExport .Annotations ["networking.fleet.azure.com/weight" ] = "1"
1040+ unavailableHasConflictSvcExport .Status = fleetnetworkingv1alpha1.ServiceExportStatus {
1041+ Conditions : []metav1.Condition {
1042+ {
1043+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1044+ Status : metav1 .ConditionTrue ,
1045+ Reason : "ServiceIsValid" ,
1046+ },
1047+ {
1048+ Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1049+ Status : metav1 .ConditionTrue ,
1050+ Reason : "ConflictFound" ,
1051+ },
1052+ },
1053+ }
1054+
1055+ unavailableInvalidNoConflictSvcExport := svcExportTemplate .DeepCopy ()
1056+ unavailableInvalidNoConflictSvcExport .Annotations ["networking.fleet.azure.com/weight" ] = "1"
1057+ unavailableInvalidNoConflictSvcExport .Status = fleetnetworkingv1alpha1.ServiceExportStatus {
1058+ Conditions : []metav1.Condition {
1059+ {
1060+ Type : string (fleetnetworkingv1alpha1 .ServiceExportValid ),
1061+ Status : metav1 .ConditionFalse ,
1062+ Reason : "ServiceIneligible" ,
1063+ },
1064+ {
1065+ Type : string (fleetnetworkingv1alpha1 .ServiceExportConflict ),
1066+ Status : metav1 .ConditionTrue ,
1067+ Reason : "ConflictFound" ,
1068+ },
1069+ },
1070+ }
1071+
1072+ testCases := []struct {
1073+ name string
1074+ svcExport * fleetnetworkingv1alpha1.ServiceExport
1075+ wantManifestProcessingAvailabilityResultType ManifestProcessingAvailabilityResultType
1076+ }{
1077+ {
1078+ name : "available svcExport (annotation weight is 0)" ,
1079+ svcExport : availableValidSvcExport ,
1080+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1081+ },
1082+ {
1083+ name : "available svcExport (annotation weight is 1)" ,
1084+ svcExport : availableNoConflictSvcExport ,
1085+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1086+ },
1087+ {
1088+ name : "unavailable svcExport (annotation weight is 0)" ,
1089+ svcExport : unavailableInvalidSvcExport ,
1090+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1091+ },
1092+ {
1093+ name : "unavailable svcExport with conflict (annotation weight is 1)" ,
1094+ svcExport : unavailableHasConflictSvcExport ,
1095+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1096+ },
1097+ {
1098+ name : "unavailable invalid svcExport (annotation weight is 1)" ,
1099+ svcExport : unavailableInvalidNoConflictSvcExport ,
1100+ wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1101+ },
1102+ }
1103+
1104+ for _ , tc := range testCases {
1105+ t .Run (tc .name , func (t * testing.T ) {
1106+ gotResTyp , err := trackServiceExportAvailability (toUnstructured (t , tc .svcExport ))
1107+ if err != nil {
1108+ t .Fatalf ("trackServiceExportAvailability() = %v, want no error" , err )
1109+ }
1110+ if gotResTyp != tc .wantManifestProcessingAvailabilityResultType {
1111+ t .Errorf ("manifestProcessingAvailabilityResultType = %v, want %v" , gotResTyp , tc .wantManifestProcessingAvailabilityResultType )
1112+ }
1113+ })
1114+ }
1115+ }
1116+
9861117// TestTrackInMemberClusterObjAvailability tests the trackInMemberClusterObjAvailability method.
9871118func TestTrackInMemberClusterObjAvailability (t * testing.T ) {
9881119 ctx := context .Background ()
0 commit comments