Skip to content
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

✨ ADD scheme package for AddToScheme #770

Merged
merged 1 commit into from
Apr 26, 2024
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
22 changes: 2 additions & 20 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,26 @@ import (
"time"

"github.com/spf13/pflag"
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

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

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata/cache"
catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/pkg/features"
"github.com/operator-framework/operator-controller/pkg/scheme"
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(ocv1alpha1.AddToScheme(scheme))
utilruntime.Must(rukpakv1alpha2.AddToScheme(scheme))
utilruntime.Must(catalogd.AddToScheme(scheme))
utilruntime.Must(carvelv1alpha1.AddToScheme(scheme))

//+kubebuilder:scaffold:scheme
}

func main() {
var (
metricsAddr string
Expand All @@ -86,7 +68,7 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts), zap.StacktraceLevel(zapcore.DPanicLevel)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Scheme: scheme.Scheme,
Metrics: server.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
Expand Down
14 changes: 2 additions & 12 deletions internal/catalogmetadata/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

Expand All @@ -22,17 +20,9 @@ import (

"github.com/operator-framework/operator-controller/internal/catalogmetadata"
catalogClient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/pkg/scheme"
)

var (
scheme *runtime.Scheme
)

func init() {
scheme = runtime.NewScheme()
utilruntime.Must(catalogd.AddToScheme(scheme))
}

func TestClient(t *testing.T) {
t.Run("Bundles", func(t *testing.T) {
for _, tt := range []struct {
Expand Down Expand Up @@ -172,7 +162,7 @@ func TestClient(t *testing.T) {
tt.fetcher.contentMap = catalogContentMap

fakeCatalogClient := catalogClient.New(
fake.NewClientBuilder().WithScheme(scheme).WithObjects(objs...).Build(),
fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(objs...).Build(),
tt.fetcher,
)

Expand Down
17 changes: 3 additions & 14 deletions internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ import (
"testing"

"github.com/stretchr/testify/require"
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"

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

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/pkg/scheme"
testutil "github.com/operator-framework/operator-controller/test/util"
)

func newClient(t *testing.T) client.Client {
cl, err := client.New(cfg, client.Options{Scheme: sch})
cl, err := client.New(cfg, client.Options{Scheme: scheme.Scheme})
require.NoError(t, err)
require.NotNil(t, cl)
return cl
Expand All @@ -55,7 +51,7 @@ func newClientAndReconciler(t *testing.T) (client.Client, *controllers.ClusterEx
reconciler := &controllers.ClusterExtensionReconciler{
Client: cl,
BundleProvider: &fakeCatalogClient,
Scheme: sch,
Scheme: scheme.Scheme,
Resolver: resolver,
}
return cl, reconciler
Expand All @@ -72,7 +68,6 @@ func newClientAndExtensionReconciler(t *testing.T) (client.Client, *controllers.
}

var (
sch *runtime.Scheme
cfg *rest.Config
)

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

sch = runtime.NewScheme()
utilruntime.Must(ocv1alpha1.AddToScheme(sch))
utilruntime.Must(rukpakv1alpha2.AddToScheme(sch))
utilruntime.Must(corev1.AddToScheme(sch))
utilruntime.Must(carvelv1alpha1.AddToScheme(sch))

code := m.Run()
utilruntime.Must(testEnv.Stop())
os.Exit(code)
Expand Down
6 changes: 0 additions & 6 deletions internal/controllers/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/utils/ptr"

"github.com/operator-framework/deppy/pkg/deppy"
Expand All @@ -28,10 +26,6 @@ import (
)

func TestVariableSource(t *testing.T) {
sch := runtime.NewScheme()
utilruntime.Must(ocv1alpha1.AddToScheme(sch))
utilruntime.Must(rukpakv1alpha2.AddToScheme(sch))

stableChannel := catalogmetadata.Channel{Channel: declcfg.Channel{
Name: "stable",
Entries: []declcfg.ChannelEntry{
Expand Down
28 changes: 28 additions & 0 deletions pkg/scheme/scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package scheme

import (
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"

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

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
)

var Scheme = runtime.NewScheme()

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(Scheme))
utilruntime.Must(ocv1alpha1.AddToScheme(Scheme))
utilruntime.Must(rukpakv1alpha2.AddToScheme(Scheme))
utilruntime.Must(catalogd.AddToScheme(Scheme))
utilruntime.Must(carvelv1alpha1.AddToScheme(Scheme))
utilruntime.Must(appsv1.AddToScheme(Scheme))
utilruntime.Must(corev1.AddToScheme(Scheme))
//+kubebuilder:scaffold:scheme
}
16 changes: 2 additions & 14 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ import (
"os"
"testing"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

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

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/pkg/scheme"
)

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

scheme := runtime.NewScheme()

utilruntime.Must(ocv1alpha1.AddToScheme(scheme))
utilruntime.Must(rukpakv1alpha2.AddToScheme(scheme))
utilruntime.Must(catalogd.AddToScheme(scheme))
utilruntime.Must(appsv1.AddToScheme(scheme))
utilruntime.Must(corev1.AddToScheme(scheme))

var err error
c, err = client.New(cfg, client.Options{Scheme: scheme})
c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
utilruntime.Must(err)

os.Exit(m.Run())
Expand Down
Loading