Skip to content

Commit

Permalink
logs services up
Browse files Browse the repository at this point in the history
  • Loading branch information
dciangot committed Oct 30, 2023
1 parent f1ba9eb commit eb9371d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
37 changes: 36 additions & 1 deletion pkg/virtualkubelet/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,42 @@ func statusRequest(podsList []*v1.Pod, token string) ([]byte, error) {
return returnValue, nil
}

func LogRetrieval(p *VirtualKubeletProvider, ctx context.Context, logsRequest commonIL.LogStruct) (io.ReadCloser, error) {
b, err := os.ReadFile(commonIL.InterLinkConfigInst.VKTokenFile) // just pass the file name
if err != nil {
log.G(ctx).Fatal(err)
}
token := string(b)

bodyBytes, err := json.Marshal(logsRequest)
if err != nil {
log.L.Error(err)
return nil, err
}
reader := bytes.NewReader(bodyBytes)
req, err := http.NewRequest(http.MethodGet, commonIL.InterLinkConfigInst.Interlinkurl+":"+commonIL.InterLinkConfigInst.Interlinkport+"/getLogs", reader)
if err != nil {
log.L.Error(err)
return nil, err
}

//log.L.Println(string(bodyBytes))

req.Header.Add("Authorization", "Bearer "+token)

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}

if resp.StatusCode != http.StatusOK {
return nil, errors.New("Unexpected error occured while getting logs. Status code: " + strconv.Itoa(resp.StatusCode) + ". Check InterLink's logs for further informations")
} else {
return resp.Body, nil
}

}

func RemoteExecution(p *VirtualKubeletProvider, ctx context.Context, mode int8, imageLocation string, pod *v1.Pod) error {
var req []*v1.Pod
req = []*v1.Pod{pod}
Expand All @@ -150,7 +186,6 @@ func RemoteExecution(p *VirtualKubeletProvider, ctx context.Context, mode int8,
}
log.G(ctx).Info(string(returnVal))
break

case DELETE:
returnVal, err := deleteRequest(req, token)
if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion pkg/virtualkubelet/virtualkubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,18 @@ func addAttributes(ctx context.Context, span trace.Span, attrs ...string) contex
}

func (p *VirtualKubeletProvider) GetLogs(ctx context.Context, namespace, podName, containerName string, opts api.ContainerLogOpts) (io.ReadCloser, error) {
return nil, fmt.Errorf("NOT IMPLEMENTED YET")
var span trace.Span
ctx, span = trace.StartSpan(ctx, "GetLogs") //nolint: ineffassign,staticcheck
defer span.End()

logsRequest := commonIL.LogStruct{
Namespace: namespace,
PodName: podName,
ContainerName: containerName,
Opts: commonIL.ContainerLogOpts(opts),
}

return LogRetrieval(p, ctx, logsRequest)
}

// GetStatsSummary returns dummy stats for all pods known by this provider.
Expand Down

0 comments on commit eb9371d

Please sign in to comment.