From 57d1305db9f032c94949b719f0dc052ac7cd2d41 Mon Sep 17 00:00:00 2001 From: hthieu Date: Thu, 1 Jul 2021 20:03:09 +0200 Subject: Support pre/post install/delete hooks   MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update instance create and delete handler to support pre/post install/delete hooks.  Add hook.go: to execute and delete hook (base on delete policy).  Implement watchUntilReady in generic plugin to wait for readiness of hook rss. Add hook_sorter.go: to sort hook based on weight. User can define timeout for each type of hooks in overwrite-values. Variable name is k8s-rb-instance-pre-install-timeout (default 60s), k8s-rb-instance-post-install-timeout (default 600s), k8s-rb-instance-pre-delete-timeout (default 60s) and k8s-rb-instance-post-delete-timeout (600s). This is timeout for each hook of a hook event (not a total time). Add recovery capability to continue the execution of instantiation (create or delete) when the plugin stop unexpectedly. For now, this is disabled because we have data-race issue during test. Will enable when we find the solution. Add basic test for hooks (in hook_test.go) Add test for hook in instance_test For instance get request, we can request for full data by adding query param to the request: full=true. Issue-ID: MULTICLOUD-1347 Signed-off-by: hthieu Change-Id: If2b4a90831b9bfce1af8b926e4062a7d706bee08 --- src/k8splugin/api/api.go | 1 + src/k8splugin/api/instancehandler.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/k8splugin/api') diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go index 33eaefca..94fb9b34 100644 --- a/src/k8splugin/api/api.go +++ b/src/k8splugin/api/api.go @@ -50,6 +50,7 @@ func NewRouter(defClient rb.DefinitionManager, Queries("rb-name", "{rb-name}", "rb-version", "{rb-version}", "profile-name", "{profile-name}").Methods("GET") + //Want to get full Data -> add query param: /install/{instID}?full=true instRouter.HandleFunc("/instance/{instID}", instHandler.getHandler).Methods("GET") instRouter.HandleFunc("/instance/{instID}/status", instHandler.statusHandler).Methods("GET") instRouter.HandleFunc("/instance/{instID}/query", instHandler.queryHandler).Methods("GET") diff --git a/src/k8splugin/api/instancehandler.go b/src/k8splugin/api/instancehandler.go index 3baa8065..3fc514cd 100644 --- a/src/k8splugin/api/instancehandler.go +++ b/src/k8splugin/api/instancehandler.go @@ -122,8 +122,15 @@ func (i instanceHandler) createHandler(w http.ResponseWriter, r *http.Request) { func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := vars["instID"] + var resp interface{} + var err error + + if r.URL.Query().Get("full") == "true" { + resp, err = i.client.GetFull(id) + } else { + resp, err = i.client.Get(id) + } - resp, err := i.client.Get(id) if err != nil { log.Error("Error getting Instance", log.Fields{ "error": err, @@ -132,7 +139,6 @@ func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) { 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) -- cgit 1.2.3-korg