Skip to content

Commit

Permalink
E2E tests for channel: TLS key pair rotation (knative-extensions#3406)
Browse files Browse the repository at this point in the history
* Save work progress

* Expose the TLS port

* Adding the logger to see what is happening

* Java - Adding the debugging information

* Adding the path to the contract

* Comment out the certificate rotation test portion

* Resolve the source certificate not found issue

* Fix the issue in the test

* Update control-plane/pkg/prober/prober.go

Co-authored-by: Calum Murray <cmurray@redhat.com>

* Update control-plane/pkg/reconciler/channel/channel.go

Co-authored-by: Calum Murray <cmurray@redhat.com>

* Update control-plane/pkg/reconciler/channel/channel.go

Co-authored-by: Calum Murray <cmurray@redhat.com>

* Update control-plane/pkg/reconciler/channel/resources/service.go

Co-authored-by: Calum Murray <cmurray@redhat.com>

* Update data-plane/receiver/src/main/java/dev/knative/eventing/kafka/broker/receiver/impl/IngressProducerReconcilableStore.java

Co-authored-by: Calum Murray <cmurray@redhat.com>

* Fix the inconsistent varable name

* Fix the failed build issue

* Remove the logger

* Run formatting

* Update data-plane/receiver/src/main/java/dev/knative/eventing/kafka/broker/receiver/impl/ReceiverVerticle.java

Co-authored-by: Calum Murray <cmurray@redhat.com>

* Remove the logger

* Code gen

* Update control-plane/pkg/reconciler/channel/channel.go

Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>

* Remove the uncessary code

* Fix the failing reconciler tests due to the missing newly added filed in the test

* Format fix

* Instead of using channel service name, we directly use channel name for Path

* Instead of using channel service name, we directly use channel name for Path

---------

Co-authored-by: Calum Murray <cmurray@redhat.com>
Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
  • Loading branch information
3 people committed Oct 26, 2023
1 parent 6c0e105 commit 828b81e
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,28 @@ spec:
required:
- url
properties:
name:
type: string
url:
type: string
CACerts:
type: string
audience:
type: string
addresses:
description: Kafka Sink is Addressable. It exposes the endpoints as URIs to get events delivered into the Kafka topic.
type: array
items:
type: object
properties:
name:
type: string
url:
type: string
CACerts:
type: string
audience:
type: string
annotations:
description: Annotations is additional Status fields for the Resource to save some additional State as well as convey more information to the user. This is roughly akin to Annotations on any k8s resource, just the reconciler conveying richer information outwards.
type: object
Expand Down
5 changes: 3 additions & 2 deletions control-plane/pkg/reconciler/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (r *Reconciler) reconcileKind(ctx context.Context, channel *messagingv1beta
}

httpAddress := receiver.ChannelHTTPAddress(channelHttpHost)
httpsAddress := receiver.HTTPSAddress(channelHttpsHost, channelService, caCerts)
httpsAddress := receiver.HTTPSAddress(channelHttpsHost, channel, caCerts)
// Permissive mode:
// - status.address http address with path-based routing
// - status.addresses:
Expand All @@ -337,7 +337,7 @@ func (r *Reconciler) reconcileKind(ctx context.Context, channel *messagingv1beta
return err
}

httpsAddress := receiver.HTTPSAddress(channelHttpsHost, channelService, caCerts)
httpsAddress := receiver.HTTPSAddress(channelHttpsHost, channel, caCerts)
addressableStatus.Addresses = []duckv1.Addressable{httpsAddress}
addressableStatus.Address = &httpsAddress
} else {
Expand Down Expand Up @@ -672,6 +672,7 @@ func (r *Reconciler) getChannelContractResource(ctx context.Context, topic strin
Ingress: &contract.Ingress{
Host: receiver.Host(channel.GetNamespace(), channel.GetName()),
EnableAutoCreateEventTypes: feature.FromContext(ctx).IsEnabled(feature.EvenTypeAutoCreate),
Path: receiver.Path(channel.GetNamespace(), channel.GetName()),
},
BootstrapServers: config.GetBootstrapServers(),
Reference: &contract.Reference{
Expand Down
26 changes: 23 additions & 3 deletions control-plane/pkg/reconciler/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down Expand Up @@ -262,6 +263,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
EgressConfig: &contract.EgressConfig{
Expand Down Expand Up @@ -338,6 +340,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down Expand Up @@ -408,6 +411,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down Expand Up @@ -482,6 +486,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{},
Expand Down Expand Up @@ -554,6 +559,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -631,6 +637,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -713,6 +720,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -795,6 +803,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -883,6 +892,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -1173,6 +1183,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down Expand Up @@ -1270,6 +1281,7 @@ func TestReconcileKind(t *testing.T) {
},
},
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -1376,6 +1388,7 @@ func TestReconcileKind(t *testing.T) {
},
},
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -1479,6 +1492,7 @@ func TestReconcileKind(t *testing.T) {
},
},
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
Egresses: []*contract.Egress{{
Expand Down Expand Up @@ -1557,6 +1571,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down Expand Up @@ -1626,6 +1641,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down Expand Up @@ -1738,6 +1754,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down Expand Up @@ -1823,6 +1840,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
EgressConfig: &contract.EgressConfig{
Expand Down Expand Up @@ -1864,7 +1882,7 @@ func TestReconcileKind(t *testing.T) {
WithChannelAddresses([]duckv1.Addressable{
{
Name: pointer.String("https"),
URL: httpsURL(ChannelServiceName, ChannelNamespace),
URL: httpsURL(ChannelName, ChannelNamespace),
CACerts: pointer.String(testCaCerts),
},
{
Expand Down Expand Up @@ -1925,6 +1943,7 @@ func TestReconcileKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
EgressConfig: &contract.EgressConfig{
Expand Down Expand Up @@ -1966,13 +1985,13 @@ func TestReconcileKind(t *testing.T) {
WithChannelAddresses([]duckv1.Addressable{
{
Name: pointer.String("https"),
URL: httpsURL(ChannelServiceName, ChannelNamespace),
URL: httpsURL(ChannelName, ChannelNamespace),
CACerts: pointer.String(testCaCerts),
},
}),
WithChannelAddress(duckv1.Addressable{
Name: pointer.String("https"),
URL: httpsURL(ChannelServiceName, ChannelNamespace),
URL: httpsURL(ChannelName, ChannelNamespace),
CACerts: pointer.String(testCaCerts),
}),
WithChannelAddessable(),
Expand Down Expand Up @@ -2014,6 +2033,7 @@ func TestFinalizeKind(t *testing.T) {
BootstrapServers: ChannelBootstrapServers,
Reference: ChannelReference(),
Ingress: &contract.Ingress{
Path: receiver.Path(ChannelNamespace, ChannelName),
Host: receiver.Host(ChannelNamespace, ChannelName),
},
},
Expand Down
10 changes: 9 additions & 1 deletion control-plane/pkg/reconciler/channel/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func NewController(ctx context.Context, watcher configmap.Watcher, configs *conf

logger := logging.FromContext(ctx)

featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"))
featureStore.WatchConfigs(watcher)

_, err := reconciler.GetOrCreateDataPlaneConfigMap(ctx)
if err != nil {
logger.Fatal("Failed to get or create data plane config map",
Expand All @@ -96,7 +99,12 @@ func NewController(ctx context.Context, watcher configmap.Watcher, configs *conf
logger.Warn("Failed to get CA certs when at least one address uses TLS", zap.Error(err))
}

impl := kafkachannelreconciler.NewImpl(ctx, reconciler)
impl := kafkachannelreconciler.NewImpl(ctx, reconciler,
func(impl *controller.Impl) controller.Options {
return controller.Options{
ConfigStore: featureStore,
}
})
IPsLister := prober.IdentityIPsLister()
reconciler.IngressHost = network.GetServiceHostname(configs.IngressName, configs.SystemNamespace)
reconciler.Prober, err = prober.NewComposite(ctx, "", "", IPsLister, impl.EnqueueKey, &caCerts)
Expand Down
4 changes: 4 additions & 0 deletions control-plane/pkg/reconciler/channel/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ func TestNewController(t *testing.T) {
configmap.NewStaticWatcher(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: apisconfig.FlagsConfigName,
}}, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "config-features",
},
}),

configs,
)
if controller == nil {
Expand Down
13 changes: 11 additions & 2 deletions control-plane/pkg/reconciler/channel/resources/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ import (
)

const (
portName = "http"
portNumber = 80
portName = "http"
portNumber = 80

tlsPortName = "https"
tlsPortNumber = 443

MessagingRoleLabel = "messaging.knative.dev/role"
MessagingRole = "kafka-channel"

Expand Down Expand Up @@ -86,6 +90,11 @@ func MakeK8sService(kc *v1beta1.KafkaChannel, opts ...ServiceOption) (*corev1.Se
Protocol: corev1.ProtocolTCP,
Port: portNumber,
},
{
Name: tlsPortName,
Protocol: corev1.ProtocolTCP,
Port: tlsPortNumber,
},
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions control-plane/pkg/reconciler/testing/objects_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ func NewPerChannelService(env *config.Env) *corev1.Service {
Protocol: corev1.ProtocolTCP,
Port: 80,
},
{
Name: "https",
Protocol: corev1.ProtocolTCP,
Port: 443,
},
},
},
}
Expand Down
48 changes: 48 additions & 0 deletions test/e2e_new/channel_eventing_tls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//go:build e2e
// +build e2e

/*
* 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 e2e_new

import (
"testing"
"time"

"knative.dev/eventing-kafka-broker/test/rekt/features"
"knative.dev/pkg/system"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/knative"
)

func TestChannelTLSCARotation(t *testing.T) {
t.Parallel()

ctx, env := global.Environment(
knative.WithKnativeNamespace(system.Namespace()),
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
eventshub.WithTLS(t),
environment.WithPollTimings(5*time.Second, 4*time.Minute),
)

env.Test(ctx, t, features.RotateChannelTLSCertificates())
}
Loading

0 comments on commit 828b81e

Please sign in to comment.