astefanutti commented on a change in pull request #784: Refactor controller
logic
URL: https://github.com/apache/camel-k/pull/784#discussion_r299383851
##########
File path: pkg/controller/integrationplatform/integrationplatform_controller.go
##########
@@ -109,53 +110,83 @@ func (r *ReconcileIntegrationPlatform) Reconcile(request
reconcile.Request) (rec
ctx := context.TODO()
// Fetch the IntegrationPlatform instance
- instance := &camelv1alpha1.IntegrationPlatform{}
- err := r.client.Get(ctx, request.NamespacedName, instance)
- if err != nil {
+ var instance camelv1alpha1.IntegrationPlatform
+
+ if err := r.client.Get(ctx, request.NamespacedName, &instance); err !=
nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted
after reconcile request.
- // Owned objects are automatically garbage collected.
For additional cleanup logic use finalizers.
+ // Owned objects are automatically garbage collected.
For additional cleanup
+ // logic use finalizers.
+
// Return and don't requeue
return reconcile.Result{}, nil
}
// Error reading the object - requeue the request.
return reconcile.Result{}, err
}
- integrationPlatformActionPool := []Action{
+ actions := []Action{
NewInitializeAction(),
NewWarmAction(),
NewCreateAction(),
NewStartAction(),
}
- ilog := rlog.ForIntegrationPlatform(instance)
- for _, a := range integrationPlatformActionPool {
+ var targetPhase camelv1alpha1.IntegrationPlatformPhase
+ var err error
+
+ target := instance.DeepCopy()
+ targetLog := rlog.ForIntegrationPlatform(target)
+
+ for _, a := range actions {
a.InjectClient(r.client)
- a.InjectLogger(ilog)
- if a.CanHandle(instance) {
- ilog.Infof("Invoking action %s", a.Name())
- if err := a.Handle(ctx, instance); err != nil {
- if k8serrors.IsConflict(err) {
- ilog.Error(err, "conflict")
- return reconcile.Result{
- Requeue: true,
- }, nil
+ a.InjectLogger(targetLog)
+
+ if a.CanHandle(target) {
+ targetLog.Infof("Invoking action %s", a.Name())
+
+ phaseFrom := target.Status.Phase
+
+ target, err = a.Handle(ctx, target)
+ if err != nil {
+ return reconcile.Result{
Review comment:
Shouldn't that be `reconcile.Result{}, err` to avoid swallowing the error?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services