Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knative port sink binding v1 deployment test to rekt #6479

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions test/e2e/source_sinkbinding_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"

. "github.com/cloudevents/sdk-go/v2/test"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
duckv1 "knative.dev/pkg/apis/duck/v1"
Expand All @@ -42,90 +41,6 @@ import (
rttestingv1 "knative.dev/eventing/pkg/reconciler/testing/v1"
)

func TestSinkBindingV1Deployment(t *testing.T) {
const (
sinkBindingName = "e2e-sink-binding"
deploymentName = "e2e-sink-binding-deployment"
// the heartbeats image is built from test_images/heartbeats
imageName = "heartbeats"

recordEventPodName = "e2e-sink-binding-recordevent-pod-v1beta1dep"
)

client := setup(t, true)
defer tearDown(client)

ctx := context.Background()

// create event logger pod and service
eventTracker, _ := recordevents.StartEventRecordOrFail(ctx, client, recordEventPodName)
extensionSecret := string(uuid.NewUUID())

// create sink binding
sinkBinding := rttestingv1.NewSinkBinding(
sinkBindingName,
client.Namespace,
rttestingv1.WithSink(duckv1.Destination{Ref: resources.KnativeRefForService(recordEventPodName, client.Namespace)}),
rttestingv1.WithSubject(tracker.Reference{
APIVersion: "apps/v1",
Kind: "Deployment",
Namespace: client.Namespace,
Name: deploymentName,
}),
rttestingv1.WithCloudEventOverrides(duckv1.CloudEventOverrides{Extensions: map[string]string{
"sinkbinding": extensionSecret,
}}),
)
client.CreateSinkBindingV1OrFail(sinkBinding)

message := fmt.Sprintf("msg %s for TestSinkBindingDeployment", uuid.NewUUID())
client.CreateDeploymentOrFail(&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: client.Namespace,
Name: deploymentName,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"foo": "bar",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: imageName,
Image: pkgTest.ImagePath(imageName),
ImagePullPolicy: corev1.PullIfNotPresent,
Args: []string{"--msg=" + message},
Env: []corev1.EnvVar{{
Name: "POD_NAME",
Value: deploymentName,
}, {
Name: "POD_NAMESPACE",
Value: client.Namespace,
}},
}},
},
},
},
})

// wait for all test resources to be ready
client.WaitForAllTestResourcesReadyOrFail(ctx)

// Look for events with expected data, and sinkbinding extension
eventTracker.AssertAtLeast(2, recordevents.MatchEvent(
recordevents.MatchHeartBeatsImageMessage(message),
HasSource(fmt.Sprintf("https://knative.dev/eventing/test/heartbeats/#%s/%s", client.Namespace, deploymentName)),
HasExtension("sinkbinding", extensionSecret),
))
}

func TestSinkBindingV1CronJob(t *testing.T) {
const (
sinkBindingName = "e2e-sink-binding"
Expand Down
60 changes: 60 additions & 0 deletions test/rekt/features/sinkbinding/feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2022 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 sinkbinding

import (
"github.com/cloudevents/sdk-go/v2/test"
"k8s.io/apimachinery/pkg/util/uuid"
"knative.dev/eventing/test/rekt/resources/deployment"
"knative.dev/eventing/test/rekt/resources/sinkbinding"
"knative.dev/reconciler-test/pkg/eventshub"
eventasssert "knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/resources/svc"
)

func SinkBindingV1Deployment() *feature.Feature {
sbinding := feature.MakeRandomK8sName("sinkbinding")
sink := feature.MakeRandomK8sName("sink")
subject := feature.MakeRandomK8sName("subject")
extensionSecret := string(uuid.NewUUID())

f := feature.NewFeatureNamed("SinkBinding V1 Deployment test")

f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))
f.Setup("install a deployment", deployment.Install(subject))

extensions := map[string]string{
"sinkbinding": extensionSecret,
}

cfg := []manifest.CfgFn{
sinkbinding.WithExtensions(extensions),
}

f.Setup("install SinkBinding", sinkbinding.Install(sbinding, svc.AsDestinationRef(sink), deployment.AsTrackerReference(subject), cfg...))
f.Setup("SinkBinding goes ready", sinkbinding.IsReady(sbinding))

f.Stable("ApiServerSource as event source").
Must("delivers events",
eventasssert.OnStore(sink).MatchEvent(
test.HasExtension("sinkbinding", extensionSecret),
).AtLeast(1))

return f
}
6 changes: 3 additions & 3 deletions test/rekt/resources/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ var yaml embed.FS
func Install(name string) feature.StepFn {
cfg := map[string]interface{}{
"name": name,
"selectors": map[string]string{"app": name}, // default
"image": "gcr.io/knative-samples/helloworld-go", // default
"port": 8080, // default
"selectors": map[string]string{"app": name}, // default
"image": "gcr.io/knative-nightly/knative.dev/eventing/cmd/heartbeats", // default
"port": 8080, // default
}

return func(ctx context.Context, t feature.T) {
Expand Down
6 changes: 6 additions & 0 deletions test/rekt/resources/deployment/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ spec:
image: {{ .image }}
ports:
- containerPort: {{ .port }}
env:
- name: POD_NAME
value: heartbeats
- name: POD_NAMESPACE
value: {{ .namespace }}

6 changes: 6 additions & 0 deletions test/rekt/resources/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Example() {
}

files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg)

if err != nil {
panic(err)
}
Expand All @@ -64,4 +65,9 @@ func Example() {
// image: gcr.io/knative-samples/helloworld-go
// ports:
// - containerPort: 8080
// env:
// - name: POD_NAME
// value: heartbeats
// - name: POD_NAMESPACE
// value: bar
}
2 changes: 1 addition & 1 deletion test/rekt/resources/sinkbinding/sinkbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func WithExtensions(extensions map[string]string) manifest.CfgFn {

if extensions != nil {
if _, set := ceOverrides["extensions"]; !set {
ceOverrides["ref"] = map[string]interface{}{}
ceOverrides["extensions"] = map[string]interface{}{}
}
ceExt := ceOverrides["extensions"].(map[string]interface{})
for k, v := range extensions {
Expand Down
40 changes: 13 additions & 27 deletions test/rekt/sink_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,23 @@ import (
"testing"

"knative.dev/eventing/test/rekt/features/sinkbinding"
"knative.dev/eventing/test/rekt/resources/deployment"
sb "knative.dev/eventing/test/rekt/resources/sinkbinding"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/resources/svc"
"knative.dev/pkg/system"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/knative"
)

// TestSmoke_SinkBinding
func TestSmoke_SinkBinding(t *testing.T) {
func TestSinkBindingV1Deployment(t *testing.T) {
t.Parallel()

ctx, env := global.Environment()
ctx, env := global.Environment(
knative.WithKnativeNamespace(system.Namespace()),
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
)
t.Cleanup(env.Finish)

names := []string{
"customname",
"name-with-dash",
"name1with2numbers3",
"name63-01234567890123456789012345678901234567890123456789012345",
}

for _, name := range names {
f := sinkbinding.GoesReady(name)

sink := feature.MakeRandomK8sName("sink")
f.Setup("install a service", svc.Install(sink, "app", "rekt"))

subject := feature.MakeRandomK8sName("subject")
f.Setup("install a deployment", deployment.Install(subject))

f.Setup("install a sinkbinding", sb.Install(name, svc.AsDestinationRef(sink), deployment.AsTrackerReference(subject)))

env.Test(ctx, t, f)
}
env.Test(ctx, t, sinkbinding.SinkBindingV1Deployment())
}
43 changes: 37 additions & 6 deletions test/rekt/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@ import (
"testing"

"k8s.io/utils/pointer"
_ "knative.dev/pkg/system/testing"

"knative.dev/reconciler-test/pkg/manifest"

eventingduck "knative.dev/eventing/pkg/apis/duck/v1"
"knative.dev/eventing/test/rekt/features/apiserversource"
"knative.dev/eventing/test/rekt/features/broker"
"knative.dev/eventing/test/rekt/features/containersource"
"knative.dev/eventing/test/rekt/features/parallel"
"knative.dev/eventing/test/rekt/features/pingsource"
"knative.dev/eventing/test/rekt/features/sequence"
"knative.dev/eventing/test/rekt/features/sinkbinding"
b "knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/channel_impl"
"knative.dev/eventing/test/rekt/resources/delivery"
"knative.dev/eventing/test/rekt/resources/deployment"
presources "knative.dev/eventing/test/rekt/resources/parallel"
ps "knative.dev/eventing/test/rekt/resources/pingsource"
sresources "knative.dev/eventing/test/rekt/resources/sequence"

presources "knative.dev/eventing/test/rekt/resources/parallel"
sb "knative.dev/eventing/test/rekt/resources/sinkbinding"
_ "knative.dev/pkg/system/testing"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/resources/svc"
)

// TestSmoke_Broker
Expand Down Expand Up @@ -272,3 +274,32 @@ func SpecDelivery(spec map[string]interface{}) {
linear := eventingduck.BackoffPolicyLinear
delivery.WithRetry(10, &linear, pointer.StringPtr("PT1S"))(spec)
}

// TestSmoke_SinkBinding
func TestSmoke_SinkBinding(t *testing.T) {
t.Parallel()

ctx, env := global.Environment()
t.Cleanup(env.Finish)

names := []string{
"customname",
"name-with-dash",
"name1with2numbers3",
"name63-01234567890123456789012345678901234567890123456789012345",
}

for _, name := range names {
f := sinkbinding.GoesReady(name)

sink := feature.MakeRandomK8sName("sink")
f.Setup("install a service", svc.Install(sink, "app", "rekt"))

subject := feature.MakeRandomK8sName("subject")
f.Setup("install a deployment", deployment.Install(subject))

f.Setup("install a sinkbinding", sb.Install(name, svc.AsDestinationRef(sink), deployment.AsTrackerReference(subject)))

env.Test(ctx, t, f)
}
}