Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Fix Kafka Channel dispatcher ownerRef #1536

Merged

Conversation

aliok
Copy link
Member

@aliok aliok commented Sep 9, 2020

Fixes #1188

Proposed Changes

  • Create the dispatcher deployment and service in advance
  • Deployment has 0 replicas initially and will be scaled up when the first KafkaChannel is created
  • Existing reconcilation logic is kept as it is harmless
  • Also tested with namespaced channels

Release Note

🐛 Fix bug
Cluster scoped KafkaChannel dispatcher is now created with 0 replicas in advance and will be scaled up with the creation of the first KafkaChannel. No manual operation is needed when upgrading.

Docs

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 9, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 9, 2020
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 9, 2020
@aliok aliok changed the title [WIP] Fix Kafka Channel dispatcher ownerRef Fix Kafka Channel dispatcher ownerRef Sep 9, 2020
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 9, 2020
@aliok
Copy link
Member Author

aliok commented Sep 9, 2020

cc @lionelvillard

@slinkydeveloper
Copy link
Contributor

This approach makes sense to me 👍

/lgtm
/approve
/hold waiting for @lionelvillard approval

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2020
@knative-prow-robot knative-prow-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 9, 2020
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2020
@@ -89,3 +91,13 @@ func TopicName(separator, namespace, name string) string {
topic := []string{knativeKafkaTopicPrefix, namespace, name}
return strings.Join(topic, separator)
}

func FindContainer(d *appsv1.Deployment, containerName string) *corev1.Container {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a function like this in the codebase. Any pointers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@aliok aliok Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold
Ok, looks like I need to write some unit tests for this function I created...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/unhold

Done with unit tests.
Next time I need this, I will refactor it into a function in knative/pkg

Comment on lines +302 to +310
d, err := r.KubeClientSet.AppsV1().Deployments(dispatcherNamespace).Update(expected)
if err == nil {
controller.GetEventRecorder(ctx).Event(kc, corev1.EventTypeNormal, dispatcherDeploymentUpdated, "Dispatcher deployment updated")
kc.Status.PropagateDispatcherStatus(&d.Status)
return d, nil
} else {
kc.Status.MarkServiceFailed("DispatcherDeploymentUpdateFailed", "Failed to update the dispatcher deployment: %v", err)
}
return d, newDeploymentWarn(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a new commit and made it easier to understand now.
Looks more similar to old code: https://github.com/knative/eventing-contrib/blob/master/kafka/channel/pkg/reconciler/controller/kafkachannel.go#L307

@n3wscott
Copy link
Contributor

n3wscott commented Sep 9, 2020

/lgtm

This sets us up for different kinds of deployments as the dispatcher as well in the future with a bit more work.

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2020
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2020
@aliok
Copy link
Member Author

aliok commented Sep 9, 2020

Code changes to address comments are not unit tested yet. Let me do them first.
UPDATE: done

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2020
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-eventing-contrib-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
kafka/channel/pkg/reconciler/controller/kafkachannel.go 53.9% 54.2% 0.3
kafka/channel/pkg/utils/util.go 88.2% 90.5% 2.2

@aliok
Copy link
Member Author

aliok commented Sep 9, 2020

@matzew @lionelvillard
This is all green now, ready for another look

}

if *d.Spec.Replicas == 0 {
logging.FromContext(ctx).Infof("Dispatcher deployment has 0 replicas. Scaling up deployment to 1 replicas")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: replicas -> replica, both instances.

Copy link
Member

@matzew matzew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 10, 2020
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aliok, matzew, slinkydeveloper

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit 1fcaa7b into knative:master Sep 10, 2020
@matzew matzew mentioned this pull request Sep 10, 2020
@aliok aliok deleted the fix-kafka-ch-dispatcher-ownerref2 branch September 14, 2020 07:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kafka-ch-dispatcher has no ownerref
8 participants