diff --git a/pkg/reconciler/trigger/trigger.go b/pkg/reconciler/trigger/trigger.go index 53399319c97..e1a020970cc 100644 --- a/pkg/reconciler/trigger/trigger.go +++ b/pkg/reconciler/trigger/trigger.go @@ -260,15 +260,16 @@ func (r *Reconciler) propagateDependencyReadiness(dependencyObjRef corev1.Object return fmt.Errorf("getting the dependency: %v", err) } dependency := dependencyObj.(*duckv1alpha1.KResource) - // Temporarily comment it until we figure out whether we update Status.ObservedGeneration when KResource changes - // From manual testing, it looks like we never update Status.ObservedGeneration - //if dependency.GetGeneration() != dependency.Status.ObservedGeneration { - // logging.FromContext(ctx).Error("The ObjectMeta Generation of dependency is not equal to the observedGeneration of status", - // zap.Any("ObjectMeta Generation of dependency", dependency.GetGeneration()), - // zap.Any("ObservedGeneration of status", dependency.Status.ObservedGeneration)) - // t.Status.MarkDependencyUnknown("GenerationNotEqual", "The ObjectMeta Generation of dependency %d is not equal to the ObservedGeneration of status %d", dependency.GetGeneration(), dependency.Status.ObservedGeneration) - // return nil - //} + + // The dependency hasn't yet reconciled our latest changes to + // its desired state, so its conditions are outdated. + if dependency.GetGeneration() != dependency.Status.ObservedGeneration { + logging.FromContext(ctx).Info("The ObjectMeta Generation of dependency is not equal to the observedGeneration of status", + zap.Any("objectMetaGeneration", dependency.GetGeneration()), + zap.Any("statusObservedGeneration", dependency.Status.ObservedGeneration)) + t.Status.MarkDependencyUnknown("GenerationNotEqual", "The dependency's metadata.generation, %q, is not equal to its status.observedGeneration, %q.", dependency.GetGeneration(), dependency.Status.ObservedGeneration) + return nil + } t.Status.PropagateDependencyStatus(dependency) return nil } diff --git a/pkg/reconciler/trigger/trigger_test.go b/pkg/reconciler/trigger/trigger_test.go index 49ce62d4346..782aba403b5 100644 --- a/pkg/reconciler/trigger/trigger_test.go +++ b/pkg/reconciler/trigger/trigger_test.go @@ -79,6 +79,9 @@ const ( testSchedule = "*/2 * * * *" testData = "data" sinkName = "testsink" + + currentGeneration = 1 + outdatedGeneration = 0 ) var ( @@ -568,6 +571,37 @@ func TestAllCases(t *testing.T) { ), }}, }, { + Name: "Dependency generation not equal", + Key: triggerKey, + Objects: []runtime.Object{ + makeReadyBroker(), + makeBrokerFilterService(), + makeReadySubscription(), + makeGenerationNotEqualCronJobSource(), + reconciletesting.NewTrigger(triggerName, testNS, brokerName, + reconciletesting.WithTriggerUID(triggerUID), + reconciletesting.WithTriggerSubscriberURI(subscriberURI), + reconciletesting.WithInitTriggerConditions, + reconciletesting.WithDependencyAnnotation(dependencyAnnotation), + ), + }, + WantErr: false, + WantEvents: []string{ + Eventf(corev1.EventTypeNormal, "TriggerReconciled", "Trigger reconciled")}, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: reconciletesting.NewTrigger(triggerName, testNS, brokerName, + reconciletesting.WithTriggerUID(triggerUID), + reconciletesting.WithTriggerSubscriberURI(subscriberURI), + // The first reconciliation will initialize the status conditions. + reconciletesting.WithInitTriggerConditions, + reconciletesting.WithDependencyAnnotation(dependencyAnnotation), + reconciletesting.WithTriggerBrokerReady(), + reconciletesting.WithTriggerSubscribed(), + reconciletesting.WithTriggerStatusSubscriberURI(subscriberURI), + reconciletesting.WithTriggerDependencyUnknown("GenerationNotEqual", fmt.Sprintf("The dependency's metadata.generation, %q, is not equal to its status.observedGeneration, %q.", currentGeneration, outdatedGeneration))), + }}, + }, + { Name: "Dependency ready", Key: triggerKey, Objects: []runtime.Object{ @@ -761,6 +795,13 @@ func makeNotReadyCronJobSource() *sourcesv1alpha1.CronJobSource { return NewCronJobSource(cronJobSourceName, testNS, WithCronJobApiVersion(cronJobSourceAPIVersion), WithCronJobSourceSinkNotFound) } +func makeGenerationNotEqualCronJobSource() *sourcesv1alpha1.CronJobSource { + c := makeNotReadyCronJobSource() + c.Generation = currentGeneration + c.Status.ObservedGeneration = outdatedGeneration + return c +} + func makeReadyCronJobSource() *sourcesv1alpha1.CronJobSource { return NewCronJobSource(cronJobSourceName, testNS, WithCronJobApiVersion(cronJobSourceAPIVersion),