Skip to content

test(e2e): patch installplans w/ server-side apply #1617

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

Merged
merged 1 commit into from
Jul 2, 2020
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
11 changes: 11 additions & 0 deletions pkg/lib/testobj/runtime.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testobj

import (
"encoding/json"
"fmt"

"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -102,3 +103,13 @@ func WithItems(list runtime.Object, items ...runtime.Object) runtime.Object {

return out
}

// MarshalJSON marshals an object to JSON and panics if it can't.
func MarshalJSON(obj runtime.Object) (marshaled []byte) {
var err error
if marshaled, err = json.Marshal(obj); err != nil {
panic(fmt.Sprintf("failed to marshal obj to json: %s", err))
}

return
}
38 changes: 38 additions & 0 deletions test/e2e/ctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import (
"strings"

. "github.com/onsi/ginkgo"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
kscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"

operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
operatorsv2alpha1 "github.com/operator-framework/api/pkg/operators/v2alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
pversioned "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned"
controllerclient "sigs.k8s.io/controller-runtime/pkg/client"
)

var ctx TestContext
Expand All @@ -23,6 +29,11 @@ type TestContext struct {
operatorClient versioned.Interface
dynamicClient dynamic.Interface
packageClient pversioned.Interface

scheme *runtime.Scheme

// client is the controller-runtime client -- we should use this from now on
client controllerclient.Client
}

// Ctx returns a pointer to the global test context. During parallel
Expand All @@ -40,6 +51,10 @@ func (ctx TestContext) Logf(f string, v ...interface{}) {
fmt.Fprintf(GinkgoWriter, f, v...)
}

func (ctx TestContext) Scheme() *runtime.Scheme {
return ctx.scheme
}

func (ctx TestContext) RESTConfig() *rest.Config {
return ctx.restConfig
}
Expand All @@ -60,6 +75,10 @@ func (ctx TestContext) PackageClient() pversioned.Interface {
return ctx.packageClient
}

func (ctx TestContext) Client() controllerclient.Client {
return ctx.client
}

func setDerivedFields(ctx *TestContext) error {
if ctx == nil {
return fmt.Errorf("nil test context")
Expand Down Expand Up @@ -93,5 +112,24 @@ func setDerivedFields(ctx *TestContext) error {
}
ctx.packageClient = packageClient

ctx.scheme = runtime.NewScheme()
localSchemeBuilder := runtime.NewSchemeBuilder(
kscheme.AddToScheme,
operatorsv1alpha1.AddToScheme,
operatorsv1.AddToScheme,
operatorsv2alpha1.AddToScheme,
)
if err := localSchemeBuilder.AddToScheme(ctx.scheme); err != nil {
return err
}

client, err := controllerclient.New(ctx.restConfig, controllerclient.Options{
Scheme: ctx.scheme,
})
if err != nil {
return err
}
ctx.client = client

return nil
}
Loading