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

Propagate errors of ARO ImageConfig controller to ARO Operator #2939

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 12 additions & 10 deletions pkg/operator/controllers/imageconfig/image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/util/azureclient"
)

Expand All @@ -33,15 +34,16 @@ const (
)

type Reconciler struct {
log *logrus.Entry

client client.Client
base.AROController
}

func NewReconciler(log *logrus.Entry, client client.Client) *Reconciler {
return &Reconciler{
log: log,
client: client,
AROController: base.AROController{
Log: log,
Client: client,
Name: ControllerName,
},
}
}

Expand All @@ -51,17 +53,17 @@ func NewReconciler(log *logrus.Entry, client client.Client) *Reconciler {
// - Fails fast if both are not nil, unsupported
func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
instance := &arov1alpha1.Cluster{}
err := r.client.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, instance)
err := r.Client.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, instance)
if err != nil {
return reconcile.Result{}, err
}

if !instance.Spec.OperatorFlags.GetSimpleBoolean(controllerEnabled) {
r.log.Debug("controller is disabled")
r.Log.Debug("controller is disabled")
return reconcile.Result{}, nil
}

r.log.Debug("running")
r.Log.Debug("running")
requiredRegistries, err := GetCloudAwareRegistries(instance)
if err != nil {
// Not returning error as it will requeue again
Expand All @@ -70,7 +72,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.

// Get image.config yaml
imageconfig := &configv1.Image{}
err = r.client.Get(ctx, types.NamespacedName{Name: request.Name}, imageconfig)
err = r.Client.Get(ctx, types.NamespacedName{Name: request.Name}, imageconfig)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -102,7 +104,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}

// Update image config registry
return reconcile.Result{}, r.client.Update(ctx, imageconfig)
return reconcile.Result{}, r.Client.Update(ctx, imageconfig)
}

// SetupWithManager setup the manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,15 @@ func TestImageConfigReconciler(t *testing.T) {

clientFake := ctrlfake.NewClientBuilder().WithObjects(instance, tt.image).Build()

r := &Reconciler{
log: logrus.NewEntry(logrus.StandardLogger()),
client: clientFake,
}
r := NewReconciler(logrus.NewEntry(logrus.StandardLogger()), clientFake)
request := ctrl.Request{}
request.Name = "cluster"

_, err := r.Reconcile(ctx, request)
utilerror.AssertErrorMessage(t, err, tt.wantErr)

imgcfg := &configv1.Image{}
err = r.client.Get(ctx, types.NamespacedName{Name: request.Name}, imgcfg)
err = r.Client.Get(ctx, types.NamespacedName{Name: request.Name}, imgcfg)
if err != nil {
t.Fatal(err)
}
Expand Down