From 0e94869758abf79b93d69e5f7f0e4d1ad8bb902b Mon Sep 17 00:00:00 2001 From: Md Saif Husain <70682968+md-saif-husain@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:57:47 +0530 Subject: [PATCH 1/7] provision sequence audience using channel audience --- pkg/apis/flows/v1/sequence_lifecycle.go | 2 +- pkg/apis/flows/v1/sequence_lifecycle_test.go | 34 ++++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/pkg/apis/flows/v1/sequence_lifecycle.go b/pkg/apis/flows/v1/sequence_lifecycle.go index bc6559edacc..bd2b47b8853 100644 --- a/pkg/apis/flows/v1/sequence_lifecycle.go +++ b/pkg/apis/flows/v1/sequence_lifecycle.go @@ -186,7 +186,7 @@ func (ss *SequenceStatus) setAddress(address *duckv1.Addressable) { ss.Address = duckv1.Addressable{} sCondSet.Manage(ss).MarkUnknown(SequenceConditionAddressable, "emptyAddress", "addressable is nil") } else { - ss.Address = duckv1.Addressable{URL: address.URL} + ss.Address = duckv1.Addressable{URL: address.URL, Audience: address.Audience} sCondSet.Manage(ss).MarkTrue(SequenceConditionAddressable) } } diff --git a/pkg/apis/flows/v1/sequence_lifecycle_test.go b/pkg/apis/flows/v1/sequence_lifecycle_test.go index fd12f77368d..b5633720d8d 100644 --- a/pkg/apis/flows/v1/sequence_lifecycle_test.go +++ b/pkg/apis/flows/v1/sequence_lifecycle_test.go @@ -17,6 +17,7 @@ limitations under the License. package v1 import ( + "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -69,6 +70,7 @@ func getSubscription(name string, ready bool) *messagingv1.Subscription { func getChannelable(ready bool) *eventingduckv1.Channelable { URL := apis.HTTP("example.com") + channelAudience := fmt.Sprintf("messaging.knative.dev/inmemorychannel/%s/%s", "testNS", "test-imc") c := eventingduckv1.Channelable{ TypeMeta: metav1.TypeMeta{ APIVersion: "messaging.knative.dev/v1", @@ -83,7 +85,7 @@ func getChannelable(ready bool) *eventingduckv1.Channelable { Type: apis.ConditionReady, Status: corev1.ConditionTrue, }}) - c.Status.Address = &duckv1.Addressable{URL: URL} + c.Status.Address = &duckv1.Addressable{URL: URL, Audience: &channelAudience} } else { c.Status.SetConditions([]apis.Condition{{ Type: apis.ConditionReady, @@ -369,13 +371,15 @@ func TestSequenceReady(t *testing.T) { func TestSequencePropagateSetAddress(t *testing.T) { URL := apis.HTTP("example.com") URL2 := apis.HTTP("another.example.com") + channelAudience := fmt.Sprintf("messaging.knative.dev/inmemorychannel/%s/%s", "testNS", "test-imc") tests := []struct { - name string - status SequenceStatus - address *duckv1.Addressable - want duckv1.Addressable - wantStatus corev1.ConditionStatus - wantAddress string + name string + status SequenceStatus + address *duckv1.Addressable + want duckv1.Addressable + wantStatus corev1.ConditionStatus + wantAddress string + wantAudience string }{{ name: "nil", status: SequenceStatus{}, @@ -422,6 +426,14 @@ func TestSequencePropagateSetAddress(t *testing.T) { address: &duckv1.Addressable{URL: nil}, want: duckv1.Addressable{}, wantStatus: corev1.ConditionUnknown, + }, { + name: "audience", + status: SequenceStatus{}, + address: &duckv1.Addressable{URL: URL, Audience: &channelAudience}, + want: duckv1.Addressable{URL: URL, Audience: &channelAudience}, + wantStatus: corev1.ConditionTrue, + wantAddress: "http://example.com", + wantAudience: "messaging.knative.dev/inmemorychannel/testNS/test-imc", }} for _, tt := range tests { @@ -440,9 +452,17 @@ func TestSequencePropagateSetAddress(t *testing.T) { if got.URL != nil { gotAddress = got.URL.String() } + if diff := cmp.Diff(tt.wantAddress, gotAddress); diff != "" { t.Error("unexpected address.url (-want, +got) =", diff) } + gotAudience := "" + if got.Audience != nil { + gotAudience = *got.Audience + } + if diff := cmp.Diff(tt.wantAudience, gotAudience); diff != "" { + t.Error("unexpected address.audience (-want, +got) =", diff) + } }) } } From 3c8f878a9668286bc3f6f107cce46ca113a228ee Mon Sep 17 00:00:00 2001 From: Md Saif Husain <70682968+md-saif-husain@users.noreply.github.com> Date: Thu, 26 Oct 2023 19:25:34 +0530 Subject: [PATCH 2/7] change wantAudience as pointer --- pkg/apis/flows/v1/sequence_lifecycle_test.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/apis/flows/v1/sequence_lifecycle_test.go b/pkg/apis/flows/v1/sequence_lifecycle_test.go index b5633720d8d..20dac331642 100644 --- a/pkg/apis/flows/v1/sequence_lifecycle_test.go +++ b/pkg/apis/flows/v1/sequence_lifecycle_test.go @@ -379,7 +379,7 @@ func TestSequencePropagateSetAddress(t *testing.T) { want duckv1.Addressable wantStatus corev1.ConditionStatus wantAddress string - wantAudience string + wantAudience *string }{{ name: "nil", status: SequenceStatus{}, @@ -433,7 +433,7 @@ func TestSequencePropagateSetAddress(t *testing.T) { want: duckv1.Addressable{URL: URL, Audience: &channelAudience}, wantStatus: corev1.ConditionTrue, wantAddress: "http://example.com", - wantAudience: "messaging.knative.dev/inmemorychannel/testNS/test-imc", + wantAudience: &channelAudience, }} for _, tt := range tests { @@ -456,11 +456,7 @@ func TestSequencePropagateSetAddress(t *testing.T) { if diff := cmp.Diff(tt.wantAddress, gotAddress); diff != "" { t.Error("unexpected address.url (-want, +got) =", diff) } - gotAudience := "" - if got.Audience != nil { - gotAudience = *got.Audience - } - if diff := cmp.Diff(tt.wantAudience, gotAudience); diff != "" { + if diff := cmp.Diff(tt.wantAudience, got.Audience); diff != "" { t.Error("unexpected address.audience (-want, +got) =", diff) } }) From 3aab74e027220f4d2f2dd7cd6537584306163990 Mon Sep 17 00:00:00 2001 From: Md Saif Husain <70682968+md-saif-husain@users.noreply.github.com> Date: Fri, 27 Oct 2023 20:05:04 +0530 Subject: [PATCH 3/7] add e2e test --- test/auth/oidc_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/auth/oidc_test.go b/test/auth/oidc_test.go index 211a7c1d829..de2c61d14f6 100644 --- a/test/auth/oidc_test.go +++ b/test/auth/oidc_test.go @@ -33,10 +33,12 @@ import ( brokerfeatures "knative.dev/eventing/test/rekt/features/broker" "knative.dev/eventing/test/rekt/features/channel" parallelfeatures "knative.dev/eventing/test/rekt/features/parallel" + sequencefeatures "knative.dev/eventing/test/rekt/features/sequence" "knative.dev/eventing/test/rekt/resources/broker" "knative.dev/eventing/test/rekt/resources/channel_impl" "knative.dev/eventing/test/rekt/resources/channel_template" "knative.dev/eventing/test/rekt/resources/parallel" + "knative.dev/eventing/test/rekt/resources/sequence" ) func TestBrokerSupportsOIDC(t *testing.T) { @@ -95,3 +97,21 @@ func TestParallelSupportsOIDC(t *testing.T) { env.Test(ctx, t, oidc.ParallelHasAudienceOfInputChannel(name, env.Namespace(), channel_impl.GVR(), channel_impl.GVK().Kind)) } + +func TestSequenceSupportsOIDC(t *testing.T) { + t.Parallel() + + ctx, env := global.Environment( + knative.WithKnativeNamespace(system.Namespace()), + knative.WithLoggingConfig, + knative.WithTracingConfig, + k8s.WithEventListener, + environment.Managed(t), + environment.WithPollTimings(4*time.Second, 12*time.Minute), + ) + + name := feature.MakeRandomK8sName("sequence") + env.Prerequisite(ctx, t, sequencefeatures.GoesReady(name)) + + env.Test(ctx, t, oidc.AddressableHasAudiencePopulated(sequence.GVR(), sequence.GVK().Kind, name, env.Namespace())) +} From feba9fb2039123d5363a3517736c799162aa9606 Mon Sep 17 00:00:00 2001 From: Md Saif Husain <70682968+md-saif-husain@users.noreply.github.com> Date: Thu, 16 Nov 2023 19:43:40 +0530 Subject: [PATCH 4/7] update sequence audience e2e test --- test/auth/features/oidc/sequence.go | 42 ++++++++++++++++++++++++ test/auth/oidc_test.go | 6 ++-- test/rekt/resources/sequence/sequence.go | 5 +++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/auth/features/oidc/sequence.go diff --git a/test/auth/features/oidc/sequence.go b/test/auth/features/oidc/sequence.go new file mode 100644 index 00000000000..5353301c211 --- /dev/null +++ b/test/auth/features/oidc/sequence.go @@ -0,0 +1,42 @@ +/* +Copyright 2023 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 oidc + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/eventing/pkg/auth" + "knative.dev/eventing/pkg/reconciler/sequence/resources" + "knative.dev/eventing/test/rekt/resources/addressable" + "knative.dev/eventing/test/rekt/resources/sequence" + "knative.dev/reconciler-test/pkg/feature" +) + +func SequenceHasAudienceOfInputChannel(sequenceName, sequenceNamespace string, channelGVR schema.GroupVersionResource, channelKind string) *feature.Feature { + f := feature.NewFeatureNamed("Parallel has audience of input channel") + + f.Setup("Parallel goes ready", sequence.IsReady(sequenceName)) + + expectedAudience := auth.GetAudience(channelGVR.GroupVersion().WithKind(channelKind), metav1.ObjectMeta{ + Name: resources.SequenceChannelName(sequenceName, 0), + Namespace: sequenceNamespace, + }) + + f.Alpha("Parallel").Must("has audience set", sequence.ValidateAddress(sequenceName, addressable.AssertAddressWithAudience(expectedAudience))) + + return f +} diff --git a/test/auth/oidc_test.go b/test/auth/oidc_test.go index de2c61d14f6..45dd9de3069 100644 --- a/test/auth/oidc_test.go +++ b/test/auth/oidc_test.go @@ -107,11 +107,13 @@ func TestSequenceSupportsOIDC(t *testing.T) { knative.WithTracingConfig, k8s.WithEventListener, environment.Managed(t), - environment.WithPollTimings(4*time.Second, 12*time.Minute), ) name := feature.MakeRandomK8sName("sequence") - env.Prerequisite(ctx, t, sequencefeatures.GoesReady(name)) + env.Prerequisite(ctx, t, sequencefeatures.GoesReady(name, sequence.WithChannelTemplate(channel_template.ChannelTemplate{ + TypeMeta: channel_impl.TypeMeta(), + Spec: map[string]interface{}{}, + }))) env.Test(ctx, t, oidc.AddressableHasAudiencePopulated(sequence.GVR(), sequence.GVK().Kind, name, env.Namespace())) } diff --git a/test/rekt/resources/sequence/sequence.go b/test/rekt/resources/sequence/sequence.go index 5a8a0dc1329..d29ce9afdc5 100644 --- a/test/rekt/resources/sequence/sequence.go +++ b/test/rekt/resources/sequence/sequence.go @@ -150,3 +150,8 @@ func WithChannelTemplate(template channel_template.ChannelTemplate) manifest.Cfg channelTemplate["spec"] = template.Spec } } + +// ValidateAddress validates the address retured by Address +func ValidateAddress(name string, validate addressable.ValidateAddressFn, timings ...time.Duration) feature.StepFn { + return addressable.ValidateAddress(GVR(), name, validate, timings...) +} From 19d66759c483ee29e0ac474ad74c1989bf87975b Mon Sep 17 00:00:00 2001 From: Md Saif Husain <70682968+md-saif-husain@users.noreply.github.com> Date: Sat, 18 Nov 2023 20:11:19 +0530 Subject: [PATCH 5/7] rename sequence to parallel --- test/auth/features/oidc/sequence.go | 6 +++--- test/auth/oidc_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/auth/features/oidc/sequence.go b/test/auth/features/oidc/sequence.go index 5353301c211..1c0013cb5f0 100644 --- a/test/auth/features/oidc/sequence.go +++ b/test/auth/features/oidc/sequence.go @@ -27,16 +27,16 @@ import ( ) func SequenceHasAudienceOfInputChannel(sequenceName, sequenceNamespace string, channelGVR schema.GroupVersionResource, channelKind string) *feature.Feature { - f := feature.NewFeatureNamed("Parallel has audience of input channel") + f := feature.NewFeatureNamed("Sequence has audience of input channel") - f.Setup("Parallel goes ready", sequence.IsReady(sequenceName)) + f.Setup("Sequence goes ready", sequence.IsReady(sequenceName)) expectedAudience := auth.GetAudience(channelGVR.GroupVersion().WithKind(channelKind), metav1.ObjectMeta{ Name: resources.SequenceChannelName(sequenceName, 0), Namespace: sequenceNamespace, }) - f.Alpha("Parallel").Must("has audience set", sequence.ValidateAddress(sequenceName, addressable.AssertAddressWithAudience(expectedAudience))) + f.Alpha("Sequence").Must("has audience set", sequence.ValidateAddress(sequenceName, addressable.AssertAddressWithAudience(expectedAudience))) return f } diff --git a/test/auth/oidc_test.go b/test/auth/oidc_test.go index 45dd9de3069..84a8566c4b8 100644 --- a/test/auth/oidc_test.go +++ b/test/auth/oidc_test.go @@ -115,5 +115,5 @@ func TestSequenceSupportsOIDC(t *testing.T) { Spec: map[string]interface{}{}, }))) - env.Test(ctx, t, oidc.AddressableHasAudiencePopulated(sequence.GVR(), sequence.GVK().Kind, name, env.Namespace())) + env.Test(ctx, t, oidc.SequenceHasAudienceOfInputChannel(sequence.GVR(), sequence.GVK().Kind, name, env.Namespace())) } From 40f98aeef952f39473821d085a3bc88263e7bca3 Mon Sep 17 00:00:00 2001 From: Md Saif Husain <70682968+md-saif-husain@users.noreply.github.com> Date: Sat, 18 Nov 2023 20:31:02 +0530 Subject: [PATCH 6/7] use channelAudience as variable declaration --- pkg/apis/flows/v1/sequence_lifecycle_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/apis/flows/v1/sequence_lifecycle_test.go b/pkg/apis/flows/v1/sequence_lifecycle_test.go index 20dac331642..24c822147bb 100644 --- a/pkg/apis/flows/v1/sequence_lifecycle_test.go +++ b/pkg/apis/flows/v1/sequence_lifecycle_test.go @@ -35,6 +35,8 @@ var sequenceConditionReady = apis.Condition{ Status: corev1.ConditionTrue, } +var channelAudience = fmt.Sprintf("messaging.knative.dev/inmemorychannel/%s/%s", "testNS", "test-imc") + func TestSequenceGetConditionSet(t *testing.T) { r := &Sequence{} @@ -371,7 +373,7 @@ func TestSequenceReady(t *testing.T) { func TestSequencePropagateSetAddress(t *testing.T) { URL := apis.HTTP("example.com") URL2 := apis.HTTP("another.example.com") - channelAudience := fmt.Sprintf("messaging.knative.dev/inmemorychannel/%s/%s", "testNS", "test-imc") + tests := []struct { name string status SequenceStatus From f4c087e032c3c71daf8a2fc395f0f7a8af070460 Mon Sep 17 00:00:00 2001 From: Md Saif Husain <70682968+md-saif-husain@users.noreply.github.com> Date: Wed, 22 Nov 2023 19:24:40 +0530 Subject: [PATCH 7/7] fix build issues --- test/auth/oidc_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/auth/oidc_test.go b/test/auth/oidc_test.go index 84a8566c4b8..e1c813e2f75 100644 --- a/test/auth/oidc_test.go +++ b/test/auth/oidc_test.go @@ -115,5 +115,5 @@ func TestSequenceSupportsOIDC(t *testing.T) { Spec: map[string]interface{}{}, }))) - env.Test(ctx, t, oidc.SequenceHasAudienceOfInputChannel(sequence.GVR(), sequence.GVK().Kind, name, env.Namespace())) + env.Test(ctx, t, oidc.SequenceHasAudienceOfInputChannel(name, env.Namespace(), channel_impl.GVR(), channel_impl.GVK().Kind)) }