Skip to content

Commit

Permalink
Only list ready EventPolicies in .status.policies
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr committed Jun 18, 2024
1 parent 98f6c79 commit 594e3d7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
11 changes: 6 additions & 5 deletions pkg/reconciler/inmemorychannel/controller/inmemorychannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, imc *v1.InMemoryChannel)
if len(applyingEvenPolicies) > 0 {
unreadyEventPolicies := []string{}
for _, policy := range applyingEvenPolicies {
imc.Status.Policies = append(imc.Status.Policies, eventingduck.AppliedEventPolicyRef{
Name: policy.Name,
APIVersion: eventingv1alpha1.SchemeGroupVersion.String(),
})

if !policy.Status.IsReady() {
unreadyEventPolicies = append(unreadyEventPolicies, policy.Name)
} else {
// only add Ready policies to the list
imc.Status.Policies = append(imc.Status.Policies, eventingduck.AppliedEventPolicyRef{
Name: policy.Name,
APIVersion: eventingv1alpha1.SchemeGroupVersion.String(),
})
}
}

Expand Down
47 changes: 40 additions & 7 deletions pkg/reconciler/inmemorychannel/controller/inmemorychannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const (

imcGeneration = 7

eventPolicyName = "test-event-policy"
readyEventPolicyName = "test-event-policy-ready"
unreadyEventPolicyName = "test-event-policy-unready"
)

var (
Expand Down Expand Up @@ -676,7 +677,7 @@ func TestAllCases(t *testing.T) {
),
}},
}, {
Name: "Should mark NotReady on unread EventPolicy",
Name: "Should mark NotReady on unready EventPolicy",
Key: imcKey,
Objects: []runtime.Object{
makeDLSServiceAsUnstructured(),
Expand All @@ -703,8 +704,40 @@ func TestAllCases(t *testing.T) {
WithInMemoryChannelAddress(channelServiceAddress),
WithDeadLetterSink(imcDest),
WithInMemoryChannelStatusDLS(dlsStatus),
WithInMemoryChannelEventPoliciesNotReady("NotReady", fmt.Sprintf("event policies %s are not ready", eventPolicyName)),
WithInMemoryChannelEventPoliciesListed(makeUnreadyEventPolicy()),
WithInMemoryChannelEventPoliciesNotReady("NotReady", fmt.Sprintf("event policies %s are not ready", makeUnreadyEventPolicy().Name)),
),
}},
}, {
Name: "Should list only Ready EventPolicy",
Key: imcKey,
Objects: []runtime.Object{
makeDLSServiceAsUnstructured(),
makeReadyDeployment(),
makeService(),
makeReadyEndpoints(),
NewInMemoryChannel(imcName, testNS,
WithDeadLetterSink(imcDest),
WithInMemoryChannelGeneration(imcGeneration),
),
makeChannelService(NewInMemoryChannel(imcName, testNS)),
makeReadyEventPolicy(),
makeUnreadyEventPolicy(),
},
WantErr: false,
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewInMemoryChannel(imcName, testNS,
WithInitInMemoryChannelConditions,
WithInMemoryChannelDeploymentReady(),
WithInMemoryChannelGeneration(imcGeneration),
WithInMemoryChannelStatusObservedGeneration(imcGeneration),
WithInMemoryChannelServiceReady(),
WithInMemoryChannelEndpointsReady(),
WithInMemoryChannelChannelServiceReady(),
WithInMemoryChannelAddress(channelServiceAddress),
WithDeadLetterSink(imcDest),
WithInMemoryChannelStatusDLS(dlsStatus),
WithInMemoryChannelEventPoliciesNotReady("NotReady", fmt.Sprintf("event policies %s are not ready", makeUnreadyEventPolicy().Name)),
WithInMemoryChannelEventPoliciesListed(makeReadyEventPolicy()),
),
}},
}}
Expand Down Expand Up @@ -889,7 +922,7 @@ func makeUnknownDeployment() *appsv1.Deployment {
return d
}

func makeEventPolicy() *v1alpha1.EventPolicy {
func makeEventPolicy(eventPolicyName string) *v1alpha1.EventPolicy {
return &v1alpha1.EventPolicy{
TypeMeta: metav1.TypeMeta{
APIVersion: "eventing.knative.dev/v1alpha1",
Expand All @@ -915,13 +948,13 @@ func makeEventPolicy() *v1alpha1.EventPolicy {
}

func makeReadyEventPolicy() *v1alpha1.EventPolicy {
policy := makeEventPolicy()
policy := makeEventPolicy(readyEventPolicyName)
policy.Status.Conditions = []apis.Condition{{Type: v1alpha1.EventPolicyConditionReady, Status: corev1.ConditionTrue}}
return policy
}

func makeUnreadyEventPolicy() *v1alpha1.EventPolicy {
policy := makeEventPolicy()
policy := makeEventPolicy(unreadyEventPolicyName)
policy.Status.Conditions = []apis.Condition{{Type: v1alpha1.EventPolicyConditionReady, Status: corev1.ConditionFalse}}
return policy
}
Expand Down

0 comments on commit 594e3d7

Please sign in to comment.