Skip to content

Add NATS Streaming provisioner#624

Merged
knative-prow-robot merged 28 commits into
masterfrom
unknown repository
Dec 5, 2018
Merged

Add NATS Streaming provisioner#624
knative-prow-robot merged 28 commits into
masterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Nov 16, 2018

Proposed Changes

  • Add NATS Streaming provisioner

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Nov 16, 2018
@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 16, 2018
@ghost ghost changed the title Add natss provisioner WIP: Add natss provisioner Nov 16, 2018
@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 Nov 16, 2018
@ghost ghost changed the title WIP: Add natss provisioner [WIP] Add natss provisioner Nov 16, 2018
@ghost ghost changed the title [WIP] Add natss provisioner [WIP] Add NATSS provisioner Nov 16, 2018
@ghost ghost changed the title [WIP] Add NATSS provisioner [WIP] Add NATS Streaming provisioner Nov 16, 2018
@@ -0,0 +1,101 @@
apiVersion: v1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a README at the root of the natss folder, similar like the in-memory and kafka channel provisioners have it, e.g.:
https://github.com/knative/eventing/tree/master/config/provisioners/kafka

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

feel free to include links to setup for nats(s) as well

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Comment thread config/provisioners/natss/README.md Outdated

NATS Streaming is deployed as a StatefulSet.
For tuning NATS Streaming, see:
https://github.com/nats-io/nats-streaming-server#configuring
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also state the name of the ConfigMap that contains the configuration.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added in README.
Done

r.logger.Info("Not reconciling Channel, it is not controlled by this Controller", zap.Any("ref", c.Spec))
return reconcile.Result{}, nil
}
//r.logger.Info("Reconciling Channel:", zap.Any("channel", c))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Either uncomment or remove.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done


// Modify a copy, not the original.
c = c.DeepCopy()
err = r.reconcile(ctx, c)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this follows a pattern in other reoncilers, but I changed my preference recently and think that this should be in a new variable reconcileErr.

My reasoning is that err tends to be checked and handled immediately, without the intention of using it again in the future. As this piece of code wants to use err again later, I think it is useful to give it a different name.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done


if c.DeletionTimestamp != nil {
// K8s garbage collection will delete the K8s service and VirtualService for this channel.
// We use a finalizer to ensure the channel config has been synced.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It doesn't look like there is any config that is synced. Do we need a finalizer at all?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Right, don't need it.
Done

// Modify a copy of this object, rather than the original.
ccp = ccp.DeepCopy()

err = r.reconcile(ctx, ccp)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

reconcileErr, using the same reasoning as above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

// Modify a copy, not the original.
c = c.DeepCopy()

err = r.reconcile(ctx, c)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

reconcileErr, same reasoning as above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

err = errors.New("can't close empty stan connection")
return
}
err = (*sc).Close()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the dereference needed? Does sc.Close() work?

Copy link
Copy Markdown
Author

@ghost ghost Nov 29, 2018

Choose a reason for hiding this comment

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

Here "sc" is a pointer to an interface, see it in the function signature: "sc *stan.Conn"


// Close must be the last call to close the connection
func Close(sc *stan.Conn, logger *zap.SugaredLogger) (err error) {
defer func() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a comment about why this might panic, so we defer a recover().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done


// Publish a message to a subject
func Publish(sc *stan.Conn, subj string, msg *[]byte, logger *zap.SugaredLogger) (err error) {
defer func() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a comment about why this might panic, so we defer a recover().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

err = errors.New("cant'publish on empty stan connection")
return
}
err = (*sc).Publish(subj, *msg)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the dereference needed? Does sc.Close() work?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

"sc" is a pointer to an interface

)

var (
natsConnMux sync.Mutex
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a comment about when this lock needs to be held.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Refactored.
Done

kind: Service
metadata:
name: nats-streaming
namespace: knative-eventing
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure if the nats-streaming bit should be in the knative-eventing ns

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

NATSS is running now in its own namespace: natss
Done

Comment thread config/provisioners/natss/README.md Outdated
1. Setup [Knative Eventing](../../../DEVELOPMENT.md).
1. Apply the 'natss' ClusterChannelProvisioner, Controller, and Dispatcher.
```shell
ko apply -f config/provisioners/natss/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The above would provision natss, and the cpp - right ?

I think I'd prefer some separation here (e.g see Kafka). and that the actual provisioning of the natss bits would be more a sample - as well as showing how to use existing/external natss.

and than for the ccp, have just something like:

ko apply -f config/provisioners/natss/natss.yaml

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

@ghost ghost changed the title [WIP] Add NATS Streaming provisioner Add NATS Streaming provisioner Dec 4, 2018
@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 Dec 4, 2018
- list
- watch
- create

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

- update

The common lib was changed to update the VirtualService if it has an unexpected spec.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

sidecar.istio.io/inject: "true"
labels: *labels
spec:
serviceAccountName: natss-controller
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally this would use a different service account (as it needs fewer permissions than the controller). Doesn't need to be this PR, but please add a TODO to use a different service account.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The dispatcher uses now "natss-dispatcher" as ServiceAccount
Done

"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestInjectClient(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be in reconcile_test.go?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved
Done

// The Channel may have been deleted since it was added to the workqueue.
if errors.IsNotFound(err) {
r.logger.Info("Could not find Channel", zap.Error(err))
// unsubscribe all active subscriptions for this channel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure we can rely on this to notice Channel deletion. I would expect to use a finalizer if you want to notice the channel is being deleted.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Channel finalizer is used now to cleanup the NATSS active subscriptions.
Done

@ghost ghost changed the title Add NATS Streaming provisioner [WIP] Add NATS Streaming provisioner Dec 5, 2018
@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 Dec 5, 2018
@knative-metrics-robot
Copy link
Copy Markdown

@ghost ghost changed the title [WIP] Add NATS Streaming provisioner Add NATS Streaming provisioner Dec 5, 2018
@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 Dec 5, 2018
Copy link
Copy Markdown
Contributor

@Harwayne Harwayne left a comment

Choose a reason for hiding this comment

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

/lgtm

s.subscriptions[cRef] = chMap
}
for _, sub := range subscriptions {
// check if the subscribtion already exist and do nothing in this case
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

subscribtion -> subscription

}
// Unsubscribe for deleted subscriptions
for sub := range chMap {
if ok := activeSubs[sub]; !ok {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because this is a set, we probably shouldn't rely on the value being true

if _, ok := activeSubs[sub]; !ok {

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 5, 2018
Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/approve

/hold for comments

@@ -0,0 +1,44 @@
# NATS Streaming Channels

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be worth providing a quick overview here of the benefits of NATS Streaming:

Approx throughput?
Durability / chance of data loss?
Resource requirements?
Ordering guarantees?

app: nats-streaming
spec:
serviceName: nats-streaming
replicas: 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does 1 replica have durability implications? Can this number be changed on the fly?

return reconcile.Result{}, reconcileErr
}

// IsControlled determines if the in-memory Channel Controller should control (and therefore
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/in-memory/nats/, correct?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

or s/in-memory Channel/this/

for i := 0; i < 60; i++ {
if sc, err = stan.Connect(clusterId, clientId, stan.NatsURL(natsUrl)); err != nil {
logger.Warnf("Connect(): create new connection failed: %v", err)
time.Sleep(1 * time.Second)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given the 1-60 loop above, I don't know that changing this sleep alone will help much.

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, radufa

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

The pull request process is described here

Details 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 5, 2018
@knative-prow-robot knative-prow-robot merged commit b25850b into knative:master Dec 5, 2018
@evankanderson
Copy link
Copy Markdown
Member

Feel free to do a followup PR for the comments; I wanted to strike while Adam's review was hot.

pierDipi added a commit to pierDipi/eventing that referenced this pull request Jun 12, 2024
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants