Skip to content

Commit a723c34

Browse files
committed
No more panics (#767)
Signed-off-by: Todd Short <[email protected]>
1 parent 69a61a1 commit a723c34

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ func init() {
134134
ReasonErrorGettingReleaseState,
135135
ReasonUpgradeFailed,
136136
ReasonCreateDynamicWatchFailed,
137+
ReasonBundleLoadFailed,
138+
ReasonErrorGettingClient,
137139
)
138140
}
139141

cmd/manager/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func main() {
116116
acg, err := helmclient.NewActionClientGetter(cfgGetter)
117117
if err != nil {
118118
setupLog.Error(err, "unable to create helm client")
119+
os.Exit(1)
119120
}
120121

121122
if systemNamespace == "" {
@@ -125,6 +126,7 @@ func main() {
125126
unpacker, err := source.NewDefaultUnpacker(mgr, systemNamespace, unpackImage)
126127
if err != nil {
127128
setupLog.Error(err, "unable to create unpacker")
129+
os.Exit(1)
128130
}
129131

130132
storageURL, err := url.Parse(fmt.Sprintf("%s/bundles/", httpExternalAddr))

internal/controllers/clusterextension_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ func (r *ClusterExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Req
111111

112112
reconciledExt := existingExt.DeepCopy()
113113
res, reconcileErr := r.reconcile(ctx, reconciledExt)
114+
if reconcileErr != nil {
115+
return ctrl.Result{}, reconcileErr
116+
}
114117

115118
// Do checks before any Update()s, as Update() may modify the resource structure!
116119
updateStatus := !equality.Semantic.DeepEqual(existingExt.Status, reconciledExt.Status)

internal/controllers/suite_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ import (
2222
"path/filepath"
2323
"testing"
2424

25+
"github.com/go-logr/logr"
2526
"github.com/stretchr/testify/require"
27+
"k8s.io/apimachinery/pkg/api/meta"
2628
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2729
"k8s.io/client-go/rest"
2830
"sigs.k8s.io/controller-runtime/pkg/client"
2931
"sigs.k8s.io/controller-runtime/pkg/envtest"
32+
"sigs.k8s.io/controller-runtime/pkg/manager"
3033

3134
"github.com/operator-framework/deppy/pkg/deppy/solver"
35+
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
3236

3337
"github.com/operator-framework/operator-controller/internal/controllers"
38+
"github.com/operator-framework/operator-controller/internal/rukpak/source"
39+
"github.com/operator-framework/operator-controller/internal/rukpak/util"
3440
"github.com/operator-framework/operator-controller/pkg/scheme"
3541
testutil "github.com/operator-framework/operator-controller/test/util"
3642
)
@@ -49,9 +55,11 @@ func newClientAndReconciler(t *testing.T) (client.Client, *controllers.ClusterEx
4955
cl := newClient(t)
5056
fakeCatalogClient := testutil.NewFakeCatalogClient(testBundleList)
5157
reconciler := &controllers.ClusterExtensionReconciler{
52-
Client: cl,
53-
BundleProvider: &fakeCatalogClient,
54-
Scheme: scheme.Scheme,
58+
Client: cl,
59+
BundleProvider: &fakeCatalogClient,
60+
Scheme: scheme.Scheme,
61+
ActionClientGetter: acg,
62+
Unpacker: unp,
5563
}
5664
return cl, reconciler
5765
}
@@ -68,6 +76,8 @@ func newClientAndExtensionReconciler(t *testing.T) (client.Client, *controllers.
6876

6977
var (
7078
cfg *rest.Config
79+
acg helmclient.ActionClientGetter
80+
unp source.Unpacker
7181
)
7282

7383
func TestMain(m *testing.M) {
@@ -85,6 +95,17 @@ func TestMain(m *testing.M) {
8595
log.Panic("expected cfg to not be nil")
8696
}
8797

98+
rm := meta.NewDefaultRESTMapper(nil)
99+
cfgGetter, err := helmclient.NewActionConfigGetter(cfg, rm, logr.Logger{})
100+
utilruntime.Must(err)
101+
acg, err = helmclient.NewActionClientGetter(cfgGetter)
102+
utilruntime.Must(err)
103+
104+
mgr, err := manager.New(cfg, manager.Options{})
105+
utilruntime.Must(err)
106+
unp, err = source.NewDefaultUnpacker(mgr, util.DefaultSystemNamespace, util.DefaultUnpackImage)
107+
utilruntime.Must(err)
108+
88109
code := m.Run()
89110
utilruntime.Must(testEnv.Stop())
90111
os.Exit(code)

0 commit comments

Comments
 (0)