-
Notifications
You must be signed in to change notification settings - Fork 88
/
kurl_node_join_command.go
95 lines (84 loc) · 2.31 KB
/
kurl_node_join_command.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package handlers
import (
"net/http"
"time"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/kurl"
"github.com/replicatedhq/kots/pkg/logger"
)
type GenerateNodeJoinCommandResponse struct {
Command []string `json:"command"`
Expiry string `json:"expiry"`
}
func (h *Handler) GenerateNodeJoinCommandWorker(w http.ResponseWriter, r *http.Request) {
client, err := k8sutil.GetClientset()
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
command, expiry, err := kurl.GenerateAddNodeCommand(client, false)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
JSON(w, http.StatusOK, GenerateNodeJoinCommandResponse{
Command: command,
Expiry: expiry.Format(time.RFC3339),
})
}
func (h *Handler) GenerateNodeJoinCommandMaster(w http.ResponseWriter, r *http.Request) {
client, err := k8sutil.GetClientset()
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
command, expiry, err := kurl.GenerateAddNodeCommand(client, true)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
JSON(w, http.StatusOK, GenerateNodeJoinCommandResponse{
Command: command,
Expiry: expiry.Format(time.RFC3339),
})
}
func (h *Handler) GenerateNodeJoinCommandSecondary(w http.ResponseWriter, r *http.Request) {
client, err := k8sutil.GetClientset()
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
command, expiry, err := kurl.GenerateAddNodeCommand(client, false)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
JSON(w, http.StatusOK, GenerateNodeJoinCommandResponse{
Command: command,
Expiry: expiry.Format(time.RFC3339),
})
}
func (h *Handler) GenerateNodeJoinCommandPrimary(w http.ResponseWriter, r *http.Request) {
client, err := k8sutil.GetClientset()
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
command, expiry, err := kurl.GenerateAddNodeCommand(client, true)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
JSON(w, http.StatusOK, GenerateNodeJoinCommandResponse{
Command: command,
Expiry: expiry.Format(time.RFC3339),
})
}