Skip to content

Commit

Permalink
Fix argo message and close body for node
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Apr 29, 2024
1 parent 083e628 commit 64200e7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/apps/argocd_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func MakeInstallArgoCD() *cobra.Command {
}

const ArgoCDInfoMsg = `
# Get the ArgoCD CLI
arkade install argocd
# Install the "argocd" CLI:
arkade get argocd
# Port-forward the ArgoCD API server
kubectl port-forward svc/argocd-server -n argocd 8443:443 &
Expand Down
11 changes: 8 additions & 3 deletions cmd/system/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ func MakeInstallContainerd() *cobra.Command {
return err
}

content, err := io.ReadAll(response.Body)
defer response.Body.Close()

body, err := io.ReadAll(response.Body)
if err != nil {
return err
}
if response.StatusCode != http.StatusOK {
return fmt.Errorf("error fetching systemd unit file, status code: %d, body: %s", response.StatusCode, string(body))
}

content = bytes.ReplaceAll(content, []byte("/usr/local/bin/containerd"), []byte(installPath+"/containerd"))
body = bytes.ReplaceAll(body, []byte("/usr/local/bin/containerd"), []byte(installPath+"/containerd"))

if err := createSystemdUnit(systemdUnitName, content); err != nil {
if err := createSystemdUnit(systemdUnitName, body); err != nil {
return err
}
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/system/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ func getGoVersion() (string, error) {
return "", err
}

if res.StatusCode != http.StatusOK {
return "", fmt.Errorf("unexpected status code: %d", res.StatusCode)
}
if res.Body == nil {
return "", fmt.Errorf("unexpected empty body")
}

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

if res.StatusCode != http.StatusOK {
return "", fmt.Errorf("unexpected status code: %d", res.StatusCode)
}

content := strings.TrimSpace(string(body))
version, _, ok := strings.Cut(content, "\n")
if !ok {
Expand Down
9 changes: 9 additions & 0 deletions cmd/system/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ func getLatestNodeVersion(version, channel string) (*string, error) {
return nil, err
}

if res.Body != nil {
defer res.Body.Close()
}

body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("could not find latest version for %s, (%d), body: %s", version, res.StatusCode, string(body))
}

regex := regexp.MustCompile(`(?m)node-v(\d+.\d+.\d+)-linux-.*`)
result := regex.FindStringSubmatch(string(body))

Expand Down

0 comments on commit 64200e7

Please sign in to comment.