Skip to content

Commit

Permalink
Align to 1.1... manually, again (#1607)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew authored Dec 14, 2021
1 parent 3f14b14 commit 129af86
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 329 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009
knative.dev/eventing v0.28.0
knative.dev/eventing-kafka v0.28.0
knative.dev/hack v0.0.0-20211210083629-92d8a0a00cb6
knative.dev/pkg v0.0.0-20211214124451-fe5b178f358f
knative.dev/reconciler-test v0.0.0-20211213105719-9cdcfcc2f3fd
knative.dev/hack v0.0.0-20211203062838-e11ac125e707
knative.dev/pkg v0.0.0-20211206113427-18589ac7627e
knative.dev/reconciler-test v0.0.0-20211207070557-0d138a88867b
)
9 changes: 3 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1332,16 +1332,13 @@ knative.dev/eventing v0.28.0/go.mod h1:zxoB37kQxEkfCvKA7wZuHOPYInz6SFJzrhmG9IAd/
knative.dev/eventing-kafka v0.28.0 h1:mJs8G0va7mYli/aQ4PO644zXjeVNHRUl4nCSr5qxu0M=
knative.dev/eventing-kafka v0.28.0/go.mod h1:/AYX5c6EhXGCQrTVDazkbGnsEPYdKfkW1JNE7D/cT9I=
knative.dev/hack v0.0.0-20211122162614-813559cefdda/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20211203062838-e11ac125e707 h1:Nx3HBoTHjYzXT9xxh5j6A8pMapNqyDLqjl784YxWPDQ=
knative.dev/hack v0.0.0-20211203062838-e11ac125e707/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20211210083629-92d8a0a00cb6 h1:31f2yC4ILoJ8l1wyGdYzOEkfjvrZ6LMSk4/MlbcHl/M=
knative.dev/hack v0.0.0-20211210083629-92d8a0a00cb6/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack/schema v0.0.0-20211203062838-e11ac125e707/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
knative.dev/pkg v0.0.0-20211206113427-18589ac7627e h1:8hK7g4jz56ZtF3iQLsvrvR/hHnP5ZWLSxLnyYMbfxwY=
knative.dev/pkg v0.0.0-20211206113427-18589ac7627e/go.mod h1:E6B4RTjZyxe55a0kxOlnEHEl71zuG7gghnqYvNBKwBw=
knative.dev/pkg v0.0.0-20211214124451-fe5b178f358f h1:EtH8Bzm8R+DhBuz/hW1u/cdasbXCCGV+RabHxT0jY2c=
knative.dev/pkg v0.0.0-20211214124451-fe5b178f358f/go.mod h1:hrD91/shO1o4KMZa4oWhnbRPmVJhvq86TLy/STF/qf8=
knative.dev/reconciler-test v0.0.0-20211207070557-0d138a88867b h1:qdT9bpo7TaMM5ol8cEnjrzSINCAiJNWruOFauUQreu8=
knative.dev/reconciler-test v0.0.0-20211207070557-0d138a88867b/go.mod h1:dCq1Fuu+eUISdnxABMvoDhefF91DYwE6O3rTYTraXbw=
knative.dev/reconciler-test v0.0.0-20211213105719-9cdcfcc2f3fd h1:r6UffzGaWFldibbODOT6qWwg5J/MxCihu8WuDP3r8BU=
knative.dev/reconciler-test v0.0.0-20211213105719-9cdcfcc2f3fd/go.mod h1:dCq1Fuu+eUISdnxABMvoDhefF91DYwE6O3rTYTraXbw=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
Expand Down
23 changes: 19 additions & 4 deletions vendor/knative.dev/pkg/test/monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net"
"os"
"os/exec"
"strings"
"time"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -74,11 +75,25 @@ func Cleanup(pid int) error {
// PortForward sets up local port forward to the pod specified by the "app" label in the given namespace
func PortForward(logf logging.FormatLogger, podList *v1.PodList, localPort, remotePort int, namespace string) (int, error) {
podName := podList.Items[0].Name
cmd := exec.Command("kubectl", "port-forward", podName, fmt.Sprintf("%d:%d", localPort, remotePort), "-n", namespace)
if err := cmd.Start(); err != nil {
portFwdCmd := fmt.Sprintf("kubectl port-forward %s %d:%d -n %s", podName, localPort, remotePort, namespace)
portFwdProcess, err := executeCmdBackground(logf, portFwdCmd)

if err != nil {
return 0, fmt.Errorf("failed to port forward: %w", err)
}

logf("Running %s port-forward in background, pid = %d", podName, cmd.Process.Pid)
return cmd.Process.Pid, nil
logf("Running %s port-forward in background, pid = %d", podName, portFwdProcess.Pid)
return portFwdProcess.Pid, nil
}

// RunBackground starts a background process and returns the Process if succeed
func executeCmdBackground(logf logging.FormatLogger, format string, args ...interface{}) (*os.Process, error) {
cmd := fmt.Sprintf(format, args...)
logf("Executing command: %s", cmd)
parts := strings.Split(cmd, " ")
c := exec.Command(parts[0], parts[1:]...) // #nosec
if err := c.Start(); err != nil {
return nil, fmt.Errorf("%s command failed: %w", cmd, err)
}
return c.Process, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

corev1 "k8s.io/api/core/v1"

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

Expand Down
17 changes: 5 additions & 12 deletions vendor/knative.dev/reconciler-test/pkg/environment/magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ type MagicEnvironment struct {

// milestones sends milestone events, if configured.
milestones milestone.Emitter

// managedT is used for test-scoped logging, if configured.
managedT feature.T
}

const (
Expand All @@ -88,13 +85,11 @@ func (mr *MagicEnvironment) References() []corev1.ObjectReference {
}

func (mr *MagicEnvironment) Finish() {
// Delete the namespace after sending the Finished milestone event
// since emitters might use the namespace.
mr.milestones.Finished()
if err := mr.DeleteNamespaceIfNeeded(); err != nil {
mr.milestones.Exception(NamespaceDeleteErrorReason, "failed to delete namespace %q, %v", mr.namespace, err)
panic(err)
}
mr.milestones.Finished()
}

// WithPollTimings is an environment option to override default poll timings.
Expand All @@ -108,9 +103,6 @@ func WithPollTimings(interval, timeout time.Duration) EnvOpts {
// - registers a t.Cleanup callback on env.Finish().
func Managed(t feature.T) EnvOpts {
return func(ctx context.Context, env Environment) (context.Context, error) {
if e, ok := env.(*MagicEnvironment); ok {
e.managedT = t
}
t.Cleanup(env.Finish)
return ctx, nil
}
Expand Down Expand Up @@ -145,13 +137,14 @@ func (mr *MagicGlobalEnvironment) Environment(opts ...EnvOpts) (context.Context,
// It is possible to have milestones set in the options, check for nil in
// env first before attempting to pull one from the os environment.
if env.milestones == nil {
eventEmitter, err := milestone.NewMilestoneEmitterFromEnv(mr.instanceID, namespace)
milestones, err := milestone.NewMilestoneEmitterFromEnv(mr.instanceID, namespace)
if err != nil {
// This is just an FYI error, don't block the test run.
logging.FromContext(mr.c).Error("failed to create the milestone event sender", zap.Error(err))
}
logEmitter := milestone.NewLogEmitter(ctx, namespace, env.managedT)
env.milestones = milestone.Compose(eventEmitter, logEmitter)
if milestones != nil {
env.milestones = milestones
}
}

if err := env.CreateNamespaceIfNeeded(); err != nil {
Expand Down
44 changes: 10 additions & 34 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 (
"strings"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -104,48 +103,25 @@ func (f *Feature) References() []corev1.ObjectReference {
return f.refs
}

// DeleteResources delete all known resources to the Feature registered
// via `Reference`.
//
// It doesn't fail when a referenced resource couldn't be deleted.
// Use References to get the undeleted resources.
//
// Expected to be used as a StepFn.
// DeleteResourcesFn delete all known resources to the Feature registered
// via `Reference`. Expected to be used as a StepFn.
func (f *Feature) DeleteResources(ctx context.Context, t T) {
// refFailedDeletion keeps the failed to delete resources.
var refFailedDeletion []corev1.ObjectReference
dc := dynamicclient.Get(ctx)
for _, ref := range f.References() {

gv, err := schema.ParseGroupVersion(ref.APIVersion)
if err != nil {
t.Fatalf("Could not parse GroupVersion for %+v", ref.APIVersion)
}

resource := apis.KindToResource(gv.WithKind(ref.Kind))
t.Logf("Deleting %s/%s of GVR: %+v", ref.Namespace, ref.Name, resource)

// Delete immediately, grace period is 0.
deleteOptions := metav1.NewDeleteOptions(0)
// Set delete propagation policy to foreground
foregroundDeletePropagation := metav1.DeletePropagationForeground
deleteOptions.PropagationPolicy = &foregroundDeletePropagation

err = dc.Resource(resource).Namespace(ref.Namespace).Delete(ctx, ref.Name, *deleteOptions)
// Ignore not found errors.
if err != nil && !apierrors.IsNotFound(err) {
refFailedDeletion = append(refFailedDeletion, ref)
t.Logf("Warning, failed to delete %s/%s of GVR: %+v: %v", ref.Namespace, ref.Name, resource, err)
t.Errorf("Could not parse GroupVersion for %+v", ref.APIVersion)
} else {
resource := apis.KindToResource(gv.WithKind(ref.Kind))
t.Logf("Deleting %s/%s of GVR: %+v", ref.Namespace, ref.Name, resource)
if err := dc.Resource(resource).Namespace(ref.Namespace).Delete(ctx, ref.Name, *metav1.NewDeleteOptions(0)); err != nil {
t.Logf("Warning, failed to delete %s/%s of GVR: %+v", ref.Namespace, ref.Name, resource)
}
}
}
f.refs = refFailedDeletion
f.refs = []corev1.ObjectReference(nil)
}

var (
// Expected to be used as a StepFn.
_ StepFn = (&Feature{}).DeleteResources
)

// Setup adds a step function to the feature set at the Setup timing phase.
func (f *Feature) Setup(name string, fn StepFn) {
f.AddStep(Step{
Expand Down

This file was deleted.

Loading

0 comments on commit 129af86

Please sign in to comment.