Skip to content

Defaulting for Channel should resolve the namespace from context, not the resource #4514

Open
@aliok

Description

@aliok

Describe the bug
When I use Kube REST api in the way kn uses it, I can see behavior differences when I post these 2:

  • {"kind":"Channel","apiVersion":"messaging.knative.dev/v1beta1","metadata":{"name":"my-channel"}}
  • {"kind":"Channel","apiVersion":"messaging.knative.dev/v1beta1","metadata":{"name":"my-channel", "namespace":"knativetutorial"}}

URL posted is same: apis/messaging.knative.dev/v1beta1/namespaces/knativetutorial/channels

This problem makes eventing webhook pick the wrong default channel for namespace.

See following.

Make IMC cluster default and KafkaChannel knativetutorial namespace default:

$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: default-ch-webhook
  namespace: knative-eventing
data:
  default-ch-config: |
    clusterDefault:
      apiVersion: messaging.knative.dev/v1beta1
      kind: InMemoryChannel
    namespaceDefaults:
      knativetutorial:
        apiVersion: messaging.knative.dev/v1alpha1
        kind: KafkaChannel
        spec:
          numPartitions: 2
          replicationFactor: 1
EOF

Start proxy:

$ kubectl proxy --port=8080 &

Post 2 channel requests to the same namespace URL; 1 with namespace in metadata, other not:

$ curl -XPOST  \
    -d '{"kind":"Channel","apiVersion":"messaging.knative.dev/v1beta1","metadata":{"name":"my-channel-1", "namespace":"knativetutorial"}}' \
    -H "Content-Type: application/json" \
    'http://localhost:8080/apis/messaging.knative.dev/v1beta1/namespaces/knativetutorial/channels'

$ curl -XPOST  \
    -d '{"kind":"Channel","apiVersion":"messaging.knative.dev/v1beta1","metadata":{"name":"my-channel-2"}}' \
    -H "Content-Type: application/json" \
    'http://localhost:8080/apis/messaging.knative.dev/v1beta1/namespaces/knativetutorial/channels'

First channel is created with KafkaChannel, the 2nd created with IMC.

$ k get channels -A
NAMESPACE         NAME           URL                                                                AGE   READY   REASON
knativetutorial   my-channel-1   http://my-channel-1-kn-channel.knativetutorial.svc.cluster.local   6s    True    
knativetutorial   my-channel-2   http://my-channel-2-kn-channel.knativetutorial.svc.cluster.local   5s    True    

$ k get kafkachannels -A
NAMESPACE         NAME           READY   REASON   URL                                                                AGE
knativetutorial   my-channel-1   True             http://my-channel-1-kn-channel.knativetutorial.svc.cluster.local   15s

$ k get imc -A
NAMESPACE         NAME           URL                                                                AGE   READY   REASON
knativetutorial   my-channel-2   http://my-channel-2-kn-channel.knativetutorial.svc.cluster.local   11s   True    

Expected behavior
Defaulting to use the context namespace.

To Reproduce
Steps are above.

Knative release version
0.17, 0.18, 0.19

Additional context
Add any other context about the problem here such as proposed priority

Metadata

Metadata

Labels

area/channelskind/bugCategorizes issue or PR as related to a bug.kind/good-first-issueDenotes an issue ready for a new contributor.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.triage/acceptedIssues which should be fixed (post-triage)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions