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

Add leaf node remotes config #284

Merged
merged 3 commits into from
Sep 5, 2020
Merged

Conversation

variadico
Copy link
Contributor

@variadico variadico commented Sep 4, 2020

Currently, there is no way to specify leaf node remotes. This adds config
support for leaf node remotes and also includes some example YAML to deploy on
Kubernetes.

Fixes #280

@@ -201,9 +201,16 @@ type RemoteGatewayOpts struct {
URL string `json:"url,omitempty"`
}

// LeafNodeRemote is the URL for remote NATS system.
type LeafNodeRemote struct {
URL string `json:"url,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

I think we should probably also support the array version:

URL         []string `json:"urls,omitempty"`

Copy link
Contributor Author

@variadico variadico Sep 4, 2020

Choose a reason for hiding this comment

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

Is this possible NATS config?

leafnodes {
    remotes = [
        {
          url: ["nats-leaf://s3cr3t@foo", "nats-leaf://s3cr3t@bar"]
        },
    ]
}

Copy link
Member

Choose a reason for hiding this comment

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

yes also possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, okay. Sounds good. 👍

Copy link
Member

Choose a reason for hiding this comment

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

both these are valid:

leafnodes {
    remotes = [
        {
          url: "nats-leaf://s3cr3t@foo,nats-leaf://s3cr3t@bar"
        },
    ]
}

array version:

leafnodes {
    remotes = [
        {
          urls: ["nats-leaf://s3cr3t@foo", "nats-leaf://s3cr3t@bar"]
        },
    ]
}


leafnodeConfig:
remotes:
- url: nats://1.2.3.4:7422
Copy link
Member

Choose a reason for hiding this comment

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

url can be many comma separated, but can also be an array urls: ["nats://...", "nats://..."] can be common in case to explicit about the clusters

Copy link
Member

@wallyqs wallyqs left a comment

Choose a reason for hiding this comment

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

LGTM! Might be good to have support for array version of the remotes too, also we need to add the option for remote leafnode TLS certs and the volume in a similar way as it is done here with the credentials.

@variadico
Copy link
Contributor Author

variadico commented Sep 4, 2020

Okay, so looks like the controller code generator doesn't like if we use interface{} types in the YAML. This means we can't overload the type of url in YAML.

However, I exposed two keys in the YAML, so this is possible.

  leafnodeConfig:
    remotes:
    - url: nats://1.2.3.4:7422
      credentials: /etc/nats-creds/user.ncreds

# and

  leafnodeConfig:
    remotes:
    - urls: [nats://1.2.3.4:7422, nats://1.2.3.4:7423]
      credentials: /etc/nats-creds/user.ncreds

# and technically even this

  leafnodeConfig:
    remotes:
    - url: nats://1.2.3.4:7422
      urls: [nats://1.2.3.4:7422, nats://1.2.3.4:7423]
      credentials: /etc/nats-creds/user.ncreds

# in the above case, all of the URLs get combined into 1 array of URLs

All combinations of these URL keys get merged into this.

leafnodes {
    remotes = [
        {
          urls: [nats://1.2.3.4:7422, ...]
        },
    ]
}

Change: fafdb24

Copy link
Member

@wallyqs wallyqs left a comment

Choose a reason for hiding this comment

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

LGTM!

@wallyqs wallyqs merged commit 621a503 into master Sep 5, 2020
@wallyqs wallyqs deleted the add-leaf-node-remotes-config branch September 5, 2020 00:14
@Kampe
Copy link

Kampe commented Oct 7, 2020

Question for you all, when I start my nats servers I should see some connection logs about the leaf nodes connecting? Is there a way to verify the connections?

@variadico
Copy link
Contributor Author

Yeah, you should see something like this.

nats-server -c /tmp/leaf.conf 
....
[3704] 2019/12/09 09:55:31.548308 [INF] Listening for client connections on 127.0.0.1:4111
...
[3704] 2019/12/09 09:55:31.549404 [INF] Connected leafnode to "localhost"

Source: https://docs.nats.io/nats-server/configuration/leafnodes

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.

Create nats leaf remote connection
4 participants