MCPcopy Index your code
hub / github.com/1Panel-dev/KubePi / KubernetesAPIProxy

Method KubernetesAPIProxy

internal/api/v1/proxy/proxy.go:48–198  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48func (h *Handler) KubernetesAPIProxy() iris.Handler {
49 return func(ctx *context.Context) {
50 // 解析参数
51 name := ctx.Params().GetString("name")
52 proxyPath := ensureProxyPathValid(ctx.Params().GetString("p"))
53 namespace := ctx.URLParam("namespace")
54 keywords := ctx.URLParam("keywords")
55 search := false
56 if ctx.URLParamExists("search") {
57 search, _ = ctx.URLParamBool("search")
58 }
59
60 requestMethod := ctx.Request().Method
61 // 获取当亲集群
62 c, err := h.clusterService.Get(name, common.DBOptions{})
63 if err != nil {
64 ctx.StatusCode(iris.StatusInternalServerError)
65 ctx.Values().Set("message", fmt.Sprintf("get cluster failed: %s", err.Error()))
66 return
67 }
68 // 获取session
69 u := ctx.Values().Get("profile")
70 profile := u.(session.UserProfile)
71 // 生成transport
72 ts, err := h.generateTLSTransport(c, profile)
73 if err != nil {
74 ctx.StatusCode(iris.StatusInternalServerError)
75 ctx.Values().Set("message", err)
76 return
77 }
78 // 生成httpClient
79 httpClient := http.Client{Transport: ts}
80 k := kubernetes.NewKubernetes(c)
81 clusterVersionMinor, err := k.VersionMinor()
82 if err != nil {
83 ctx.StatusCode(iris.StatusInternalServerError)
84 ctx.Values().Set("message", err)
85 return
86 }
87 compatibleClusterVersion(clusterVersionMinor, &proxyPath)
88
89 //判断是否已经包含了namespace的查询
90 hasNsFilter := hasNamespaceFilter(proxyPath)
91 resourceName, err := parseResourceName(proxyPath)
92 if err != nil {
93 ctx.StatusCode(iris.StatusInternalServerError)
94 ctx.Values().Set("message", err)
95 return
96 }
97 // 判断资源类型是否是namespace级别的
98 namespaced, err := k.IsNamespacedResource(resourceName)
99 if err != nil {
100 ctx.StatusCode(iris.StatusInternalServerError)
101 ctx.Values().Set("message", err)
102 return
103 }
104 if strings.Contains(proxyPath, "namespaces") {
105 namespaced = false

Callers 1

InstallFunction · 0.95

Calls 15

generateTLSTransportMethod · 0.95
VersionMinorMethod · 0.95
IsNamespacedResourceMethod · 0.95
CanVisitAllNamespaceMethod · 0.95
GetUserNamespaceNamesMethod · 0.95
NewKubernetesFunction · 0.92
ensureProxyPathValidFunction · 0.85
compatibleClusterVersionFunction · 0.85
hasNamespaceFilterFunction · 0.85
parseResourceNameFunction · 0.85
pagerAndSearchFunction · 0.85

Tested by

no test coverage detected