From 120019529489b5cbcf82d77eec228283fb12d43a Mon Sep 17 00:00:00 2001 From: Konrad Bańka Date: Fri, 12 Mar 2021 08:46:20 +0100 Subject: Fix Healthcheck API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I5da50363bb240fdc85d3624f43cb0526786da542 --- src/k8splugin/api/instancehchandler.go | 67 +++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'src/k8splugin/api/instancehchandler.go') 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 + } } -- cgit 1.2.3-korg