From 713429433b86049234a205d06dadc68dd0fe6551 Mon Sep 17 00:00:00 2001 From: Matt Hook Date: Tue, 5 Sep 2023 16:32:19 +1200 Subject: [PATCH] speed up namespace lookup --- http/handler/kubernetes/handler.go | 3 ++ .../kubernetes/kubernetes_namespaces.go | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 http/handler/kubernetes/kubernetes_namespaces.go diff --git a/http/handler/kubernetes/handler.go b/http/handler/kubernetes/handler.go index 6b47dd0e..304f9131 100644 --- a/http/handler/kubernetes/handler.go +++ b/http/handler/kubernetes/handler.go @@ -25,5 +25,8 @@ func NewHandler(notaryService *security.NotaryService, kubernetesDeployer *exec. h.Handle("/kubernetes/stack", notaryService.DigitalSignatureVerification(httperror.LoggerHandler(h.kubernetesDeploy))).Methods(http.MethodPost) + h.Handle("/kubernetes/namespaces", + notaryService.DigitalSignatureVerification(httperror.LoggerHandler(h.kubernetesGetNamespaces))).Methods(http.MethodGet) + return h } diff --git a/http/handler/kubernetes/kubernetes_namespaces.go b/http/handler/kubernetes/kubernetes_namespaces.go new file mode 100644 index 00000000..a2175a95 --- /dev/null +++ b/http/handler/kubernetes/kubernetes_namespaces.go @@ -0,0 +1,33 @@ +package kubernetes + +import ( + "fmt" + "net/http" + + httperror "github.com/portainer/portainer/pkg/libhttp/error" + "github.com/portainer/portainer/pkg/libhttp/request" + "github.com/portainer/portainer/pkg/libhttp/response" +) + +type getNamespacePayload struct{} + +func (payload *getNamespacePayload) Validate(r *http.Request) error { + + return nil +} + +func (handler *Handler) kubernetesGetNamespaces(rw http.ResponseWriter, r *http.Request) *httperror.HandlerError { + var payload getNamespacePayload + err := request.DecodeAndValidateJSONPayload(r, &payload) + if err != nil { + return httperror.BadRequest("Invalid request payload", err) + } + + for _, header := range r.Header { + for _, value := range header { + fmt.Println("Header:", value) + } + } + + return response.Empty(rw) +}