-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EventPolicy reconciliation for Sequence (#8106)
* feat: initial commit Signed-off-by: Leo Li <leoli@redhat.com> * feat: add the test for eventpolicy in sequence reconciler Signed-off-by: Leo Li <leoli@redhat.com> * fix: fix the typo and remove the unused helper function Signed-off-by: Leo Li <leoli@redhat.com> * fix: trying to fix the git diff issue Signed-off-by: Leo Li <leoli@redhat.com> * fix: trying to fix the git diff issue Signed-off-by: Leo Li <leoli@redhat.com> * fix: fix the nit minor comments Signed-off-by: Leo Li <leoli@redhat.com> * fix: update the reconcilation mechanism Signed-off-by: Leo Li <leoli@redhat.com> * fix: fix the goimports and remove unused helper functions and input parameters Signed-off-by: Leo Li <leoli@redhat.com> * fix: add more unit tests to test out remove steps from the sequence Signed-off-by: Leo Li <leoli@redhat.com> * Update pkg/reconciler/sequence/sequence.go Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com> * Update pkg/reconciler/sequence/sequence.go Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com> * Apply suggestions from code review Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com> * fix: fix the nit review comments from pierdipi and rahul Signed-off-by: Leo Li <leoli@redhat.com> * fix: using auth.GetEventPoliciesForResource when trying to list all Sequence's eventPolicy (not for the immediate channels) Signed-off-by: Leo Li <leoli@redhat.com> * feat: add the sorting to avoid flaky test when there are multiple eventplocies per sequence Signed-off-by: Leo Li <leoli@redhat.com> * feat: remove the nil condition for channel name when creating the sequence policy name Signed-off-by: Leo Li <leoli@redhat.com> * feat: add more unit tests Signed-off-by: Leo Li <leoli@redhat.com> * fix: lint & goimports Signed-off-by: Leo Li <leoli@redhat.com> * fix: fix the review comments * fix: fix Christoph's review comments Signed-off-by: Leo Li <leoli@redhat.com> * feat: adding a test for sequence with existing intermediate eventpolicies requiring update and cleanup. Signed-off-by: Leo Li <leoli@redhat.com> * fix: the deepDerivative failed to compare the eventpolicy's From.Spec, change to reflect.DeepEqual Signed-off-by: Leo Li <leoli@redhat.com> * fix: change back to use DeepDerivative Signed-off-by: Leo Li <leoli@redhat.com> * fix: fix the test case to make the eventpolicy has a valid spec Signed-off-by: Leo Li <leoli@redhat.com> * fix: fix the flaky issue by soring the policies Signed-off-by: Leo Li <leoli@redhat.com> * fix: change input channel's ownerref to sequence's eventpolicy --------- Signed-off-by: Leo Li <leoli@redhat.com> Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
- Loading branch information
Showing
4 changed files
with
2,360 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
Copyright 2024 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package resources | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" | ||
eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" | ||
flowsv1 "knative.dev/eventing/pkg/apis/flows/v1" | ||
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" | ||
"knative.dev/pkg/kmeta" | ||
) | ||
|
||
const ( | ||
SequenceChannelEventPolicyLabelPrefix = "flows.knative.dev/" | ||
sequenceKind = "Sequence" | ||
subscriptionKind = "Subscription" | ||
eventPolicyKind = "EventPolicy" | ||
) | ||
|
||
func MakeEventPolicyForSequenceChannel(s *flowsv1.Sequence, channel *eventingduckv1.Channelable, subscription *messagingv1.Subscription) *eventingv1alpha1.EventPolicy { | ||
return &eventingv1alpha1.EventPolicy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: channel.Namespace, | ||
Name: SequenceEventPolicyName(s.Name, channel.Name), | ||
OwnerReferences: []metav1.OwnerReference{ | ||
{ | ||
APIVersion: flowsv1.SchemeGroupVersion.String(), | ||
Kind: sequenceKind, | ||
Name: s.Name, | ||
UID: s.UID, | ||
}, | ||
}, | ||
Labels: LabelsForSequenceChannelsEventPolicy(s.Name), | ||
}, | ||
Spec: eventingv1alpha1.EventPolicySpec{ | ||
To: []eventingv1alpha1.EventPolicySpecTo{ | ||
{ | ||
Ref: &eventingv1alpha1.EventPolicyToReference{ | ||
APIVersion: channel.APIVersion, | ||
Kind: channel.Kind, | ||
Name: channel.Name, | ||
}, | ||
}, | ||
}, | ||
From: []eventingv1alpha1.EventPolicySpecFrom{ | ||
{ | ||
Ref: &eventingv1alpha1.EventPolicyFromReference{ | ||
APIVersion: messagingv1.SchemeGroupVersion.String(), | ||
Kind: subscriptionKind, | ||
Name: subscription.Name, | ||
Namespace: subscription.Namespace, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func LabelsForSequenceChannelsEventPolicy(sequenceName string) map[string]string { | ||
return map[string]string{ | ||
SequenceChannelEventPolicyLabelPrefix + "sequence-name": sequenceName, | ||
} | ||
} | ||
|
||
func SequenceEventPolicyName(sequenceName, postfix string) string { | ||
|
||
if postfix == "" { | ||
return sequenceName | ||
} | ||
return kmeta.ChildName(sequenceName, "-"+postfix) | ||
|
||
} | ||
|
||
// MakeEventPolicyForSequenceInputChannel creates an EventPolicy for the input channel of a Sequence | ||
func MakeEventPolicyForSequenceInputChannel(s *flowsv1.Sequence, inputChannel *eventingduckv1.Channelable, sequencePolicy *eventingv1alpha1.EventPolicy) *eventingv1alpha1.EventPolicy { | ||
return &eventingv1alpha1.EventPolicy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: inputChannel.Namespace, | ||
Name: SequenceEventPolicyName(s.Name, sequencePolicy.Name), | ||
OwnerReferences: []metav1.OwnerReference{ | ||
{ | ||
APIVersion: eventingv1alpha1.SchemeGroupVersion.String(), | ||
Kind: eventPolicyKind, | ||
Name: sequencePolicy.Name, | ||
UID: sequencePolicy.UID, | ||
}, | ||
}, | ||
Labels: LabelsForSequenceChannelsEventPolicy(s.Name), | ||
}, | ||
Spec: eventingv1alpha1.EventPolicySpec{ | ||
To: []eventingv1alpha1.EventPolicySpecTo{ | ||
{ | ||
Ref: &eventingv1alpha1.EventPolicyToReference{ | ||
APIVersion: inputChannel.APIVersion, | ||
Kind: inputChannel.Kind, | ||
Name: inputChannel.Name, | ||
}, | ||
}, | ||
}, | ||
From: sequencePolicy.Spec.From, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.