forked from bacchus-snu/sgs-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkubeconfig.go
More file actions
47 lines (40 loc) · 1.14 KB
/
kubeconfig.go
File metadata and controls
47 lines (40 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"io"
"log"
"net/http"
"os"
"path/filepath"
)
func DownloadKubeconfig() {
kubeconfigURL := "https://raw.githubusercontent.com/bacchus-snu/sgs-cli/main/config.yaml"
destinationPath := filepath.Join(os.Getenv("HOME"), ".sgs", "config.yaml")
// Check if the file already exists
if _, err := os.Stat(destinationPath); os.IsNotExist(err) {
// Create the directory if it doesn't exist
err := os.MkdirAll(filepath.Dir(destinationPath), 0755)
if err != nil {
log.Fatalf("Failed to create directory: %v", err)
}
// Download the kubeconfig file
response, err := http.Get(kubeconfigURL)
if err != nil {
log.Fatalf("Failed to download kubeconfig file: %v", err)
}
defer response.Body.Close()
// Create the file
file, err := os.Create(destinationPath)
if err != nil {
log.Fatalf("Failed to create file: %v", err)
}
defer file.Close()
// Copy the response body to the file
_, err = io.Copy(file, response.Body)
if err != nil {
log.Fatalf("Failed to save kubeconfig file: %v", err)
}
log.Printf("Kubeconfig file downloaded successfully")
} else {
log.Printf("Kubeconfig file already exists")
}
}