Fix CLI unable to get pod logs from controller (#1451)
This commit is contained in:
@@ -19,10 +19,15 @@ package client
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
)
|
||||
|
||||
func (c *Client) FunctionCreate(f *fv1.Function) (*metav1.ObjectMeta, error) {
|
||||
@@ -152,3 +157,29 @@ func (c *Client) FunctionList(functionNamespace string) ([]fv1.Function, error)
|
||||
|
||||
return funcs, nil
|
||||
}
|
||||
|
||||
func (c *Client) FunctionPodLogs(m *metav1.ObjectMeta) (io.ReadCloser, int, error) {
|
||||
relativeUrl := fmt.Sprintf("functions/%v", m.Name)
|
||||
relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace)
|
||||
|
||||
queryURL, err := url.Parse(c.Url)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "error parsing the base URL '%v'", c.Url)
|
||||
}
|
||||
queryURL.Path = fmt.Sprintf("/proxy/logs/%s", m.Name)
|
||||
|
||||
console.Verbose(2, fmt.Sprintf("Try to get pod logs from controller '%v'", queryURL.String()))
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, queryURL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "error creating logs request")
|
||||
}
|
||||
|
||||
httpClient := http.Client{}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "error executing get logs request")
|
||||
}
|
||||
|
||||
return resp.Body, resp.StatusCode, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user