Skip to content

Commit

Permalink
Merge pull request #200 from deads2k/use-host-etcd-2
Browse files Browse the repository at this point in the history
bug 1806723: use correct IP for bootstrap host env vars
  • Loading branch information
openshift-merge-robot authored Feb 25, 2020
2 parents 6ff2c92 + 3c0172c commit e4e8d68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
12 changes: 12 additions & 0 deletions pkg/dnshelpers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ func GetEscapedPreferredInternalIPAddressForNodeName(network *configv1.Network,
}
}

func GetURLHostForIP(ip string) (string, error) {
isIPV4, err := IsIPv4(ip)
if err != nil {
return "", err
}
if isIPV4 {
return ip, nil
}

return "[" + ip + "]", nil
}

// GetPreferredInternalIPAddressForNodeName returns the first internal ip address of the correct family and the family
func GetPreferredInternalIPAddressForNodeName(network *configv1.Network, node *corev1.Node) (string, string, error) {
ipFamily, err := GetPreferredIPFamily(network)
Expand Down
24 changes: 8 additions & 16 deletions pkg/operator/targetconfigcontroller/etcd_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,18 @@ func getAllClusterMembers(envVarContext envVarContext) (map[string]string, error
endpoints = append(endpoints, fmt.Sprintf("https://%s:2379", endpointIP))
}

hostEtcdEndpoints, err := envVarContext.endpointLister.Endpoints(operatorclient.TargetNamespace).Get("host-etcd")
hostEtcdEndpoints, err := envVarContext.endpointLister.Endpoints(operatorclient.TargetNamespace).Get("host-etcd-2")
if err != nil {
return nil, err
}
for _, endpointAddress := range hostEtcdEndpoints.Subsets[0].Addresses {
if endpointAddress.Hostname == "etcd-bootstrap" {

isIPV4, err := dnshelpers.IsIPv4(endpointAddress.IP)
if err != nil {
return nil, err
}
if isIPV4 {
endpoints = append(endpoints, "https://"+endpointAddress.IP+":2379")
} else {
endpoints = append(endpoints, "https://["+endpointAddress.IP+"]:2379")
}

break
if bootstrapIP := hostEtcdEndpoints.Annotations["alpha.installer.openshift.io/etcd-bootstrap"]; len(bootstrapIP) > 0 {
urlHost, err := dnshelpers.GetURLHostForIP(bootstrapIP)
if err != nil {
return nil, err
}
endpoints = append(endpoints, "https://"+urlHost+":2379")
}

ret["ALL_ETCD_ENDPOINTS"] = strings.Join(endpoints, ",")

return ret, nil
Expand Down Expand Up @@ -151,7 +143,7 @@ func getEscapedIPAddress(envVarContext envVarContext) (map[string]string, error)
if err != nil {
return nil, err
}
ret[fmt.Sprintf("NODE_%s_IP", envVarSafe(nodeInfo.NodeName))] = "[" + escapedIPAddress + "]"
ret[fmt.Sprintf("NODE_%s_IP", envVarSafe(nodeInfo.NodeName))] = escapedIPAddress
}

return ret, nil
Expand Down

0 comments on commit e4e8d68

Please sign in to comment.