Skip to content

Commit c7d5efe

Browse files
committed
fix the generation
1 parent 05e20d8 commit c7d5efe

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

pkg/common/condition/condition.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ func UnconflictedServiceExportConflictCondition(internalServiceExport fleetnetv1
7373
Name: internalServiceExport.Spec.ServiceReference.Name,
7474
}
7575
return metav1.Condition{
76-
Type: string(fleetnetv1alpha1.ServiceExportConflict),
77-
Status: metav1.ConditionFalse,
78-
Reason: conditionReasonNoConflictFound,
76+
Type: string(fleetnetv1alpha1.ServiceExportConflict),
77+
Status: metav1.ConditionFalse,
78+
Reason: conditionReasonNoConflictFound,
79+
// Right now, it becomes very tricky because we need to consider both serviceExport generation & service generation.
80+
// The service can be updated without updating the serviceExport.
81+
// However, service controller does not populate the generation on the spec.
82+
// use the internalServiceExport generation? any service & weight annotation changes will update the internalServiceExport generation.
7983
ObservedGeneration: internalServiceExport.Spec.ServiceReference.Generation, // use the generation of the original object
8084
Message: fmt.Sprintf("service %s is exported without conflict", svcName),
8185
}

pkg/controllers/member/internalserviceexport/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (r *Reconciler) reportBackConflictCondition(ctx context.Context,
179179
klog.V(4).InfoS("No conflict condition to report back", "internalServiceExport", internalSvcExportRef)
180180
return false, nil
181181
}
182-
182+
internalSvcExportConflictCond.ObservedGeneration = svcExport.Generation // use the generation of the original object
183183
svcExportConflictCond := meta.FindStatusCondition(svcExport.Status.Conditions, string(fleetnetv1alpha1.ServiceExportConflict))
184184
if reflect.DeepEqual(internalSvcExportConflictCond, svcExportConflictCond) {
185185
// The conflict condition has not changed and there is no need to report back; this is also an expected

pkg/controllers/member/serviceexport/controller.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
164164
}
165165
// Mark the ServiceExport as invalid.
166166
klog.V(2).InfoS("Mark service export as invalid (service ineligible)", "service", svcRef)
167-
err = r.markServiceExportAsInvalidSvcIneligible(ctx, &svcExport, &svc)
167+
err = r.markServiceExportAsInvalidSvcIneligible(ctx, &svcExport)
168168
if err != nil {
169169
klog.ErrorS(err, "Failed to mark service export as invalid (service ineligible)", "service", svcRef)
170170
}
@@ -234,7 +234,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
234234

235235
// Mark the ServiceExport as valid.
236236
klog.V(2).InfoS("Mark service export as valid", "service", svcRef)
237-
if err = r.markServiceExportAsValid(ctx, &svcExport, &svc); err != nil {
237+
if err = r.markServiceExportAsValid(ctx, &svcExport); err != nil {
238238
klog.ErrorS(err, "Failed to mark service export as valid", "service", svcRef)
239239
return ctrl.Result{}, err
240240
}
@@ -478,11 +478,11 @@ func (r *Reconciler) removeServiceExportCleanupFinalizer(ctx context.Context, sv
478478
func (r *Reconciler) markServiceExportAsInvalidNotFound(ctx context.Context, svcExport *fleetnetv1alpha1.ServiceExport) error {
479479
validCond := meta.FindStatusCondition(svcExport.Status.Conditions, string(fleetnetv1alpha1.ServiceExportValid))
480480
expectedValidCond := &metav1.Condition{
481-
Type: string(fleetnetv1alpha1.ServiceExportValid),
482-
Status: metav1.ConditionFalse,
483-
// The Service is not found, therefore the observedGeneration field is ignored.
484-
Reason: svcExportInvalidNotFoundCondReason,
485-
Message: fmt.Sprintf("service %s/%s is not found", svcExport.Namespace, svcExport.Name),
481+
Type: string(fleetnetv1alpha1.ServiceExportValid),
482+
Status: metav1.ConditionFalse,
483+
Reason: svcExportInvalidNotFoundCondReason,
484+
ObservedGeneration: svcExport.Generation,
485+
Message: fmt.Sprintf("service %s/%s is not found", svcExport.Namespace, svcExport.Name),
486486
}
487487
if condition.EqualCondition(validCond, expectedValidCond) {
488488
// A stable state has been reached; no further action is needed.
@@ -494,13 +494,13 @@ func (r *Reconciler) markServiceExportAsInvalidNotFound(ctx context.Context, svc
494494
}
495495

496496
// markServiceExportAsInvalidSvcIneligible marks a ServiceExport as invalid.
497-
func (r *Reconciler) markServiceExportAsInvalidSvcIneligible(ctx context.Context, svcExport *fleetnetv1alpha1.ServiceExport, svc *corev1.Service) error {
497+
func (r *Reconciler) markServiceExportAsInvalidSvcIneligible(ctx context.Context, svcExport *fleetnetv1alpha1.ServiceExport) error {
498498
validCond := meta.FindStatusCondition(svcExport.Status.Conditions, string(fleetnetv1alpha1.ServiceExportValid))
499499
expectedValidCond := &metav1.Condition{
500500
Type: string(fleetnetv1alpha1.ServiceExportValid),
501501
Status: metav1.ConditionFalse,
502502
Reason: svcExportInvalidIneligibleCondReason,
503-
ObservedGeneration: svc.Generation,
503+
ObservedGeneration: svcExport.Generation,
504504
Message: fmt.Sprintf("service %s/%s is not eligible for export", svcExport.Namespace, svcExport.Name),
505505
}
506506
if condition.EqualCondition(validCond, expectedValidCond) {
@@ -520,13 +520,13 @@ func (r *Reconciler) addServiceExportCleanupFinalizer(ctx context.Context, svcEx
520520

521521
// markServiceExportAsValid marks a ServiceExport as valid; if no conflict condition has been added, the
522522
// ServiceExport will be marked as pending conflict resolution as well.
523-
func (r *Reconciler) markServiceExportAsValid(ctx context.Context, svcExport *fleetnetv1alpha1.ServiceExport, svc *corev1.Service) error {
523+
func (r *Reconciler) markServiceExportAsValid(ctx context.Context, svcExport *fleetnetv1alpha1.ServiceExport) error {
524524
validCond := meta.FindStatusCondition(svcExport.Status.Conditions, string(fleetnetv1alpha1.ServiceExportValid))
525525
expectedValidCond := &metav1.Condition{
526526
Type: string(fleetnetv1alpha1.ServiceExportValid),
527527
Status: metav1.ConditionTrue,
528528
Reason: svcExportValidCondReason,
529-
ObservedGeneration: svc.Generation,
529+
ObservedGeneration: svcExport.Generation,
530530
Message: fmt.Sprintf("service %s/%s is valid for export", svcExport.Namespace, svcExport.Name),
531531
}
532532
conflictCond := meta.FindStatusCondition(svcExport.Status.Conditions, string(fleetnetv1alpha1.ServiceExportConflict))
@@ -549,7 +549,7 @@ func (r *Reconciler) markServiceExportAsValid(ctx context.Context, svcExport *fl
549549
meta.SetStatusCondition(&svcExport.Status.Conditions, metav1.Condition{
550550
Type: string(fleetnetv1alpha1.ServiceExportConflict),
551551
Status: metav1.ConditionUnknown,
552-
ObservedGeneration: svc.Generation,
552+
ObservedGeneration: svcExport.Generation,
553553
Reason: svcExportPendingConflictResolutionReason,
554554
Message: fmt.Sprintf("service %s/%s is pending export conflict resolution", svcExport.Namespace, svcExport.Name),
555555
})

0 commit comments

Comments
 (0)