MCPcopy Index your code
hub / github.com/devspace-sh/devspace / logs

Method logs

pkg/devspace/server/logs.go:65–129  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

63}
64
65func (h *handler) logs(w http.ResponseWriter, r *http.Request) {
66 // Kube Context
67 kubeContext := h.ctx.KubeClient().CurrentContext()
68 contextParam, ok := r.URL.Query()["context"]
69 if ok && len(contextParam) == 1 && contextParam[0] != "" {
70 kubeContext = contextParam[0]
71 }
72
73 // Namespace
74 kubeNamespace := h.ctx.KubeClient().Namespace()
75 namespace, ok := r.URL.Query()["namespace"]
76 if ok && len(namespace) == 1 && namespace[0] != "" {
77 kubeNamespace = namespace[0]
78 }
79
80 // Create kubectl client
81 client, err := kubectl.NewClientFromContext(kubeContext, kubeNamespace, false, kubeconfig.NewLoader())
82 if err != nil {
83 h.ctx.Log().Errorf("Error in %s: %v", r.URL.String(), err)
84 http.Error(w, err.Error(), http.StatusInternalServerError)
85 return
86 }
87
88 name, ok := r.URL.Query()["name"]
89 if !ok || len(name) != 1 {
90 http.Error(w, "name is missing", http.StatusBadRequest)
91 return
92 }
93 container, ok := r.URL.Query()["container"]
94 if !ok || len(container) != 1 {
95 http.Error(w, "container is missing", http.StatusBadRequest)
96 return
97 }
98
99 ws, err := upgrader.Upgrade(w, r, nil)
100 if err != nil {
101 h.ctx.Log().Errorf("Error upgrading connection in %s: %v", r.URL.String(), err)
102 http.Error(w, err.Error(), http.StatusInternalServerError)
103 return
104 }
105
106 defer ws.Close()
107
108 // Open logs connection
109 reader, err := client.Logs(context.TODO(), namespace[0], name[0], container[0], false, ptr.Int64(100), true)
110 if err != nil {
111 h.ctx.Log().Errorf("Error in %s: %v", r.URL.String(), err)
112 websocketError(ws, err)
113 return
114 }
115
116 defer reader.Close()
117
118 // Stream logs
119 stream := &wsStream{WebSocket: ws}
120 _, err = io.Copy(stream, reader)
121 if err != nil {
122 h.ctx.Log().Errorf("Error in %s pipeReader: %v", r.URL.String(), err)

Callers

nothing calls this directly

Calls 15

NewClientFromContextFunction · 0.92
NewLoaderFunction · 0.92
Int64Function · 0.92
websocketErrorFunction · 0.85
SetWriteDeadlineMethod · 0.80
CurrentContextMethod · 0.65
KubeClientMethod · 0.65
NamespaceMethod · 0.65
LogMethod · 0.65
UpgradeMethod · 0.65
CloseMethod · 0.65
LogsMethod · 0.65

Tested by

no test coverage detected