Skip to content

Commit

Permalink
Merge pull request #284 from nats-io/add-leaf-node-remotes-config
Browse files Browse the repository at this point in the history
Add leaf node remotes config
  • Loading branch information
wallyqs authored Sep 5, 2020
2 parents 4e2be5e + fafdb24 commit 621a503
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 7 deletions.
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

leafnodeConfig:
remotes:
- url: nats://1.2.3.4:7422
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

0 comments on commit 621a503

Please sign in to comment.