Skip to content

Commit

Permalink
fix: Integration stuck waiting for platform
Browse files Browse the repository at this point in the history
fixes #660
  • Loading branch information
jamesnetherton authored and lburgazzoli committed May 24, 2019
1 parent 0572195 commit 21cd224
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/controller/integration/integration_controller.go
Expand Up @@ -6,7 +6,9 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"

k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand All @@ -17,6 +19,7 @@ import (

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/util/log"
)

/**
Expand Down Expand Up @@ -90,6 +93,40 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

// Watch for IntegrationPlatform phase transitioning to ready
// and enqueue requests for any integrations that are in phase waiting for platform
err = c.Watch(&source.Kind{Type: &v1alpha1.IntegrationPlatform{}}, &handler.EnqueueRequestsFromMapFunc{
ToRequests: handler.ToRequestsFunc(func(a handler.MapObject) []reconcile.Request {
platform := a.Object.(*v1alpha1.IntegrationPlatform)
requests := []reconcile.Request{}

if platform.Status.Phase == v1alpha1.IntegrationPlatformPhaseReady {
list := &v1alpha1.IntegrationList{}

if err := mgr.GetClient().List(context.TODO(), &k8sclient.ListOptions{Namespace: platform.Namespace}, list); err != nil {
log.Error(err, "Failed to retrieve integration list")
return requests
}

for _, integration := range list.Items {
if integration.Status.Phase == v1alpha1.IntegrationPhaseWaitingForPlatform {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: integration.Namespace,
Name: integration.Name,
},
})
}
}
}

return requests
}),
})
if err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 21cd224

Please sign in to comment.