Skip to content

Commit

Permalink
Allow different namespace references (#3917)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
pierDipi committed Jun 5, 2024
1 parent 4103b94 commit 5c4b6a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
10 changes: 6 additions & 4 deletions control-plane/cmd/webhook-kafka/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection/sharedmain"
Expand All @@ -32,10 +33,11 @@ import (
"knative.dev/pkg/webhook/resourcesemantics/defaulting"
"knative.dev/pkg/webhook/resourcesemantics/validation"

sourcesv1beta1 "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"
eventingcorev1 "knative.dev/eventing/pkg/apis/eventing/v1"
"knative.dev/eventing/pkg/apis/feature"

sourcesv1beta1 "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"

messagingv1beta1 "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/messaging/v1beta1"

"knative.dev/eventing-kafka-broker/control-plane/pkg/apis/core"
Expand Down Expand Up @@ -65,7 +67,7 @@ func NewDefaultingAdmissionController(ctx context.Context, _ configmap.Watcher)

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
ctxFunc := func(ctx context.Context) context.Context {
return ctx
return apis.AllowDifferentNamespace(ctx)
}

return defaulting.NewAdmissionController(ctx,
Expand All @@ -90,7 +92,7 @@ func NewPodDefaultingAdmissionController(ctx context.Context, _ configmap.Watche

// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
ctxFunc := func(ctx context.Context) context.Context {
return ctx
return apis.AllowDifferentNamespace(ctx)
}

return defaulting.NewAdmissionController(ctx,
Expand Down Expand Up @@ -121,7 +123,7 @@ func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher

// Decorate contexts with the current state of the config.
ctxFunc := func(ctx context.Context) context.Context {
return featureStore.ToContext(ctx)
return apis.AllowDifferentNamespace(featureStore.ToContext(ctx))
}

return validation.NewAdmissionController(ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
kafkasource "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"
eventingduck "knative.dev/eventing/pkg/apis/duck/v1"
"knative.dev/eventing/pkg/apis/feature"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"

kafkasource "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"
)

const (
Expand Down Expand Up @@ -114,6 +115,33 @@ func TestConsumerGroup_Validate(t *testing.T) {
},
wantErr: false,
},
{
name: "subscriber different namespace",
ctx: apis.AllowDifferentNamespace(context.Background()),
given: &ConsumerGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "my-cg",
Namespace: "my-ns",
},
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Subscriber: duckv1.Destination{
Ref: &duckv1.KReference{
Kind: "Sequence",
Namespace: "ma-ns-2",
Name: "my-seq",
APIVersion: "flows.knative.dev/v1",
},
},
},
},
},
},
wantErr: false,
},
{
name: "invalid delivery - timeout feature disabled",
ctx: context.Background(),
Expand Down

0 comments on commit 5c4b6a4

Please sign in to comment.