in internal/kubelet/config.go [182:216]
func (ksc *kubeletConfig) withOutpostSetup(cfg *api.NodeConfig) error {
if enabled := cfg.Spec.Cluster.EnableOutpost; enabled != nil && *enabled {
zap.L().Info("Setting up outpost..")
if cfg.Spec.Cluster.ID == "" {
return fmt.Errorf("clusterId cannot be empty when outpost is enabled.")
}
apiUrl, err := url.Parse(cfg.Spec.Cluster.APIServerEndpoint)
if err != nil {
return err
}
// TODO: cleanup
ipAddresses, err := net.LookupHost(apiUrl.Host)
if err != nil {
return err
}
var ipHostMappings []string
for _, ip := range ipAddresses {
ipHostMappings = append(ipHostMappings, fmt.Sprintf("%s\t%s", ip, apiUrl.Host))
}
output := strings.Join(ipHostMappings, "\n") + "\n"
// append to /etc/hosts file with shuffled mappings of "IP address to API server domain name"
f, err := os.OpenFile("/etc/hosts", os.O_APPEND|os.O_WRONLY, kubeletConfigPerm)
if err != nil {
return err
}
defer f.Close()
if _, err := f.WriteString(output); err != nil {
return err
}
}
return nil
}