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

feat: jetstream eventbus controller implementation #1705

Merged
merged 7 commits into from
Mar 8, 2022

Conversation

whynowy
Copy link
Member

@whynowy whynowy commented Mar 3, 2022

Signed-off-by: Derek Wang [email protected]

This PR is part of the effort of JetStream EventBus implementation.

A JetStream EventBus spec looks like below, where version is a required field in the spec.

apiVersion: argoproj.io/v1alpha1
kind: EventBus
metadata:
  name: default
spec:
  jetstream:
    version: 2.7.3

TLS enabling is not done in this PR, it should be implemented before we do an official release.

Current Nats Streaming image configuration is also moved into a configmap, together with JetStream image configs. This configmap is now only used by eventbus-controller. As one of the follow-up tasks, all of the 3 controllers will be merged to one #1564.

Checklist:

@whynowy whynowy requested a review from alexec March 3, 2022 20:02
@@ -0,0 +1,21 @@
package common
Copy link
Member Author

@whynowy whynowy Mar 3, 2022

Choose a reason for hiding this comment

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

We should refactor all those util functions under several common across the project.

// See https://docs.nats.io/running-a-nats-service/configuration#jetstream.
// Only configure "max_memory_store" or "max_file_store", do not set "store_dir" as it has been hardcoded.
// +optional
Settings *string `json:"settings,omitempty" protobuf:"bytes,15,opt,name=settings"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nice and generic. I'll update my design document to reflect this.

if j.Replicas == nil {
return 3
}
if *j.Replicas < 3 {
Copy link
Contributor

@juliev0 juliev0 Mar 3, 2022

Choose a reason for hiding this comment

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

oh, interesting. We don't let them have less than 3. Ideally maybe we'd warn them (log message or whatever) but not critical.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cluster setting has a different configuration from single node setting, it's not worth supporting that for us.

For a cluster setting, it needs at least 2 nodes to make it work. JetStream uses a RAFT algorithm for clustering, which does not make sense to use an even number. So a reasonable cluster node number is 3 or 5.

In order to ensure data consistency across complete restarts, a quorum of servers is required. A quorum is ½ cluster size + 1. This is the minimum number of nodes to ensure at least one node has the most recent data and state after a catastrophic failure. So for a cluster size of 3, you’ll need at least two JetStream enabled NATS servers available to store new messages. For a cluster size of 5, you’ll need at least 3 NATS servers, and so forth.

https://docs.nats.io/running-a-nats-service/configuration/clustering/jetstream_clustering#the-quorum

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. Just wondering if we might want to log something so it's not a silent change. But I'm good with whatever - probably rare that somebody would set replicas to 1 or 2.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding a log sounds good.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems to be awkward to add a log in the model, skip it for now.

Copy link
Contributor

@juliev0 juliev0 left a comment

Choose a reason for hiding this comment

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

Nice. Left a few comments but didn't really see any issues.

Copy link
Member

@daniel-codefresh daniel-codefresh left a comment

Choose a reason for hiding this comment

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

Overall looks great! left few small comments/questions

return &r, nil
}
}
return nil, fmt.Errorf("no nats streaming configuration found for %q", version)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to let the user know which versions are currently supported so the user would have a better indication on how to fix this error, WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Same goes for GetJetStreamVersion

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

return nil
}

func (r *jetStreamInstaller) buildStatefulSetSpec(jeVersion *controllers.JetStreamVersion) appv1.StatefulSetSpec {
Copy link
Member

Choose a reason for hiding this comment

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

can we have a default version here (like we have in the NATS installer) to make the Version field optional for the user?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having a default version will cause future upgrade issue - if version is not specified, we use a default version, that will prevent us from updating the default version later, otherwise if the default one is changed, those installation with default versions will be automatically updated. This is a problem for current nats streaming implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks for the clarification

- version: 2.7.3
natsImage: nats:2.7.3
metricsExporterImage: natsio/prometheus-nats-exporter:0.9.1
startCommand: /nats-server
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be nats-server (without the /) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This image is built from scratch, the binary is put under /, so we have to use /nats-server.

}
if x := eb.Spec.JetStream; x != nil {
if x.Version == "" {
return fmt.Errorf("invalid spec: a version for jetstream needs to be specified")
Copy link
Member

Choose a reason for hiding this comment

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

Can we add replicas validation here?

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good, done.

.
Signed-off-by: Derek Wang <[email protected]>
Copy link
Member

@sarabala1979 sarabala1979 left a comment

Choose a reason for hiding this comment

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

LGTM

.
Signed-off-by: Derek Wang <[email protected]>
@whynowy whynowy merged commit 475baac into argoproj:master Mar 8, 2022
@whynowy whynowy deleted the jsbus branch March 8, 2022 07:35
juliev0 pushed a commit to juliev0/argo-events that referenced this pull request Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants