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

bug 1806723: use correct IP for bootstrap host env vars #200

Merged
merged 2 commits into from
Feb 25, 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
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")
Copy link
Contributor

Choose a reason for hiding this comment

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

you could just do "https://"+net.JoinHostPort(bootstrapIP, "2379") and not need dnshelpers.GetURLHostForIP

}

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