-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
Signed-off-by: Subbarao Meduri <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,14 +61,16 @@ func SetRequest(method string, url string, body io.Reader, retry int) ([]byte, i | |
resp, err = getHTTPClient().Do(req) | ||
} | ||
|
||
if resp != nil { | ||
defer resp.Body.Close() | ||
respBody, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
klog.Info("failed to parse response body ", "error ", err) | ||
} | ||
return respBody, resp.StatusCode | ||
} else { | ||
if resp == nil { | ||
return nil, http.StatusNotFound | ||
} | ||
|
||
respBody, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
klog.Info("failed to parse response body ", "error ", err) | ||
resp.Body.Close() | ||
Check warning Code scanning / SonarCloud Errors unhandled. See more on SonarCloud Warning
Errors unhandled. See more on SonarCloud
|
||
return nil, resp.StatusCode | ||
} | ||
resp.Body.Close() | ||
Check warning Code scanning / SonarCloud Errors unhandled. See more on SonarCloud Warning
Errors unhandled. See more on SonarCloud
|
||
return respBody, resp.StatusCode | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,14 +427,18 @@ func FetchUserProjectList(token string, url string) []string { | |
writeError(fmt.Sprintf("failed to send http request: %v", err)) | ||
return []string{} | ||
} | ||
defer resp.Body.Close() | ||
|
||
var projects projectv1.ProjectList | ||
err = json.NewDecoder(resp.Body).Decode(&projects) | ||
if err != nil { | ||
klog.Errorf("failed to decode response json body: %v", err) | ||
resp.Body.Close() | ||
Check warning Code scanning / SonarCloud Errors unhandled. See more on SonarCloud Warning
Errors unhandled. See more on SonarCloud
|
||
return []string{} | ||
} | ||
err = resp.Body.Close() | ||
if err != nil { | ||
klog.Errorf("failed to close response body: %v", err) | ||
} | ||
|
||
projectList := make([]string, len(projects.Items)) | ||
for idx, p := range projects.Items { | ||
|
@@ -451,14 +455,18 @@ func GetUserName(token string, url string) string { | |
writeError(fmt.Sprintf("failed to send http request: %v", err)) | ||
return "" | ||
} | ||
defer resp.Body.Close() | ||
|
||
user := userv1.User{} | ||
err = json.NewDecoder(resp.Body).Decode(&user) | ||
if err != nil { | ||
klog.Errorf("failed to decode response json body: %v", err) | ||
resp.Body.Close() | ||
Check warning Code scanning / SonarCloud Errors unhandled. See more on SonarCloud Warning
Errors unhandled. See more on SonarCloud
|
||
return "" | ||
} | ||
err = resp.Body.Close() | ||
if err != nil { | ||
klog.Errorf("failed to close response body: %v", err) | ||
} | ||
|
||
return user.Name | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,12 +65,16 @@ func GetPodLogs( | |
klog.Errorf("Failed to get logs for %s/%s in namespace %s due to %v", podName, containerName, namespace, err) | ||
return "", err | ||
} | ||
defer podLogs.Close() | ||
buf := new(bytes.Buffer) | ||
_, err = io.Copy(buf, podLogs) | ||
if err != nil { | ||
klog.Errorf("Failed to copy pod logs to buffer due to %v", err) | ||
podLogs.Close() | ||
Check warning Code scanning / SonarCloud Errors unhandled. See more on SonarCloud Warning test
Errors unhandled. See more on SonarCloud
|
||
return "", err | ||
} | ||
err = podLogs.Close() | ||
if err != nil { | ||
klog.Errorf("Failed to close pod logs due to %v", err) | ||
} | ||
return buf.String(), nil | ||
} |