Skip to content

Commit

Permalink
cluster/client: advertise pod hostname
Browse files Browse the repository at this point in the history
Fixes nats-io#32

Signed-off-by: Paulo Pires <pjpires@gmail.com>
  • Loading branch information
pires authored and wallyqs committed Feb 22, 2019
1 parent 0557c5f commit fc95a34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/cluster/cluster.go
Expand Up @@ -330,7 +330,7 @@ func (c *Cluster) createPod() (*v1.Pod, error) {
}

// Create the pod.
pod := kubernetesutil.NewNatsPodSpec(name, c.cluster.Name, c.cluster.Spec, c.cluster.AsOwner())
pod := kubernetesutil.NewNatsPodSpec(c.cluster.Namespace, name, c.cluster.Name, c.cluster.Spec, c.cluster.AsOwner())
pod, err = c.config.KubeCli.Pods(c.cluster.Namespace).Create(pod)
if err != nil {
return nil, err
Expand Down
10 changes: 9 additions & 1 deletion pkg/util/kubernetes/kubernetes.go
Expand Up @@ -593,7 +593,7 @@ func addOwnerRefToObject(o metav1.Object, r metav1.OwnerReference) {
}

// NewNatsPodSpec returns a NATS peer pod specification, based on the cluster specification.
func NewNatsPodSpec(name, clusterName string, cs v1alpha2.ClusterSpec, owner metav1.OwnerReference) *v1.Pod {
func NewNatsPodSpec(namespace, name, clusterName string, cs v1alpha2.ClusterSpec, owner metav1.OwnerReference) *v1.Pod {
labels := map[string]string{
LabelAppKey: "nats",
LabelClusterNameKey: clusterName,
Expand Down Expand Up @@ -649,13 +649,21 @@ func NewNatsPodSpec(name, clusterName string, cs v1alpha2.ClusterSpec, owner met
container = containerWithRequirements(container, cs.Pod.Resources)
}

// Grab the A record that will correspond to the current pod so we can use it as the client and cluster advertise host.
// This helps with client failover, and with avoiding route connection errors in TLS-enabled clusters.
advertiseHost := fmt.Sprintf("%s.%s.%s.svc", name, ManagementServiceName(clusterName), namespace)

// Rely on the shared configuration map for configuring the cluster.
cmd := []string{
constants.NatsBinaryPath,
"-c",
constants.ConfigFilePath,
"-P",
constants.PidFilePath,
"--cluster_advertise",
advertiseHost,
"--client_advertise",
advertiseHost,
}
if cs.NoAdvertise {
cmd = append(cmd, "--no_advertise")
Expand Down

0 comments on commit fc95a34

Please sign in to comment.