@@ -92,22 +92,22 @@ func internalServiceExportReconciler(client client.Client) *Reconciler {
9292 }
9393}
9494
95- func unconflictedServiceExportConflictCondition (svcNamespace string , svcName string ) metav1.Condition {
95+ func unconflictedServiceExportConflictCondition (svcNamespace string , svcName string , observedGeneration int64 ) metav1.Condition {
9696 return metav1.Condition {
9797 Type : string (fleetnetv1alpha1 .ServiceExportConflict ),
9898 Status : metav1 .ConditionFalse ,
99- ObservedGeneration : 0 ,
99+ ObservedGeneration : observedGeneration ,
100100 LastTransitionTime : metav1 .Now (),
101101 Reason : conditionReasonNoConflictFound ,
102102 Message : fmt .Sprintf ("service %s/%s is exported without conflict" , svcNamespace , svcName ),
103103 }
104104}
105105
106- func conflictedServiceExportConflictCondition (svcNamespace string , svcName string ) metav1.Condition {
106+ func conflictedServiceExportConflictCondition (svcNamespace string , svcName string , observedGeneration int64 ) metav1.Condition {
107107 return metav1.Condition {
108108 Type : string (fleetnetv1alpha1 .ServiceExportConflict ),
109109 Status : metav1 .ConditionTrue ,
110- ObservedGeneration : 0 ,
110+ ObservedGeneration : observedGeneration ,
111111 LastTransitionTime : metav1 .Now (),
112112 Reason : conditionReasonConflictFound ,
113113 Message : fmt .Sprintf ("service %s/%s is in conflict with other exported services" , svcNamespace , svcName ),
@@ -370,6 +370,7 @@ func TestHandleDelete_EmptyServiceImportSpec(t *testing.T) {
370370}
371371
372372func TestHandleUpdate (t * testing.T ) {
373+ internalServiceExportGeneration := int64 (456 )
373374 importServicePorts := []fleetnetv1alpha1.ServicePort {
374375 {
375376 Name : "portA" ,
@@ -397,8 +398,9 @@ func TestHandleUpdate(t *testing.T) {
397398 name : "no serviceImport exists" ,
398399 internalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
399400 ObjectMeta : metav1.ObjectMeta {
400- Name : testName ,
401- Namespace : testMemberNamespace ,
401+ Name : testName ,
402+ Namespace : testMemberNamespace ,
403+ Generation : internalServiceExportGeneration ,
402404 },
403405 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
404406 Ports : []fleetnetv1alpha1.ServicePort {
@@ -430,8 +432,9 @@ func TestHandleUpdate(t *testing.T) {
430432 want : ctrl.Result {RequeueAfter : internalserviceexportRetryInterval },
431433 wantInternalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
432434 ObjectMeta : metav1.ObjectMeta {
433- Name : testName ,
434- Namespace : testMemberNamespace ,
435+ Name : testName ,
436+ Namespace : testMemberNamespace ,
437+ Generation : internalServiceExportGeneration ,
435438 },
436439 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
437440 Ports : []fleetnetv1alpha1.ServicePort {
@@ -471,8 +474,9 @@ func TestHandleUpdate(t *testing.T) {
471474 name : "serviceExport just created and has the same spec as serviceImport" ,
472475 internalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
473476 ObjectMeta : metav1.ObjectMeta {
474- Name : testName ,
475- Namespace : testMemberNamespace ,
477+ Name : testName ,
478+ Namespace : testMemberNamespace ,
479+ Generation : internalServiceExportGeneration ,
476480 },
477481 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
478482 Ports : importServicePorts ,
@@ -505,8 +509,9 @@ func TestHandleUpdate(t *testing.T) {
505509 want : ctrl.Result {},
506510 wantInternalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
507511 ObjectMeta : metav1.ObjectMeta {
508- Name : testName ,
509- Namespace : testMemberNamespace ,
512+ Name : testName ,
513+ Namespace : testMemberNamespace ,
514+ Generation : internalServiceExportGeneration ,
510515 },
511516 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
512517 Ports : importServicePorts ,
@@ -522,7 +527,7 @@ func TestHandleUpdate(t *testing.T) {
522527 },
523528 Status : fleetnetv1alpha1.InternalServiceExportStatus {
524529 Conditions : []metav1.Condition {
525- unconflictedServiceExportConflictCondition (testNamespace , testServiceName ),
530+ unconflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
526531 },
527532 },
528533 },
@@ -549,8 +554,9 @@ func TestHandleUpdate(t *testing.T) {
549554 name : "serviceExport just created and has the different spec as serviceImport" ,
550555 internalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
551556 ObjectMeta : metav1.ObjectMeta {
552- Name : testName ,
553- Namespace : testMemberNamespace ,
557+ Name : testName ,
558+ Namespace : testMemberNamespace ,
559+ Generation : internalServiceExportGeneration ,
554560 },
555561 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
556562 Ports : []fleetnetv1alpha1.ServicePort {
@@ -591,8 +597,9 @@ func TestHandleUpdate(t *testing.T) {
591597 want : ctrl.Result {},
592598 wantInternalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
593599 ObjectMeta : metav1.ObjectMeta {
594- Name : testName ,
595- Namespace : testMemberNamespace ,
600+ Name : testName ,
601+ Namespace : testMemberNamespace ,
602+ Generation : internalServiceExportGeneration ,
596603 },
597604 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
598605 Ports : []fleetnetv1alpha1.ServicePort {
@@ -616,7 +623,7 @@ func TestHandleUpdate(t *testing.T) {
616623 },
617624 Status : fleetnetv1alpha1.InternalServiceExportStatus {
618625 Conditions : []metav1.Condition {
619- conflictedServiceExportConflictCondition (testNamespace , testServiceName ),
626+ conflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
620627 },
621628 },
622629 },
@@ -640,8 +647,9 @@ func TestHandleUpdate(t *testing.T) {
640647 name : "update serviceExport and old serviceExport has the same spec as serviceImport" ,
641648 internalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
642649 ObjectMeta : metav1.ObjectMeta {
643- Name : testName ,
644- Namespace : testMemberNamespace ,
650+ Name : testName ,
651+ Namespace : testMemberNamespace ,
652+ Generation : internalServiceExportGeneration ,
645653 },
646654 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
647655 Ports : []fleetnetv1alpha1.ServicePort {
@@ -665,7 +673,7 @@ func TestHandleUpdate(t *testing.T) {
665673 },
666674 Status : fleetnetv1alpha1.InternalServiceExportStatus {
667675 Conditions : []metav1.Condition {
668- unconflictedServiceExportConflictCondition (testNamespace , testServiceName ),
676+ unconflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
669677 },
670678 },
671679 },
@@ -690,8 +698,9 @@ func TestHandleUpdate(t *testing.T) {
690698 want : ctrl.Result {},
691699 wantInternalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
692700 ObjectMeta : metav1.ObjectMeta {
693- Name : testName ,
694- Namespace : testMemberNamespace ,
701+ Name : testName ,
702+ Namespace : testMemberNamespace ,
703+ Generation : internalServiceExportGeneration ,
695704 },
696705 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
697706 Ports : []fleetnetv1alpha1.ServicePort {
@@ -715,7 +724,7 @@ func TestHandleUpdate(t *testing.T) {
715724 },
716725 Status : fleetnetv1alpha1.InternalServiceExportStatus {
717726 Conditions : []metav1.Condition {
718- conflictedServiceExportConflictCondition (testNamespace , testServiceName ),
727+ conflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
719728 },
720729 },
721730 },
@@ -739,8 +748,9 @@ func TestHandleUpdate(t *testing.T) {
739748 name : "update serviceExport and old serviceExport has the different spec as serviceImport" ,
740749 internalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
741750 ObjectMeta : metav1.ObjectMeta {
742- Name : testName ,
743- Namespace : testMemberNamespace ,
751+ Name : testName ,
752+ Namespace : testMemberNamespace ,
753+ Generation : internalServiceExportGeneration ,
744754 },
745755 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
746756 Ports : importServicePorts ,
@@ -756,7 +766,7 @@ func TestHandleUpdate(t *testing.T) {
756766 },
757767 Status : fleetnetv1alpha1.InternalServiceExportStatus {
758768 Conditions : []metav1.Condition {
759- conflictedServiceExportConflictCondition (testNamespace , testServiceName ),
769+ conflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
760770 },
761771 },
762772 },
@@ -778,8 +788,9 @@ func TestHandleUpdate(t *testing.T) {
778788 want : ctrl.Result {},
779789 wantInternalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
780790 ObjectMeta : metav1.ObjectMeta {
781- Name : testName ,
782- Namespace : testMemberNamespace ,
791+ Name : testName ,
792+ Namespace : testMemberNamespace ,
793+ Generation : internalServiceExportGeneration ,
783794 },
784795 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
785796 Ports : importServicePorts ,
@@ -795,7 +806,7 @@ func TestHandleUpdate(t *testing.T) {
795806 },
796807 Status : fleetnetv1alpha1.InternalServiceExportStatus {
797808 Conditions : []metav1.Condition {
798- unconflictedServiceExportConflictCondition (testNamespace , testServiceName ),
809+ unconflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
799810 },
800811 },
801812 },
@@ -822,8 +833,9 @@ func TestHandleUpdate(t *testing.T) {
822833 name : "there is only one serviceExport and port spec has been changed" ,
823834 internalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
824835 ObjectMeta : metav1.ObjectMeta {
825- Name : testName ,
826- Namespace : testMemberNamespace ,
836+ Name : testName ,
837+ Namespace : testMemberNamespace ,
838+ Generation : internalServiceExportGeneration ,
827839 },
828840 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
829841 Ports : []fleetnetv1alpha1.ServicePort {
@@ -847,7 +859,7 @@ func TestHandleUpdate(t *testing.T) {
847859 },
848860 Status : fleetnetv1alpha1.InternalServiceExportStatus {
849861 Conditions : []metav1.Condition {
850- unconflictedServiceExportConflictCondition (testNamespace , testServiceName ),
862+ unconflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
851863 },
852864 },
853865 },
@@ -869,8 +881,9 @@ func TestHandleUpdate(t *testing.T) {
869881 want : ctrl.Result {RequeueAfter : internalserviceexportRetryInterval },
870882 wantInternalSvcExport : & fleetnetv1alpha1.InternalServiceExport {
871883 ObjectMeta : metav1.ObjectMeta {
872- Name : testName ,
873- Namespace : testMemberNamespace ,
884+ Name : testName ,
885+ Namespace : testMemberNamespace ,
886+ Generation : internalServiceExportGeneration ,
874887 },
875888 Spec : fleetnetv1alpha1.InternalServiceExportSpec {
876889 Ports : []fleetnetv1alpha1.ServicePort {
@@ -894,7 +907,7 @@ func TestHandleUpdate(t *testing.T) {
894907 },
895908 Status : fleetnetv1alpha1.InternalServiceExportStatus {
896909 Conditions : []metav1.Condition {
897- unconflictedServiceExportConflictCondition (testNamespace , testServiceName ),
910+ unconflictedServiceExportConflictCondition (testNamespace , testServiceName , internalServiceExportGeneration ),
898911 },
899912 },
900913 },
@@ -928,7 +941,7 @@ func TestHandleUpdate(t *testing.T) {
928941 }
929942 want := tc .want
930943 if ! cmp .Equal (got , want ) {
931- t .Errorf ("handleDelete () = %+v, want %+v" , got , want )
944+ t .Errorf ("handleUpdate () = %+v, want %+v" , got , want )
932945 }
933946 options := []cmp.Option {
934947 cmpopts .IgnoreFields (metav1.ObjectMeta {}, "ResourceVersion" ),
0 commit comments