Skip to content

Commit 1476359

Browse files
committed
ADD scheme package for AddToScheme
1 parent 265d60d commit 1476359

File tree

5 files changed

+38
-60
lines changed

5 files changed

+38
-60
lines changed

cmd/manager/main.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,26 @@ import (
2323
"time"
2424

2525
"github.com/spf13/pflag"
26-
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
2726
"go.uber.org/zap/zapcore"
28-
"k8s.io/apimachinery/pkg/runtime"
29-
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
30-
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3127
_ "k8s.io/client-go/plugin/pkg/client/auth"
3228
ctrl "sigs.k8s.io/controller-runtime"
3329
"sigs.k8s.io/controller-runtime/pkg/healthz"
3430
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3531
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3632

37-
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
3833
"github.com/operator-framework/deppy/pkg/deppy/solver"
39-
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
4034

41-
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
4235
"github.com/operator-framework/operator-controller/internal/catalogmetadata/cache"
4336
catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
4437
"github.com/operator-framework/operator-controller/internal/controllers"
4538
"github.com/operator-framework/operator-controller/pkg/features"
39+
"github.com/operator-framework/operator-controller/pkg/scheme"
4640
)
4741

4842
var (
49-
scheme = runtime.NewScheme()
5043
setupLog = ctrl.Log.WithName("setup")
5144
)
5245

53-
func init() {
54-
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
55-
56-
utilruntime.Must(ocv1alpha1.AddToScheme(scheme))
57-
utilruntime.Must(rukpakv1alpha2.AddToScheme(scheme))
58-
utilruntime.Must(catalogd.AddToScheme(scheme))
59-
utilruntime.Must(carvelv1alpha1.AddToScheme(scheme))
60-
61-
//+kubebuilder:scaffold:scheme
62-
}
63-
6446
func main() {
6547
var (
6648
metricsAddr string
@@ -86,7 +68,7 @@ func main() {
8668
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts), zap.StacktraceLevel(zapcore.DPanicLevel)))
8769

8870
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
89-
Scheme: scheme,
71+
Scheme: scheme.Scheme,
9072
Metrics: server.Options{BindAddress: metricsAddr},
9173
HealthProbeBindAddress: probeAddr,
9274
LeaderElection: enableLeaderElection,

internal/catalogmetadata/client/client_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111

1212
"github.com/stretchr/testify/assert"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
"k8s.io/apimachinery/pkg/runtime"
15-
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1614
"sigs.k8s.io/controller-runtime/pkg/client"
1715
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1816

@@ -22,17 +20,9 @@ import (
2220

2321
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
2422
catalogClient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
23+
"github.com/operator-framework/operator-controller/pkg/scheme"
2524
)
2625

27-
var (
28-
scheme *runtime.Scheme
29-
)
30-
31-
func init() {
32-
scheme = runtime.NewScheme()
33-
utilruntime.Must(catalogd.AddToScheme(scheme))
34-
}
35-
3626
func TestClient(t *testing.T) {
3727
t.Run("Bundles", func(t *testing.T) {
3828
for _, tt := range []struct {
@@ -172,7 +162,7 @@ func TestClient(t *testing.T) {
172162
tt.fetcher.contentMap = catalogContentMap
173163

174164
fakeCatalogClient := catalogClient.New(
175-
fake.NewClientBuilder().WithScheme(scheme).WithObjects(objs...).Build(),
165+
fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(objs...).Build(),
176166
tt.fetcher,
177167
)
178168

internal/controllers/suite_test.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,20 @@ import (
2323
"testing"
2424

2525
"github.com/stretchr/testify/require"
26-
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
27-
corev1 "k8s.io/api/core/v1"
28-
"k8s.io/apimachinery/pkg/runtime"
2926
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3027
"k8s.io/client-go/rest"
3128
"sigs.k8s.io/controller-runtime/pkg/client"
3229
"sigs.k8s.io/controller-runtime/pkg/envtest"
3330

3431
"github.com/operator-framework/deppy/pkg/deppy/solver"
35-
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
3632

37-
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
3833
"github.com/operator-framework/operator-controller/internal/controllers"
34+
"github.com/operator-framework/operator-controller/pkg/scheme"
3935
testutil "github.com/operator-framework/operator-controller/test/util"
4036
)
4137

4238
func newClient(t *testing.T) client.Client {
43-
cl, err := client.New(cfg, client.Options{Scheme: sch})
39+
cl, err := client.New(cfg, client.Options{Scheme: scheme.Scheme})
4440
require.NoError(t, err)
4541
require.NotNil(t, cl)
4642
return cl
@@ -55,7 +51,7 @@ func newClientAndReconciler(t *testing.T) (client.Client, *controllers.ClusterEx
5551
reconciler := &controllers.ClusterExtensionReconciler{
5652
Client: cl,
5753
BundleProvider: &fakeCatalogClient,
58-
Scheme: sch,
54+
Scheme: scheme.Scheme,
5955
Resolver: resolver,
6056
}
6157
return cl, reconciler
@@ -72,7 +68,6 @@ func newClientAndExtensionReconciler(t *testing.T) (client.Client, *controllers.
7268
}
7369

7470
var (
75-
sch *runtime.Scheme
7671
cfg *rest.Config
7772
)
7873

@@ -91,12 +86,6 @@ func TestMain(m *testing.M) {
9186
log.Panic("expected cfg to not be nil")
9287
}
9388

94-
sch = runtime.NewScheme()
95-
utilruntime.Must(ocv1alpha1.AddToScheme(sch))
96-
utilruntime.Must(rukpakv1alpha2.AddToScheme(sch))
97-
utilruntime.Must(corev1.AddToScheme(sch))
98-
utilruntime.Must(carvelv1alpha1.AddToScheme(sch))
99-
10089
code := m.Run()
10190
utilruntime.Must(testEnv.Stop())
10291
os.Exit(code)

pkg/scheme/scheme.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package scheme
2+
3+
import (
4+
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
5+
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
6+
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
7+
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
8+
appsv1 "k8s.io/api/apps/v1"
9+
corev1 "k8s.io/api/core/v1"
10+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
11+
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
12+
13+
"k8s.io/apimachinery/pkg/runtime"
14+
)
15+
16+
var Scheme = runtime.NewScheme()
17+
18+
func init() {
19+
20+
utilruntime.Must(clientgoscheme.AddToScheme(Scheme))
21+
utilruntime.Must(ocv1alpha1.AddToScheme(Scheme))
22+
utilruntime.Must(rukpakv1alpha2.AddToScheme(Scheme))
23+
utilruntime.Must(catalogd.AddToScheme(Scheme))
24+
utilruntime.Must(carvelv1alpha1.AddToScheme(Scheme))
25+
utilruntime.Must(appsv1.AddToScheme(Scheme))
26+
utilruntime.Must(corev1.AddToScheme(Scheme))
27+
//+kubebuilder:scaffold:scheme
28+
29+
}

test/e2e/e2e_suite_test.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ import (
55
"os"
66
"testing"
77

8-
appsv1 "k8s.io/api/apps/v1"
9-
corev1 "k8s.io/api/core/v1"
108
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11-
"k8s.io/apimachinery/pkg/runtime"
129
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1310
"k8s.io/client-go/rest"
1411
ctrl "sigs.k8s.io/controller-runtime"
1512
"sigs.k8s.io/controller-runtime/pkg/client"
1613

1714
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
18-
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
1915

20-
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
16+
"github.com/operator-framework/operator-controller/pkg/scheme"
2117
)
2218

2319
var (
@@ -33,16 +29,8 @@ const (
3329
func TestMain(m *testing.M) {
3430
cfg = ctrl.GetConfigOrDie()
3531

36-
scheme := runtime.NewScheme()
37-
38-
utilruntime.Must(ocv1alpha1.AddToScheme(scheme))
39-
utilruntime.Must(rukpakv1alpha2.AddToScheme(scheme))
40-
utilruntime.Must(catalogd.AddToScheme(scheme))
41-
utilruntime.Must(appsv1.AddToScheme(scheme))
42-
utilruntime.Must(corev1.AddToScheme(scheme))
43-
4432
var err error
45-
c, err = client.New(cfg, client.Options{Scheme: scheme})
33+
c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
4634
utilruntime.Must(err)
4735

4836
os.Exit(m.Run())

0 commit comments

Comments
 (0)