aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api
diff options
context:
space:
mode:
authorKonrad Bańka <k.banka@samsung.com>2021-03-12 08:46:20 +0100
committerKonrad Bańka <k.banka@samsung.com>2021-03-31 18:34:14 +0200
commit120019529489b5cbcf82d77eec228283fb12d43a (patch)
treedd404d0816bf0c86db0ced390c67fadd619900a1 /src/k8splugin/api
parent4068b83937c490e638db0b8b0aceb8b7a88b7461 (diff)
Fix Healthcheck API
Fix several issues related to Healthcheck creation. Updated GET/DELETE methods to work properly. This commit leaves few FIXME/TODOs that will be handled within Helm3 Rebase commit Issue-ID: MULTICLOUD-1308 Signed-off-by: Konrad Bańka <k.banka@samsung.com> Change-Id: I5da50363bb240fdc85d3624f43cb0526786da542
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r--src/k8splugin/api/instancehchandler.go67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/k8splugin/api/instancehchandler.go b/src/k8splugin/api/instancehchandler.go
index fc1c3be4..90715178 100644
--- a/src/k8splugin/api/instancehchandler.go
+++ b/src/k8splugin/api/instancehchandler.go
@@ -46,7 +46,7 @@ func (ih instanceHCHandler) createHandler(w http.ResponseWriter, r *http.Request
}
w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
+ w.WriteHeader(http.StatusCreated)
err = json.NewEncoder(w).Encode(resp)
if err != nil {
log.Error("Error Marshaling Reponse", log.Fields{
@@ -59,10 +59,75 @@ func (ih instanceHCHandler) createHandler(w http.ResponseWriter, r *http.Request
}
func (ih instanceHCHandler) getHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ instanceId := vars["instID"]
+ healthcheckId := vars["hcID"]
+
+ resp, err := ih.client.Get(instanceId, healthcheckId)
+ if err != nil {
+ log.Error("Error getting Instance's healthcheck", log.Fields{
+ "error": err,
+ "instanceID": instanceId,
+ "healthcheckID": healthcheckId,
+ })
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(resp)
+ if err != nil {
+ log.Error("Error Marshaling Response", log.Fields{
+ "error": err,
+ "response": resp,
+ })
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
}
func (ih instanceHCHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ instanceId := vars["instID"]
+ healthcheckId := vars["hcID"]
+
+ err := ih.client.Delete(instanceId, healthcheckId)
+ if err != nil {
+ log.Error("Error deleting Instance's healthcheck", log.Fields{
+ "error": err,
+ "instanceID": instanceId,
+ "healthcheckID": healthcheckId,
+ })
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ w.WriteHeader(http.StatusAccepted)
}
func (ih instanceHCHandler) listHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ id := vars["instID"]
+
+ resp, err := ih.client.List(id)
+ if err != nil {
+ log.Error("Error getting instance healthcheck overview", log.Fields{
+ "error": err,
+ "instance-id": id,
+ })
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(resp)
+ if err != nil {
+ log.Error("Error Marshaling Response", log.Fields{
+ "error": err,
+ "response": resp,
+ })
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
}