Skip to content

Commit 53f6fa4

Browse files
Merge pull request #1617 from njhale/fix-e2e
test(e2e): patch installplans w/ server-side apply
2 parents 48951d3 + 456cb22 commit 53f6fa4

File tree

4 files changed

+273
-107
lines changed

4 files changed

+273
-107
lines changed

pkg/lib/testobj/runtime.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package testobj
22

33
import (
4+
"encoding/json"
45
"fmt"
56

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

103104
return out
104105
}
106+
107+
// MarshalJSON marshals an object to JSON and panics if it can't.
108+
func MarshalJSON(obj runtime.Object) (marshaled []byte) {
109+
var err error
110+
if marshaled, err = json.Marshal(obj); err != nil {
111+
panic(fmt.Sprintf("failed to marshal obj to json: %s", err))
112+
}
113+
114+
return
115+
}

test/e2e/ctx/ctx.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ import (
55
"strings"
66

77
. "github.com/onsi/ginkgo"
8+
"k8s.io/apimachinery/pkg/runtime"
89
"k8s.io/client-go/dynamic"
10+
kscheme "k8s.io/client-go/kubernetes/scheme"
911
"k8s.io/client-go/rest"
1012

13+
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
14+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
15+
operatorsv2alpha1 "github.com/operator-framework/api/pkg/operators/v2alpha1"
1116
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
1217
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1318
pversioned "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned"
19+
controllerclient "sigs.k8s.io/controller-runtime/pkg/client"
1420
)
1521

1622
var ctx TestContext
@@ -23,6 +29,11 @@ type TestContext struct {
2329
operatorClient versioned.Interface
2430
dynamicClient dynamic.Interface
2531
packageClient pversioned.Interface
32+
33+
scheme *runtime.Scheme
34+
35+
// client is the controller-runtime client -- we should use this from now on
36+
client controllerclient.Client
2637
}
2738

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

54+
func (ctx TestContext) Scheme() *runtime.Scheme {
55+
return ctx.scheme
56+
}
57+
4358
func (ctx TestContext) RESTConfig() *rest.Config {
4459
return ctx.restConfig
4560
}
@@ -60,6 +75,10 @@ func (ctx TestContext) PackageClient() pversioned.Interface {
6075
return ctx.packageClient
6176
}
6277

78+
func (ctx TestContext) Client() controllerclient.Client {
79+
return ctx.client
80+
}
81+
6382
func setDerivedFields(ctx *TestContext) error {
6483
if ctx == nil {
6584
return fmt.Errorf("nil test context")
@@ -93,5 +112,24 @@ func setDerivedFields(ctx *TestContext) error {
93112
}
94113
ctx.packageClient = packageClient
95114

115+
ctx.scheme = runtime.NewScheme()
116+
localSchemeBuilder := runtime.NewSchemeBuilder(
117+
kscheme.AddToScheme,
118+
operatorsv1alpha1.AddToScheme,
119+
operatorsv1.AddToScheme,
120+
operatorsv2alpha1.AddToScheme,
121+
)
122+
if err := localSchemeBuilder.AddToScheme(ctx.scheme); err != nil {
123+
return err
124+
}
125+
126+
client, err := controllerclient.New(ctx.restConfig, controllerclient.Options{
127+
Scheme: ctx.scheme,
128+
})
129+
if err != nil {
130+
return err
131+
}
132+
ctx.client = client
133+
96134
return nil
97135
}

0 commit comments

Comments
 (0)