Skip to content

Commit

Permalink
update to current reconciler-test release-1.11 (#499)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
maschmid and pierDipi authored Jan 24, 2024
1 parent e8eb184 commit dcc5a7b
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
knative.dev/hack v0.0.0-20230712131415-ddae80293c43
knative.dev/hack/schema v0.0.0-20230712131415-ddae80293c43
knative.dev/pkg v0.0.0-20231023150739-56bfe0dd9626
knative.dev/reconciler-test v0.0.0-20231024065608-1f72fcb94bc1
knative.dev/reconciler-test v0.0.0-20240118172306-00c4131cf6be
sigs.k8s.io/yaml v1.3.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,8 @@ knative.dev/hack/schema v0.0.0-20230712131415-ddae80293c43 h1:FqKKg9cUKc2I9bw27f
knative.dev/hack/schema v0.0.0-20230712131415-ddae80293c43/go.mod h1:GeIb+PLd5mllawcpHEGF5J5fYTQrvgEO5liao8lUKUs=
knative.dev/pkg v0.0.0-20231023150739-56bfe0dd9626 h1:qFE+UDBRg6cpF5LbA0sv1XK4XZ36Z7aTRCa+HcuxnNQ=
knative.dev/pkg v0.0.0-20231023150739-56bfe0dd9626/go.mod h1:g+UCgSKQ2f15kHYu/V3CPtoKo5F1x/2Y1ot0NSK7gA0=
knative.dev/reconciler-test v0.0.0-20231024065608-1f72fcb94bc1 h1:4++EB9KPIz9c/EzENw7rJxK74WTdREviBSTywS+rfz8=
knative.dev/reconciler-test v0.0.0-20231024065608-1f72fcb94bc1/go.mod h1:Yw7Jkv+7PjDitG6CUkakWc/5SZa8Tm/sgXfaFy305Ng=
knative.dev/reconciler-test v0.0.0-20240118172306-00c4131cf6be h1:22QG+BjSX3LK5rE+ID3iy3OpJOyvGIE6F4FATnL/Zi8=
knative.dev/reconciler-test v0.0.0-20240118172306-00c4131cf6be/go.mod h1:Yw7Jkv+7PjDitG6CUkakWc/5SZa8Tm/sgXfaFy305Ng=
pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
8 changes: 7 additions & 1 deletion vendor/knative.dev/reconciler-test/pkg/environment/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"fmt"
"strconv"
"strings"
"time"

"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/state"
)

var (
Expand All @@ -34,6 +36,9 @@ var (

ipFilePath = new(string)
teardownOnFail = new(bool)

pollTimeout = new(time.Duration)
pollInterval = new(time.Duration)
)

// InitFlags registers the requirement and state filter flags supported by the
Expand Down Expand Up @@ -62,7 +67,8 @@ func InitFlags(fs *flag.FlagSet) {

fs.StringVar(ipFilePath, "images.producer.file", "", "file path for file-based image producer")
fs.StringVar(testNamespace, "environment.namespace", "", "Test namespace")

fs.DurationVar(pollTimeout, "poll.timeout", state.DefaultPollTimeout, "Poll timeout")
fs.DurationVar(pollInterval, "poll.interval", state.DefaultPollInterval, "Poll interval")
fs.BoolVar(teardownOnFail, "teardown.on.fail", false, "Set this flag to do teardown even if test fails.")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (mr *MagicGlobalEnvironment) Environment(opts ...EnvOpts) (context.Context,
}

ctx := ContextWith(mr.c, env)
ctx = ContextWithPollTimings(ctx, *pollInterval, *pollTimeout)

for _, opt := range opts {
if nctx, err := opt(ctx, env); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (mr *MagicEnvironment) CreateNamespaceIfNeeded() error {
ObjectMeta: metav1.ObjectMeta{
Name: mr.namespace,
Annotations: map[string]string{},
Labels: map[string]string{
"app.kubernetes.io/component": "reconciler-test",
"app.kubernetes.io/name": "reconciler-test",
},
},
}

Expand Down
27 changes: 8 additions & 19 deletions vendor/knative.dev/reconciler-test/pkg/environment/timings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,26 @@ package environment
import (
"context"
"time"

"knative.dev/reconciler-test/pkg/state"
)

// this has been moved to state pkg to break cycle between environment and feature package,
// keeping the consts here for backwards API compatibility
const (
DefaultPollInterval = 3 * time.Second
DefaultPollTimeout = 2 * time.Minute
)

type timingsKey struct{}
type timingsType struct {
interval time.Duration
timeout time.Duration
}

// PollTimingsFromContext will get the previously set poll timing from context,
// or return the defaults if not found.
// - values from from context.
// - defaults.
// ContextWithPollTimings returns a context with poll timings set
func ContextWithPollTimings(ctx context.Context, interval, timeout time.Duration) context.Context {
return context.WithValue(ctx, timingsKey{}, timingsType{
interval: interval,
timeout: timeout,
})
return state.ContextWithPollTimings(ctx, interval, timeout)
}

// PollTimingsFromContext will get the previously set poll timing from context,
// or return the defaults if not found.
// - values from from context.
// - values from context.
// - defaults.
func PollTimingsFromContext(ctx context.Context) (time.Duration, time.Duration) {
if t, ok := ctx.Value(timingsKey{}).(timingsType); ok {
return t.interval, t.timeout
}
return DefaultPollInterval, DefaultPollTimeout
return state.PollTimingsFromContext(ctx)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ spec:
- 127.0.0.1

issuerRef:
{{ if .TLS_ISSUER_NAME }}
name: {{ .TLS_ISSUER_NAME }}
{{ else }}
name: selfsigned-ca-issuer
{{ end }}
{{ if .TLS_ISSUER_KIND }}
kind: {{ .TLS_ISSUER_KIND }}
{{ else }}
kind: Issuer
{{ end }}
group: cert-manager.io
7 changes: 7 additions & 0 deletions vendor/knative.dev/reconciler-test/pkg/eventshub/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ func StartSenderURLTLS(sink string, caCerts *string) EventsHubOption {
})
}

func IssuerRef(kind, name string) EventsHubOption {
return compose(
envAdditive(tlsIssuerKind, kind),
envAdditive(tlsIssuerName, name),
)
}

// --- Receiver options

// EchoEvent is an option to let the eventshub reply with the received event
Expand Down
6 changes: 6 additions & 0 deletions vendor/knative.dev/reconciler-test/pkg/eventshub/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func Install(name string, options ...EventsHubOption) feature.StepFn {
"withEnforceTLS": isEnforceTLS,
}

for k, v := range envs {
if strings.HasPrefix(k, "TLS_ISSUER") {
cfg[k] = v
}
}

// Install ServiceAccount, Role, RoleBinding
eventshubrbac.Install(cfg)(ctx, t)

Expand Down
4 changes: 3 additions & 1 deletion vendor/knative.dev/reconciler-test/pkg/eventshub/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const (
EventGeneratorsEnv = "EVENT_GENERATORS"
EventLogsEnv = "EVENT_LOGS"

EnforceTLS = "ENFORCE_TLS"
EnforceTLS = "ENFORCE_TLS"
tlsIssuerKind = "TLS_ISSUER_KIND"
tlsIssuerName = "TLS_ISSUER_NAME"
)

func ParseHeaders(serializedHeaders string) http.Header {
Expand Down
5 changes: 2 additions & 3 deletions vendor/knative.dev/reconciler-test/pkg/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"runtime"
"strings"
"sync"
"time"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -32,7 +31,6 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"knative.dev/pkg/apis"
"knative.dev/pkg/injection/clients/dynamicclient"

"knative.dev/reconciler-test/pkg/state"
)

Expand Down Expand Up @@ -229,7 +227,8 @@ func DeleteResources(ctx context.Context, t T, refs []corev1.ObjectReference) er

var lastResource corev1.ObjectReference // One still present resource

err := wait.Poll(time.Second, 4*time.Minute, func() (bool, error) {
interval, timeout := state.PollTimingsFromContext(ctx)
err := wait.Poll(interval, timeout, func() (bool, error) {
for _, ref := range refs {
gv, err := schema.ParseGroupVersion(ref.APIVersion)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func NewTracingGatherer(ctx context.Context, namespace string, zipkinNamespace s
kubeclient.Get(ctx),
logging.FromContext(ctx).Infof,
zipkinNamespace)
zipkin.ZipkinTracingEnabled = true
return &tracingEmitter{ctx: ctx, namespace: namespace, t: t}, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func Install(name string, options ...manifest.CfgFn) feature.StepFn {
type Assertion func(s *corev1.Secret) error

func IsPresent(name string, assertions ...Assertion) feature.StepFn {
return func(ctx context.Context, t feature.T) {
IsPresentInNamespace(name, environment.FromContext(ctx).Namespace(), assertions...)(ctx, t)
}
}

func IsPresentInNamespace(name string, ns string, assertions ...Assertion) feature.StepFn {
return func(ctx context.Context, t feature.T) {
ns := environment.FromContext(ctx).Namespace()
interval, timeout := environment.PollTimingsFromContext(ctx)
Expand Down
52 changes: 52 additions & 0 deletions vendor/knative.dev/reconciler-test/pkg/state/timings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2021 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 state

import (
"context"
"time"
)

const (
DefaultPollInterval = 3 * time.Second
DefaultPollTimeout = 2 * time.Minute
)

type timingsKey struct{}
type timingsType struct {
interval time.Duration
timeout time.Duration
}

// ContextWithPollTimings returns a context with poll timings set
func ContextWithPollTimings(ctx context.Context, interval, timeout time.Duration) context.Context {
return context.WithValue(ctx, timingsKey{}, timingsType{
interval: interval,
timeout: timeout,
})
}

// PollTimingsFromContext will get the previously set poll timing from context,
// or return the defaults if not found.
// - values from context.
// - defaults.
func PollTimingsFromContext(ctx context.Context) (time.Duration, time.Duration) {
if t, ok := ctx.Value(timingsKey{}).(timingsType); ok {
return t.interval, t.timeout
}
panic("no poll timings found in context")
}
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ knative.dev/pkg/webhook/resourcesemantics
knative.dev/pkg/webhook/resourcesemantics/conversion
knative.dev/pkg/webhook/resourcesemantics/defaulting
knative.dev/pkg/webhook/resourcesemantics/validation
# knative.dev/reconciler-test v0.0.0-20231024065608-1f72fcb94bc1
# knative.dev/reconciler-test v0.0.0-20240118172306-00c4131cf6be
## explicit; go 1.18
knative.dev/reconciler-test/cmd/eventshub
knative.dev/reconciler-test/pkg/environment
Expand Down

0 comments on commit dcc5a7b

Please sign in to comment.