/
ingress.go
50 lines (38 loc) · 1.56 KB
/
ingress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Autovia GmbH
// SPDX-License-Identifier: Apache-2.0
package k8s
import (
"context"
"log"
"net/http"
S "github.com/autovia/flightdeck/api/structs"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func IngressHandler(app *S.App, c *S.Client, w http.ResponseWriter, r *http.Request) error {
url := S.GetRequestParams(r, "/api/v1/ing/")
log.Printf("IngressHandler url: %v", url)
role, err := c.Clientset.NetworkingV1().Ingresses(url.Scope).Get(context.TODO(), url.Resource, metav1.GetOptions{})
if err != nil {
return S.RespondError(err)
}
role.ObjectMeta.ManagedFields = nil
return S.RespondFormat(r, w, http.StatusOK, role)
}
func NamespaceIngressListHandler(app *S.App, c *S.Client, w http.ResponseWriter, r *http.Request) error {
url := S.GetRequestParams(r, "/api/v1/namespace/ing/")
log.Printf("NamespaceIngressListHandler url: %v", url)
g := S.Graph{Nodes: []S.Node{}, Edges: []S.Edge{}}
ns, err := c.Clientset.CoreV1().Namespaces().Get(context.TODO(), url.Scope, metav1.GetOptions{})
if err != nil {
return S.RespondError(err)
}
node := g.AddNode("ns", string(ns.ObjectMeta.UID), ns.ObjectMeta.Name, S.NodeOptions{Type: "namespace", Group: true})
ingList, err := c.Clientset.NetworkingV1().Ingresses(url.Scope).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return S.RespondError(err)
}
for _, ing := range ingList.Items {
g.AddNode("ing", string(ing.ObjectMeta.UID), ing.ObjectMeta.Name, S.NodeOptions{Namespace: url.Scope, Type: "ing", ParentNode: node, Extent: "parent"})
}
return S.RespondJSON(w, http.StatusOK, g)
}