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

Optimize reconciliation loops #459

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 18 additions & 10 deletions pkg/controller/integration/integration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (

camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/client"
appsv1 "k8s.io/api/apps/v1"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)
Expand Down Expand Up @@ -48,15 +51,20 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

// Watch for changes to primary resource Integration
err = c.Watch(&source.Kind{Type: &camelv1alpha1.Integration{}}, &handler.EnqueueRequestForObject{})
if err != nil {
return err
}

// Watch for changes to secondary resource Pods and requeue the owner Integration
err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &camelv1alpha1.Integration{},
err = c.Watch(&source.Kind{Type: &camelv1alpha1.Integration{}}, &handler.EnqueueRequestForObject{}, predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldIntegration := e.ObjectOld.(*camelv1alpha1.Integration)
newIntegration := e.ObjectNew.(*camelv1alpha1.Integration)
// Ignore updates to the integration status in which case metadata.Generation does not change,
// or except when the integration phase changes as it's used to transition from one phase
// to another
return oldIntegration.Generation != newIntegration.Generation ||
oldIntegration.Status.Phase != newIntegration.Status.Phase
},
DeleteFunc: func(e event.DeleteEvent) bool {
// Evaluates to false if the object has been confirmed deleted
return !e.DeleteStateUnknown
},
})
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import (

camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/client"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)
Expand Down Expand Up @@ -42,7 +46,21 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

// Watch for changes to primary resource IntegrationContext
err = c.Watch(&source.Kind{Type: &camelv1alpha1.IntegrationContext{}}, &handler.EnqueueRequestForObject{})
err = c.Watch(&source.Kind{Type: &camelv1alpha1.IntegrationContext{}}, &handler.EnqueueRequestForObject{}, predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldIntegrationContext := e.ObjectOld.(*camelv1alpha1.IntegrationContext)
newIntegrationContext := e.ObjectNew.(*camelv1alpha1.IntegrationContext)
// Ignore updates to the integration context status in which case metadata.Generation
// does not change, or except when the integration context phase changes as it's used
// to transition from one phase to another
return oldIntegrationContext.Generation != newIntegrationContext.Generation ||
oldIntegrationContext.Status.Phase != newIntegrationContext.Status.Phase
},
DeleteFunc: func(e event.DeleteEvent) bool {
// Evaluates to false if the object has been confirmed deleted
return !e.DeleteStateUnknown
},
})
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import (

camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/client"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)
Expand Down Expand Up @@ -42,7 +46,21 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

// Watch for changes to primary resource IntegrationPlatform
err = c.Watch(&source.Kind{Type: &camelv1alpha1.IntegrationPlatform{}}, &handler.EnqueueRequestForObject{})
err = c.Watch(&source.Kind{Type: &camelv1alpha1.IntegrationPlatform{}}, &handler.EnqueueRequestForObject{}, predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldIntegrationPlatform := e.ObjectOld.(*camelv1alpha1.IntegrationPlatform)
newIntegrationPlatform := e.ObjectNew.(*camelv1alpha1.IntegrationPlatform)
// Ignore updates to the integration platform status in which case metadata.Generation
// does not change, or except when the integration platform phase changes as it's used
// to transition from one phase to another
return oldIntegrationPlatform.Generation != newIntegrationPlatform.Generation ||
oldIntegrationPlatform.Status.Phase != newIntegrationPlatform.Status.Phase
},
DeleteFunc: func(e event.DeleteEvent) bool {
// Evaluates to false if the object has been confirmed deleted
return !e.DeleteStateUnknown
},
})
if err != nil {
return err
}
Expand Down