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

fix: Add bindings.knative.dev/include label to SinkBinding sources #2190

Merged
merged 2 commits into from
Apr 6, 2021
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
19 changes: 17 additions & 2 deletions pkg/trait/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"

ctrl "sigs.k8s.io/controller-runtime/pkg/client"

eventing "knative.dev/eventing/pkg/apis/eventing/v1beta1"
serving "knative.dev/serving/pkg/apis/serving/v1"

Expand Down Expand Up @@ -511,7 +513,7 @@ func (t *knativeTrait) configureSinkBinding(e *Environment, env *knativeapi.Came
e.ApplicationProperties["camel.k.customizer.sinkbinding.kind"] = ref.Kind
e.ApplicationProperties["camel.k.customizer.sinkbinding.api-version"] = ref.APIVersion

if e.IntegrationInPhase(v1.IntegrationPhaseDeploying) {
if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) {
e.PostStepProcessors = append(e.PostStepProcessors, func(e *Environment) error {
sinkBindingInjected := false
e.Resources.Visit(func(object runtime.Object) {
Expand All @@ -524,7 +526,7 @@ func (t *knativeTrait) configureSinkBinding(e *Environment, env *knativeapi.Came
return nil
}

controller := e.Resources.GetController(func(object runtime.Object) bool {
controller := e.Resources.GetController(func(object ctrl.Object) bool {
return true
})
if controller != nil && !reflect.ValueOf(controller).IsNil() {
Expand All @@ -542,7 +544,20 @@ func (t *knativeTrait) configureSinkBinding(e *Environment, env *knativeapi.Came
Name: ref.Name,
APIVersion: ref.APIVersion,
}

// Add the SinkBinding in first position, to make sure it is created
// before the reference source, so that the SinkBinding webhook has
// all the information to perform injection.
e.Resources.AddFirst(knativeutil.CreateSinkBinding(source, target))

// Make sure the Eventing webhook will select the source resource,
// in order to inject the sink information.
// This is necessary for Knative environments, that are configured
// with SINK_BINDING_SELECTION_MODE=inclusion.
// See:
// - https://knative.dev/v0.20-docs/eventing/sources/sinkbinding/
// - https://github.com/knative/operator/blob/c60e62bb86ff318c44d1520927d2182659cfdeb5/docs/configuration.md#specsinkbindingselectionmode
controller.GetLabels()["bindings.knative.dev/include"] = "true"
}
return nil
})
Expand Down
4 changes: 1 addition & 3 deletions pkg/util/kubernetes/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func (c *Collection) VisitContainer(visitor func(container *corev1.Container)) {
}

// GetController returns the controller associated with the integration (e.g. Deployment, Knative Service or CronJob)
func (c *Collection) GetController(filter func(object runtime.Object) bool) runtime.Object {
func (c *Collection) GetController(filter func(object ctrl.Object) bool) ctrl.Object {
d := c.GetDeployment(func(deployment *appsv1.Deployment) bool {
return filter(deployment)
})
Expand Down Expand Up @@ -476,7 +476,6 @@ func (c *Collection) Remove(selector func(runtime.Object) bool) runtime.Object {
return nil
}

// VisitServiceMonitor ---
func (c *Collection) VisitServiceMonitor(visitor func(*monitoringv1.ServiceMonitor)) {
c.Visit(func(res runtime.Object) {
if conv, ok := res.(*monitoringv1.ServiceMonitor); ok {
Expand All @@ -485,7 +484,6 @@ func (c *Collection) VisitServiceMonitor(visitor func(*monitoringv1.ServiceMonit
})
}

// GetServiceMonitor ---
func (c *Collection) GetServiceMonitor(filter func(*monitoringv1.ServiceMonitor) bool) *monitoringv1.ServiceMonitor {
var retValue *monitoringv1.ServiceMonitor
c.VisitServiceMonitor(func(serviceMonitor *monitoringv1.ServiceMonitor) {
Expand Down