GetClusterDNS returns the DNS address to use
(clusterConfig *api.ClusterConfig)
| 86 | |
| 87 | // GetClusterDNS returns the DNS address to use |
| 88 | func GetClusterDNS(clusterConfig *api.ClusterConfig) (string, error) { |
| 89 | networkConfig := clusterConfig.Status.KubernetesNetworkConfig |
| 90 | if networkConfig == nil { |
| 91 | return "", nil |
| 92 | } |
| 93 | |
| 94 | var ( |
| 95 | serviceCIDR string |
| 96 | toClusterDNS func(net.IP) string |
| 97 | ) |
| 98 | |
| 99 | if networkConfig.ServiceIPv4CIDR != "" { |
| 100 | serviceCIDR = networkConfig.ServiceIPv4CIDR |
| 101 | toClusterDNS = func(parsedIP net.IP) string { |
| 102 | ip := parsedIP.To4() |
| 103 | ip[net.IPv4len-1] = 10 |
| 104 | return ip.String() |
| 105 | } |
| 106 | } |
| 107 | if networkConfig.ServiceIPv6CIDR != "" { |
| 108 | serviceCIDR = networkConfig.ServiceIPv6CIDR |
| 109 | toClusterDNS = func(parsedIP net.IP) string { |
| 110 | ip := parsedIP.To16() |
| 111 | ip[net.IPv6len-1] = 10 |
| 112 | return ip.String() |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | parsedIP, _, err := net.ParseCIDR(serviceCIDR) |
| 117 | if err != nil { |
| 118 | return "", fmt.Errorf("unexpected error parsing KubernetesNetworkConfig service CIDR: %q: %w", serviceCIDR, err) |
| 119 | } |
| 120 | return toClusterDNS(parsedIP), nil |
| 121 | } |
| 122 | |
| 123 | func linuxConfig(clusterConfig *api.ClusterConfig, bootScriptName, bootScriptContent, clusterDNS string, np api.NodePool, scripts ...script) (string, error) { |
| 124 | config := cloudconfig.New() |
no test coverage detected