func (c *Context) CheckCR(validationFuncs ...func(interface{}) bool) {
	name := c.CR.GetName()
	f := c.F
	gi.By("Checking the CR for " + f.typename + " name: " + name)
	err := wait.Poll(5000*time.Millisecond, c.timeout*time.Second, func() (bool, error) {
		err := f.client.Get(context.Background(), types.NamespacedName{Name: name, Namespace: c.CR.GetNamespace()}, c.CR.(runtime.Object))
		if err != nil {
			if errors.IsNotFound(err) {
				return false, nil
			}
			return false, err
		}
		for _, fn := range validationFuncs {
			if !fn(c.CR) {
				return false, nil
			}
		}
		return true, nil
	})
	if err != nil {
		g.Expect(err).NotTo(g.HaveOccurred(), "failed to check the CustomResource: %s, %v", name, err)
	}
}
CheckCR syncs to latest CR in api server
package test
import (
	"context"
	"flag"
	"fmt"
	"time"
	gi "github.com/onsi/ginkgo"
	g "github.com/onsi/gomega"
	appsv1 "k8s.io/api/apps/v1"
	corev1 "k8s.io/api/core/v1"
	apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
	"k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/apimachinery/pkg/util/yaml"
	"sigs.k8s.io/controller-runtime/pkg/client"
	"sigs.k8s.io/controller-runtime/pkg/client/config"
	"sigs.k8s.io/controller-runtime/pkg/manager"
)
const ()
var (
	ns = flag.String("namespace", "", "e2e test namespace")
)
type Framework struct {
	typename  string
	Namespace string
	mgr       manager.Manager
	stopCh    chan struct{}
	client    client.Client
}
type Context struct {
	CR      metav1.Object
	timeout time.Duration
	F       *Framework
}
func New(typename string) *Framework {
	gi.By("Initializing the framework")
	flag.Parse()
	cfg, err := config.GetConfig()
	g.Expect(err).NotTo(g.HaveOccurred(), "failed to get config: %v", err)
	mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: "0"})
	g.Expect(err).NotTo(g.HaveOccurred(), "failed to create manager: %v", err)
	err = apiextensionsv1beta1.AddToScheme(mgr.GetScheme())
	g.Expect(err).NotTo(g.HaveOccurred(), "failed to initialize the Framework: %v", err)
	namespace := *ns
	if namespace == "" {
		namespace = "default"
	}
	return &Framework{
		typename:  typename,
		Namespace: namespace,
		mgr:       mgr,
		client:    mgr.GetClient(),
		stopCh:    make(chan struct{}),
	}
}
func (f *Framework) NewContext() *Context {
	return &Context{
		F:       f,
		timeout: 120,
	}
}
func (c *Context) WithCR(cr metav1.Object) *Context {
	c.CR = cr
	c.CR.SetNamespace(c.F.Namespace)
	return c
}
func (c *Context) WithTimeout(t time.Duration) *Context {
	c.timeout = t
	return c
}
func (f *Framework) GetScheme() *runtime.Scheme {
	return f.mgr.GetScheme()
}
func (f *Framework) Start() {
	go f.mgr.Start(f.stopCh)
}
func (f *Framework) Stop() {
	gi.By("Tearing down the Framework")
	defer close(f.stopCh)
}
func (c *Context) DeleteCR() {
	err := c.F.client.Delete(context.Background(), c.CR.(runtime.Object))
	g.Expect(err).NotTo(g.HaveOccurred(), "failed to delete CR %s: %v", c.CR.GetName(), err)
}
func (c *Context) UpdateCR() {
	err := c.F.client.Update(context.Background(), c.CR.(runtime.Object))
	g.Expect(err).NotTo(g.HaveOccurred(), "failed to update CR %s: %v", c.CR.GetName(), err)
}
func (c *Context) RefreshCR() {
	err := c.F.client.Get(context.Background(), types.NamespacedName{Name: c.CR.GetName(), Namespace: c.CR.GetNamespace()}, c.CR.(runtime.Object))
	g.Expect(err).NotTo(g.HaveOccurred(), "failed to refresh CR %s: %v", c.CR.GetName(), err)
}