func (t *Case) CollectEvents(namespace string) {
	cl, err := t.Client(false)
	if err != nil {
		t.Logger.Log("Failed to collect events for %s in ns %s: %v", t.Name, namespace, err)
		return
	}
	err = t.collectEventsBeta1(cl, namespace)
	if err != nil {
		t.Logger.Log("Trying with events eventsv1 API...")
		err = t.collectEventsV1(cl, namespace)
		if err != nil {
			t.Logger.Log("Trying with events corev1 API...")
			err = t.collectEventsCoreV1(cl, namespace)
			if err != nil {
				t.Logger.Log("All event APIs failed")
			}
		}
	}
}
CollectEvents gathers all events from namespace and prints it out to log
package test
import (
	"context"
	"fmt"
	"io/ioutil"
	"path/filepath"
	"regexp"
	"sort"
	"strconv"
	"testing"
	"time"
	petname "github.com/dustinkirkland/golang-petname"
	"github.com/thoas/go-funk"
	corev1 "k8s.io/api/core/v1"
	eventsv1 "k8s.io/api/events/v1"
	eventsbeta1 "k8s.io/api/events/v1beta1"
	"k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/discovery"
	"sigs.k8s.io/controller-runtime/pkg/client"
	"k8s.io/client-go/tools/clientcmd"
	"github.com/kudobuilder/kuttl/pkg/report"
	testutils "github.com/kudobuilder/kuttl/pkg/test/utils"
)
var testStepRegex = regexp.MustCompile(`^(\d+)-(?:[^\.]+)(?:\.yaml)?$`)
type Case struct {
	Steps              []*Step
	Name               string
	Dir                string
	SkipDelete         bool
	Timeout            int
	PreferredNamespace string
	Client          func(forceNew bool) (client.Client, error)
	DiscoveryClient func() (discovery.DiscoveryInterface, error)
	Logger testutils.Logger
	Suppress []string
}
type namespace struct {
	Name        string
	AutoCreated bool
}
func (t *Case) DeleteNamespace(cl client.Client, ns *namespace) error {
	if !ns.AutoCreated {
		t.Logger.Log("Skipping deletion of user-supplied namespace:", ns.Name)
		return nil
	}
	t.Logger.Log("Deleting namespace:", ns.Name)
	ctx := context.Background()
	if t.Timeout > 0 {
		var cancel context.CancelFunc
		ctx, cancel = context.WithTimeout(ctx, time.Duration(t.Timeout)*time.Second)
		defer cancel()
	}
	return cl.Delete(ctx, &corev1.Namespace{
		ObjectMeta: metav1.ObjectMeta{
			Name: ns.Name,
		},
		TypeMeta: metav1.TypeMeta{
			Kind: "Namespace",
		},
	})
}
func (t *Case) CreateNamespace(cl client.Client, ns *namespace) error {
	if !ns.AutoCreated {
		t.Logger.Log("Skipping creation of user-supplied namespace:", ns.Name)
		return nil
	}
	t.Logger.Log("Creating namespace:", ns.Name)
	ctx := context.Background()
	if t.Timeout > 0 {
		var cancel context.CancelFunc
		ctx, cancel = context.WithTimeout(ctx, time.Duration(t.Timeout)*time.Second)
		defer cancel()
	}
	return cl.Create(ctx, &corev1.Namespace{
		ObjectMeta: metav1.ObjectMeta{
			Name: ns.Name,
		},
		TypeMeta: metav1.TypeMeta{
			Kind: "Namespace",
		},
	})
}
func (t *Case) NamespaceExists(namespace string) (bool, error) {
	cl, err := t.Client(false)
	if err != nil {
		return false, err
	}
	ns := &corev1.Namespace{}
	err = cl.Get(context.TODO(), client.ObjectKey{Name: namespace}, ns)
	if err != nil && !errors.IsNotFound(err) {
		return false, err
	}
	return ns.Name == namespace, nil
}
type byFirstTimestamp []eventsbeta1.Event
func (o byFirstTimestamp) Len() int      { return len(o) }
func (o byFirstTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o byFirstTimestamp) Less(i, j int) bool {
	if o[i].ObjectMeta.CreationTimestamp.Equal(&o[j].ObjectMeta.CreationTimestamp) {
		return o[i].Name < o[j].Name
	}
	return o[i].ObjectMeta.CreationTimestamp.Before(&o[j].ObjectMeta.CreationTimestamp)
}
type byFirstTimestampV1 []eventsv1.Event
func (o byFirstTimestampV1) Len() int      { return len(o) }
func (o byFirstTimestampV1) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o byFirstTimestampV1) Less(i, j int) bool {
	if o[i].ObjectMeta.CreationTimestamp.Equal(&o[j].ObjectMeta.CreationTimestamp) {
		return o[i].Name < o[j].Name
	}
	return o[i].ObjectMeta.CreationTimestamp.Before(&o[j].ObjectMeta.CreationTimestamp)
}
type byFirstTimestampCoreV1 []corev1.Event
func (o byFirstTimestampCoreV1) Len() int      { return len(o) }
func (o byFirstTimestampCoreV1) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o byFirstTimestampCoreV1) Less(i, j int) bool {
	if o[i].ObjectMeta.CreationTimestamp.Equal(&o[j].ObjectMeta.CreationTimestamp) {
		return o[i].Name < o[j].Name
	}
	return o[i].ObjectMeta.CreationTimestamp.Before(&o[j].ObjectMeta.CreationTimestamp)
}