func (s *SealosInstaller) appendAPIServer() error {
etcHostPath := "/etc/hosts"
etcHostMap := fmt.Sprintf("%s %s", IPFormat(s.Masters[0]), APIServer)
file, err := os.OpenFile(etcHostPath, os.O_RDWR|os.O_APPEND, 0666)
if err != nil {
os.Exit(1)
}
defer file.Close()
reader := bufio.NewReader(file)
for {
str, err := reader.ReadString('\n')
if strings.Contains(str, APIServer) {
logger.Info("local %s is already exists %s", etcHostPath, APIServer)
return nil
}
if err == io.EOF {
break
}
}
write := bufio.NewWriter(file)
_, _ = write.WriteString(etcHostMap)
return write.Flush()
}