Skip to content

Commit

Permalink
Merge pull request #16813 from rifelpet/ipv6-kops-controller
Browse files Browse the repository at this point in the history
Include all APIserver addresses for nodeup config
  • Loading branch information
k8s-ci-robot authored Sep 7, 2024
2 parents 9666e6f + 6261b0f commit eac588a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/nodemodel/nodeupconfigbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nodemodel
import (
"fmt"
"net"
"net/netip"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -318,14 +319,18 @@ func (n *nodeUpConfigBuilder) BuildConfig(ig *kops.InstanceGroup, wellKnownAddre
var controlPlaneIPs []string
switch cluster.GetCloudProvider() {
case kops.CloudProviderAWS, kops.CloudProviderHetzner, kops.CloudProviderOpenstack:
// Use a private IP address that belongs to the cluster network CIDR (some additional addresses may be FQDNs or public IPs)
// Use a private IP address that belongs to the cluster network CIDR, or any IPv6 addresses (some additional addresses may be FQDNs or public IPs)
for _, additionalIP := range wellKnownAddresses[wellknownservices.KubeAPIServer] {
for _, networkCIDR := range append(cluster.Spec.Networking.AdditionalNetworkCIDRs, cluster.Spec.Networking.NetworkCIDR) {
_, cidr, err := net.ParseCIDR(networkCIDR)
cidr, err := netip.ParsePrefix(networkCIDR)
if err != nil {
return nil, nil, fmt.Errorf("failed to parse network CIDR %q: %w", networkCIDR, err)
}
if cidr.Contains(net.ParseIP(additionalIP)) {
ip, err := netip.ParseAddr(additionalIP)
if err != nil {
continue
}
if cidr.Contains(ip) || ip.Is6() {
controlPlaneIPs = append(controlPlaneIPs, additionalIP)
}
}
Expand All @@ -336,11 +341,15 @@ func (n *nodeUpConfigBuilder) BuildConfig(ig *kops.InstanceGroup, wellKnownAddre
// Note that on GCE subnets have IP ranges, networks do not
for _, apiserverIP := range wellKnownAddresses[wellknownservices.KubeAPIServer] {
for _, subnet := range cluster.Spec.Networking.Subnets {
_, cidr, err := net.ParseCIDR(subnet.CIDR)
cidr, err := netip.ParsePrefix(subnet.CIDR)
if err != nil {
return nil, nil, fmt.Errorf("failed to parse subnet CIDR %q: %w", subnet.CIDR, err)
}
if cidr.Contains(net.ParseIP(apiserverIP)) {
ip, err := netip.ParseAddr(apiserverIP)
if err != nil {
continue
}
if cidr.Contains(ip) {
controlPlaneIPs = append(controlPlaneIPs, apiserverIP)
}
}
Expand Down
3 changes: 3 additions & 0 deletions upup/pkg/fi/cloudup/awstasks/network_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ func (e *NetworkLoadBalancer) FindAddresses(c *fi.CloudupContext) ([]string, err
if fi.ValueOf(ni.PrivateIpAddress) != "" {
addresses = append(addresses, fi.ValueOf(ni.PrivateIpAddress))
}
for _, v6 := range ni.Ipv6Addresses {
addresses = append(addresses, fi.ValueOf(v6.Ipv6Address))
}
}
}
}
Expand Down

0 comments on commit eac588a

Please sign in to comment.