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

etcd: Add initial support for an IPv6 control plane #1211

Merged
merged 4 commits into from
Dec 20, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 27 additions & 6 deletions cmd/setup-etcd-environment/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,34 @@ func runRunCmd(cmd *cobra.Command, args []string) error {
return err
}

parsedIP := net.ParseIP(setupEnv.etcdIP)
if parsedIP == nil {
return fmt.Errorf("Failed to parse IP '%s'", setupEnv.etcdIP)
}

escapedIP := setupEnv.etcdIP
escapedAllIPs := "0.0.0.0"
localhostIP := "127.0.0.1"
escapedLocalhostIP := "127.0.0.1"
if parsedIP.To4() == nil {
// This is an IPv6 address, not IPv4.

// When using an IPv6 address in a URL, we must wrap the address portion in
// [::] so that a ":port" suffix can still be added and parsed correctly.
escapedIP = fmt.Sprintf("[%s]", setupEnv.etcdIP)
escapedAllIPs = "[::]"
localhostIP = "::1"
escapedLocalhostIP = "[::1]"
}

unexportedEnv := map[string]string{
"IPV4_ADDRESS": setupEnv.etcdIP,
"WILDCARD_DNS_NAME": fmt.Sprintf("*.%s", setupEnv.opts.discoverySRV),
// TODO This can actually be IPv6, so we should rename this ...
"IPV4_ADDRESS": setupEnv.etcdIP,
"ESCAPED_IP_ADDRESS": escapedIP,
"ESCAPED_ALL_IPS": escapedAllIPs,
Copy link
Contributor

Choose a reason for hiding this comment

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

It would really help readability if instead of ESCAPED_ALL_IPS we have LISTEN_CLIENT_URLS and LISTEN_PEER_URLS

Copy link
Member Author

Choose a reason for hiding this comment

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

we'd need LISTEN_CLIENT_URLS, LISETN_PEER_URLS, LISTEN_METRIC_URLS, and METRICS_ADDR. sure you want 4 variables instead of this 1?

Copy link
Contributor

Choose a reason for hiding this comment

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

@russellb thanks for pointing out, I thought it would make the naming more explicit but having 4 variables instead of 1 would be an overdo. Feel free to mark it resolved.

"LOCALHOST_IP": localhostIP,
"ESCAPED_LOCALHOST_IP": escapedLocalhostIP,
Copy link
Contributor

Choose a reason for hiding this comment

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

confused why we need both, is it possible to conditionally set LOCALHOST_IP and conditionally escape it if ipv6?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's kind of annoying, because we only want to use it in its escaped form in some cases (in a URL), but not when it's provided as a raw IP, that's why it's there twice

"WILDCARD_DNS_NAME": fmt.Sprintf("*.%s", setupEnv.opts.discoverySRV),
}
if setupEnv.etcdDNS != "" {
unexportedEnv["DNS_NAME"] = setupEnv.etcdDNS
Expand Down Expand Up @@ -338,10 +363,6 @@ func ipAddrs(preferredIP string) ([]string, error) {
if ip == nil {
continue
}
ip = ip.To4()
if ip == nil {
continue // not an ipv4 address
}
if !ip.IsGlobalUnicast() {
continue // we only want global unicast address
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func etcdServerCertCommand(cfg RenderConfig) (interface{}, error) {
" --assetsdir=/etc/ssl/etcd \\",
fmt.Sprintf(" --dnsnames=%s \\", serverCertDNS),
" --commonname=system:etcd-server:${ETCD_DNS_NAME} \\",
" --ipaddrs=${ETCD_IPV4_ADDRESS},127.0.0.1 \\",
" --ipaddrs=${ETCD_IPV4_ADDRESS},${ETCD_LOCALHOST_IP} \\",
}...)
} else {
commands = append(commands, []string{
Expand Down
1 change: 1 addition & 0 deletions templates/common/_base/files/sysctl-forward-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ path: "/etc/sysctl.d/forward.conf"
contents:
inline: |
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1

Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ contents:
set +a

exec etcd \
--initial-advertise-peer-urls=https://${ETCD_IPV4_ADDRESS}:2380 \
--initial-advertise-peer-urls=https://${ETCD_ESCAPED_IP_ADDRESS}:2380 \
--cert-file=/etc/ssl/etcd/system:etcd-server:${ETCD_DNS_NAME}.crt \
--key-file=/etc/ssl/etcd/system:etcd-server:${ETCD_DNS_NAME}.key \
--trusted-ca-file=/etc/ssl/etcd/ca.crt \
Expand All @@ -144,10 +144,10 @@ contents:
--peer-key-file=/etc/ssl/etcd/system:etcd-peer:${ETCD_DNS_NAME}.key \
--peer-trusted-ca-file=/etc/ssl/etcd/ca.crt \
--peer-client-cert-auth=true \
--advertise-client-urls=https://${ETCD_IPV4_ADDRESS}:2379 \
--listen-client-urls=https://0.0.0.0:2379 \
--listen-peer-urls=https://0.0.0.0:2380 \
--listen-metrics-urls=https://0.0.0.0:9978 \
--advertise-client-urls=https://${ETCD_ESCAPED_IP_ADDRESS}:2379 \
--listen-client-urls=https://${ETCD_ESCAPED_ALL_IPS}:2379 \
--listen-peer-urls=https://${ETCD_ESCAPED_ALL_IPS}:2380 \
--listen-metrics-urls=https://${ETCD_ESCAPED_ALL_IPS}:9978 \
securityContext:
privileged: true
resources:
Expand Down Expand Up @@ -194,8 +194,8 @@ contents:

exec etcd grpc-proxy start \
--endpoints https://${ETCD_DNS_NAME}:9978 \
--metrics-addr https://0.0.0.0:9979 \
--listen-addr 127.0.0.1:9977 \
--metrics-addr https://${ETCD_ESCAPED_ALL_IPS}:9979 \
--listen-addr ${ETCD_ESCAPED_LOCALHOST_IP}:9977 \
--key /etc/ssl/etcd/system:etcd-peer:${ETCD_DNS_NAME}.key \
--key-file /etc/ssl/etcd/system:etcd-metric:${ETCD_DNS_NAME}.key \
--cert /etc/ssl/etcd/system:etcd-peer:${ETCD_DNS_NAME}.crt \
Expand Down