/
admin_handlers.go
152 lines (121 loc) · 5.62 KB
/
admin_handlers.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package fakerp
import (
"net/http"
"github.com/go-chi/chi"
"github.com/openshift/openshift-azure/pkg/api"
"github.com/openshift/openshift-azure/pkg/fakerp/client"
)
// handleBackup handles admin requests to backup an etcd cluster
func (s *Server) handleBackup(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
backupName := chi.URLParam(req, "backupName")
err := s.plugin.BackupEtcdCluster(req.Context(), cs, backupName)
s.adminreply(w, err, nil)
}
// handleGetControlPlanePods handles admin requests for the list of control plane pods
func (s *Server) handleGetControlPlanePods(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
pods, err := s.plugin.GetControlPlanePods(req.Context(), cs)
s.adminreply(w, err, pods)
}
// handleListClusterVMs handles admin requests for the list of cluster VMs
func (s *Server) handleListClusterVMs(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
vms, err := s.plugin.ListClusterVMs(req.Context(), cs)
s.adminreply(w, err, vms)
}
// handleReimage handles reimaging a vm in the cluster
func (s *Server) handleReimage(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
hostname := chi.URLParam(req, "hostname")
err := s.plugin.Reimage(req.Context(), cs, hostname)
s.adminreply(w, err, nil)
}
// handleListBackups handles admin requests to list etcd backups
func (s *Server) handleListBackups(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
backups, pluginErr := s.plugin.ListEtcdBackups(req.Context(), cs)
var err error
if pluginErr != nil {
// TODO: fix this nastiness: https://golang.org/doc/faq#nil_error
err = pluginErr
}
s.adminreply(w, err, backups)
}
// handleRestore handles admin requests to restore an etcd cluster from a backup
func (s *Server) handleRestore(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
config := req.Context().Value(contextKeyConfig).(*client.Config)
backupName := chi.URLParam(req, "backupName")
pluginErr := s.plugin.RecoverEtcdCluster(req.Context(), cs, GetDeployer(s.log, cs, config, s.testConfig), backupName)
var err error
if pluginErr != nil {
// TODO: fix this nastiness: https://golang.org/doc/faq#nil_error
err = pluginErr
}
s.adminreply(w, err, nil)
}
// handleRotateSecrets handles admin requests for the rotation of cluster secrets
func (s *Server) handleRotateSecrets(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
config := req.Context().Value(contextKeyConfig).(*client.Config)
pluginErr := s.plugin.RotateClusterSecrets(req.Context(), cs, GetDeployer(s.log, cs, config, s.testConfig))
if pluginErr != nil {
s.badRequest(w, pluginErr.Error())
return
}
s.store.Put(cs)
err := writeHelpers(s.log, cs)
s.adminreply(w, err, nil)
}
// handleRotateCertificates handles admin requests for the rotation of cluster secrets
func (s *Server) handleRotateCertificates(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
config := req.Context().Value(contextKeyConfig).(*client.Config)
pluginErr := s.plugin.RotateClusterCertificates(req.Context(), cs, GetDeployer(s.log, cs, config, s.testConfig))
if pluginErr != nil {
s.badRequest(w, pluginErr.Error())
return
}
s.store.Put(cs)
err := writeHelpers(s.log, cs)
s.adminreply(w, err, nil)
}
// handleRotateCertificatesAndSecrets handles admin requests for the rotation of cluster secrets
func (s *Server) handleRotateCertificatesAndSecrets(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
config := req.Context().Value(contextKeyConfig).(*client.Config)
pluginErr := s.plugin.RotateClusterCertificatesAndSecrets(req.Context(), cs, GetDeployer(s.log, cs, config, s.testConfig))
if pluginErr != nil {
s.badRequest(w, pluginErr.Error())
return
}
s.store.Put(cs)
err := writeHelpers(s.log, cs)
s.adminreply(w, err, nil)
}
// handleForceUpdate handles admin requests for the force updates of clusters
func (s *Server) handleForceUpdate(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
config := req.Context().Value(contextKeyConfig).(*client.Config)
pluginErr := s.plugin.ForceUpdate(req.Context(), cs, GetDeployer(s.log, cs, config, s.testConfig))
var err error
if pluginErr != nil {
// TODO: fix this nastiness: https://golang.org/doc/faq#nil_error
err = pluginErr
}
s.adminreply(w, err, nil)
}
// handleRunCommand handles running generic commands on a given vm within a scaleset in the cluster
func (s *Server) handleRunCommand(w http.ResponseWriter, req *http.Request) {
cs := req.Context().Value(contextKeyContainerService).(*api.OpenShiftManagedCluster)
hostname := chi.URLParam(req, "hostname")
command := chi.URLParam(req, "command")
err := s.plugin.RunCommand(req.Context(), cs, hostname, api.Command(command))
s.adminreply(w, err, nil)
}
// handleGetPluginVersion handles admin requests to get the RP plugin version for OpenShiftManagedClusters
func (s *Server) handleGetPluginVersion(w http.ResponseWriter, req *http.Request) {
version := s.plugin.GetPluginVersion(req.Context())
s.adminreply(w, nil, version)
}