-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateCluster.go
54 lines (42 loc) · 1.38 KB
/
CreateCluster.go
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
48
49
50
51
52
53
54
// Package demoautomation contains functions required to automate edge cloud resource provisioning
package demoautomation
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/decentralized-cloud/demo-automation/services/configuration"
"github.com/decentralized-cloud/demo-automation/services/gce/gke"
)
var gkeService gke.GkeContract
func init() {
configurationService, err := configuration.NewEnvConfigurationService()
if err != nil {
log.Fatalf("Failed to create configuration service. Error: %v\n", err)
}
gkeService, err = gke.NewGkeService(configurationService)
if err != nil {
log.Fatalf("Failed to create gkeService service. Error: %v\n", err)
}
}
// CreateCluster creates a new GKE cluster
func CreateCluster(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintln(w, "Only http POST method is supported")
return
}
request := gke.CreateClusterRequest{}
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Failed to decode the provided request. Error: %v\n", err)
return
}
_, err := gkeService.CreateCluster(r.Context(), &request)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Failed to create cluster. Error: %v\n", err)
return
}
w.WriteHeader(http.StatusAccepted)
}