(w http.ResponseWriter, r *http.Request)
| 264 | } |
| 265 | |
| 266 | func (h *handler) request(w http.ResponseWriter, r *http.Request) { |
| 267 | resource, ok := r.URL.Query()["resource"] |
| 268 | if !ok || len(resource) != 1 { |
| 269 | http.Error(w, "resource is missing", http.StatusBadRequest) |
| 270 | return |
| 271 | } |
| 272 | |
| 273 | // Build request options |
| 274 | options := &kubectl.GenericRequestOptions{Resource: resource[0]} |
| 275 | |
| 276 | // Kube Context |
| 277 | kubeContext := h.ctx.KubeClient().CurrentContext() |
| 278 | context, ok := r.URL.Query()["context"] |
| 279 | if ok && len(context) == 1 && context[0] != "" { |
| 280 | kubeContext = context[0] |
| 281 | } |
| 282 | |
| 283 | // Namespace |
| 284 | kubeNamespace := h.ctx.KubeClient().Namespace() |
| 285 | namespace, ok := r.URL.Query()["namespace"] |
| 286 | if ok && len(namespace) == 1 && namespace[0] != "" { |
| 287 | kubeNamespace = namespace[0] |
| 288 | options.Namespace = namespace[0] |
| 289 | } |
| 290 | |
| 291 | // Api version |
| 292 | apiVersion, ok := r.URL.Query()["apiVersion"] |
| 293 | if ok && len(apiVersion) == 1 { |
| 294 | options.APIVersion = apiVersion[0] |
| 295 | } |
| 296 | |
| 297 | // Name |
| 298 | name, ok := r.URL.Query()["name"] |
| 299 | if ok && len(name) == 1 { |
| 300 | options.Name = name[0] |
| 301 | } |
| 302 | |
| 303 | // LabelSelector |
| 304 | labelSelector, ok := r.URL.Query()["labelSelector"] |
| 305 | if ok && len(name) == 1 { |
| 306 | options.LabelSelector = labelSelector[0] |
| 307 | } |
| 308 | |
| 309 | // check client cache |
| 310 | client, err := h.getClientFromCache(kubeContext, kubeNamespace) |
| 311 | if err != nil { |
| 312 | h.ctx.Log().Errorf("Error in %s: %v", r.URL.String(), err) |
| 313 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 314 | return |
| 315 | } |
| 316 | |
| 317 | // Do the request |
| 318 | out, err := client.GenericRequest(r.Context(), options) |
| 319 | if err != nil { |
| 320 | if strings.Index(err.Error(), "request: unknown") != 0 { |
| 321 | h.ctx.Log().Errorf("Error in %s: %v", r.URL.String(), err) |
| 322 | } |
| 323 |
nothing calls this directly
no test coverage detected