Skip to content

Commit 6e9be74

Browse files
committed
Avoid failing at manager startup when the hardcoded CatalogSource isn't present
1 parent eb6135b commit 6e9be74

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

controllers/platformoperator_controller.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ import (
4040
platformv1alpha1 "github.com/timflannagan/platform-operators/api/v1alpha1"
4141
)
4242

43-
const channelName = "4.12"
43+
const (
44+
channelName = "4.12"
45+
plainProvisionerID = "core.rukpak.io/plain"
46+
)
4447

4548
// PlatformOperatorReconciler reconciles a PlatformOperator object
4649
type PlatformOperatorReconciler struct {
@@ -102,8 +105,27 @@ func (r *PlatformOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Req
102105
return ctrl.Result{}, client.IgnoreNotFound(err)
103106
}
104107

108+
css := &operatorsv1alpha1.CatalogSourceList{}
109+
if err := r.List(ctx, css); err != nil {
110+
log.Error(err, "failed to list the catalogsource resources in the cluster")
111+
return ctrl.Result{}, err
112+
}
113+
if len(css.Items) == 0 {
114+
log.Info("unable to query catalog content as no catalogsources are available")
115+
return ctrl.Result{}, nil
116+
}
117+
// TODO(tflannag): properly handle multiple catalogsources in a cluster
118+
cs := css.Items[0]
119+
120+
log.Info("creating registry client from catalogsource")
121+
rc, err := registryClient.NewClient(cs.Spec.Address)
122+
if err != nil {
123+
log.Error(err, "failed to create registry client from catalogsource", "name", cs.GetName(), "namespace", cs.GetNamespace(), "address", cs.Spec.Address)
124+
return ctrl.Result{}, err
125+
}
126+
105127
log.Info("listing bundles from context")
106-
it, err := r.RegistryClient.ListBundles(ctx)
128+
it, err := rc.ListBundles(ctx)
107129
if err != nil {
108130
log.Error(err, "failed to list bundles in the platform operators catalog source")
109131
return ctrl.Result{}, err
@@ -153,22 +175,19 @@ func (r *PlatformOperatorReconciler) ensureBundleInstance(ctx context.Context, p
153175

154176
_, err := controllerutil.CreateOrUpdate(ctx, r.Client, bi, func() error {
155177
bi.SetOwnerReferences([]metav1.OwnerReference{*controllerRef})
156-
bi.Spec = *buildBundleInstance(bi.GetName(), bundle.BundlePath)
178+
bi.Spec = *buildBundleInstance(bundle.BundlePath)
157179
return nil
158180
})
159181
return err
160182
}
161183

162184
// createBundleInstance is responsible for taking a name and image to create an embedded BundleInstance
163-
func buildBundleInstance(name, image string) *rukpakv1alpha1.BundleInstanceSpec {
185+
func buildBundleInstance(image string) *rukpakv1alpha1.BundleInstanceSpec {
164186
return &rukpakv1alpha1.BundleInstanceSpec{
165-
ProvisionerClassName: "core.rukpak.io/plain",
187+
ProvisionerClassName: plainProvisionerID,
166188
Template: &rukpakv1alpha1.BundleTemplate{
167-
ObjectMeta: metav1.ObjectMeta{
168-
Labels: map[string]string{"app": name},
169-
},
170189
Spec: rukpakv1alpha1.BundleSpec{
171-
ProvisionerClassName: "core.rukpak.io/plain",
190+
ProvisionerClassName: plainProvisionerID,
172191
Source: rukpakv1alpha1.BundleSource{
173192
Type: rukpakv1alpha1.SourceTypeImage,
174193
Image: &rukpakv1alpha1.ImageSource{

main.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"context"
2120
"flag"
2221
"os"
23-
"time"
2422

2523
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2624
// to ensure that exec-entrypoint and run can make use of them.
2725
_ "k8s.io/client-go/plugin/pkg/client/auth"
2826

2927
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
30-
registryClient "github.com/operator-framework/operator-registry/pkg/client"
3128
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
3229
"k8s.io/apimachinery/pkg/runtime"
3330
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -41,16 +38,9 @@ import (
4138
//+kubebuilder:scaffold:imports
4239
)
4340

44-
const (
45-
catalogSourceName = "platform-operators-catalog-source"
46-
catalogSourceNamespace = "platform-operators-system"
47-
catalogSourceReconnectTime = time.Second * 5
48-
)
49-
5041
var (
51-
scheme = runtime.NewScheme()
52-
setupLog = ctrl.Log.WithName("setup")
53-
catalogSourceService = catalogSourceName + "." + catalogSourceNamespace + ".svc:50051"
42+
scheme = runtime.NewScheme()
43+
setupLog = ctrl.Log.WithName("setup")
5444
)
5545

5646
func init() {
@@ -91,22 +81,9 @@ func main() {
9181
os.Exit(1)
9282
}
9383

94-
// Create a registryClient by referencing the requisite catalogSource's service and then
95-
// check that it is healthy
96-
c, err := registryClient.NewClient(catalogSourceService)
97-
if err != nil {
98-
setupLog.Error(err, "failed to create registry client from "+catalogSourceName+" catalog source")
99-
os.Exit(1)
100-
}
101-
if healthy, err := c.HealthCheck(context.Background(), catalogSourceReconnectTime); !healthy || err != nil {
102-
setupLog.Error(err, "failed to connect to "+catalogSourceName+" catalog source via the registry client")
103-
os.Exit(1)
104-
}
105-
10684
if err = (&controllers.PlatformOperatorReconciler{
107-
Client: mgr.GetClient(),
108-
Scheme: mgr.GetScheme(),
109-
RegistryClient: c,
85+
Client: mgr.GetClient(),
86+
Scheme: mgr.GetScheme(),
11087
}).SetupWithManager(mgr); err != nil {
11188
setupLog.Error(err, "unable to create controller", "controller", "PlatformOperator")
11289
os.Exit(1)

0 commit comments

Comments
 (0)