Skip to content

Commit

Permalink
fix: Kamel install with kit option can leave integrationkit stuck wai…
Browse files Browse the repository at this point in the history
…ting for platform

fixes #809
  • Loading branch information
jamesnetherton committed Jul 12, 2019
1 parent cc339f7 commit 98a36c9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions pkg/controller/integrationkit/integrationkit_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integrationkit

import (
Expand All @@ -27,6 +28,8 @@ 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"
Expand Down Expand Up @@ -106,6 +109,41 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

// Watch for IntegrationPlatform phase transitioning to ready and enqueue
// requests for any integrationkits 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)
var requests []reconcile.Request

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

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

for _, kit := range list.Items {
if kit.Status.Phase == v1alpha1.IntegrationKitPhaseWaitingForPlatform {
log.Infof("Platform %s ready, wake-up integrationkit: %s", platform.Name, kit.Name)
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: kit.Namespace,
Name: kit.Name,
},
})
}
}
}

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

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetOrLookup(ctx context.Context, c k8sclient.Reader, namespace string, name

// Get returns the currently installed platform
func Get(ctx context.Context, c k8sclient.Reader, namespace string, name string) (*v1alpha1.IntegrationPlatform, error) {
return kubernetes.GetIntegrationPlatform(ctx, c, namespace, name)
return kubernetes.GetIntegrationPlatform(ctx, c, name, namespace)
}

// GetCurrentPlatform returns the currently installed platform
Expand Down

0 comments on commit 98a36c9

Please sign in to comment.