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
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
49 changes: 49 additions & 0 deletions example/leafnode-remotes-gateways.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# NOTE: Replace the 1.2.3.4 IPs with real IPs or a domain. Also include a real
# base64 encoded credentials file.

---
apiVersion: v1
kind: Secret
metadata:
name: user-credentials
data:
user.ncreds: ...base64-encoded-credentials...

---
apiVersion: nats.io/v1alpha2
kind: NatsCluster
metadata:
name: example-nats-cluster
spec:
size: 3
version: "2.1.7"

natsConfig:
debug: true
trace: true

pod:
volumeMounts:
- name: user-credentials
mountPath: /etc/nats-creds
readOnl: true
variadico marked this conversation as resolved.
Show resolved Hide resolved

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

credentials: /etc/nats-creds/user.ncreds

gatewayConfig:
name: gateway_b
hostPort: 7222
rejectUnknown: true
gateways:
- name: gateway_a
url: nats://guser:[email protected]:7222

template:
spec:
volumes:
- name: user-credentials
secret:
secretName: user-credentials
10 changes: 9 additions & 1 deletion pkg/apis/nats/v1alpha2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,17 @@ type RemoteGatewayOpts struct {
URL string `json:"url,omitempty"`
}

// LeafNodeRemote is the URL for remote NATS system.
type LeafNodeRemote struct {
URL string `json:"url,omitempty"`
URLs []string `json:"urls,omitempty"`
Credentials string `json:"credentials,omitempty"`
}

// LeafNodeConfig is the configuration for leafnodes.
type LeafNodeConfig struct {
Port int `json:"hostPort,omitempty"`
Port int `json:"hostPort,omitempty"`
Remotes []LeafNodeRemote `json:"remotes,omitempty"`
}

// TLSConfig is the optional TLS configuration for the cluster.
Expand Down
30 changes: 29 additions & 1 deletion pkg/apis/nats/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions pkg/conf/natsconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ type GatewayConfig struct {
Authorization *AuthorizationConfig `json:"authorization,omitempty"`
}

// LeafNodeRemote is the URL for remote NATS system.
type LeafNodeRemote struct {
URLs []string `json:"urls,omitempty"`
Credentials string `json:"credentials,omitempty"`
}

type LeafNodeServerConfig struct {
Port int `json:"port,omitempty"`
TLS *TLSConfig `json:"tls,omitempty"`
TLSTimeout float64 `json:"tls_timeout,omitempty"`
Advertise string `json:"advertise,omitempty"`
Include string `json:"include,omitempty"`
Port int `json:"port,omitempty"`
TLS *TLSConfig `json:"tls,omitempty"`
TLSTimeout float64 `json:"tls_timeout,omitempty"`
Advertise string `json:"advertise,omitempty"`
Include string `json:"include,omitempty"`
Remotes []LeafNodeRemote `json:"remotes,omitempty"`
}

type RemoteGatewayOpts struct {
Expand Down
15 changes: 15 additions & 0 deletions pkg/util/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,21 @@ func addGatewayConfig(sconfig *natsconf.ServerConfig, cluster v1alpha2.ClusterSp
sconfig.LeafNode = &natsconf.LeafNodeServerConfig{
Port: cluster.LeafNodeConfig.Port,
}
for _, r := range cluster.LeafNodeConfig.Remotes {
var urls []string
if r.URL != "" {
urls = append(urls, r.URL)
}
if len(r.URLs) > 0 {
urls = append(urls, r.URLs...)
}

sconfig.LeafNode.Remotes = append(sconfig.LeafNode.Remotes, natsconf.LeafNodeRemote{
URLs: urls,
Credentials: r.Credentials,
})
}

if cluster.Pod != nil && cluster.Pod.AdvertiseExternalIP {
sconfig.LeafNode.Include = filepath.Join(".", constants.BootConfigGatewayFilePath)
}
Expand Down