Skip to content

Commit

Permalink
Merge pull request #175 from nerdeveloper/feat/upgrade-go-1.18
Browse files Browse the repository at this point in the history
refactor: upgrade go and remove deprecated APIs
  • Loading branch information
nerdeveloper committed Feb 16, 2023
2 parents ec37477 + b884290 commit 97006ee
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 711 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: setup go environment
uses: actions/setup-go@v1
with:
go-version: '1.17'
go-version: '1.18'
- name: run unit tests
run: sudo pip install virtualenv && make test
- name: build binary
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: setup go environment
uses: actions/setup-go@v1
with:
go-version: '1.17'
go-version: '1.18'
- name: run unit tests
run: sudo pip install virtualenv && make test
- name: build binary
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
2 changes: 1 addition & 1 deletion acceptance_tests/lib/Helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_helm_plugin(self):
self.run_command('%s plugin list | grep ^cm-push' % common.HELM_EXE)

def run_helm_plugin(self):
self.run_command('%s cm-push --help' % common.HELM_EXE)
self.run_command('%s cm-push --check-helm-version' % common.HELM_EXE)

def remove_helm_plugin(self):
self.run_command('%s plugin remove cm-push' % common.HELM_EXE)
27 changes: 17 additions & 10 deletions cmd/helm-cm-push/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -102,7 +101,7 @@ func newPushCmd(args []string) *cobra.Command {
}

if len(args) != 2 {
return errors.New("This command needs 2 arguments: name of chart, name of chart repository (or repo URL)")
return errors.New("this command needs 2 arguments: name of chart, name of chart repository (or repo URL)")
}
p.chartName = args[0]
p.repoName = args[1]
Expand All @@ -128,7 +127,10 @@ func newPushCmd(args []string) *cobra.Command {
f.BoolVarP(&p.checkHelmVersion, "check-helm-version", "", false, `outputs either "2" or "3" indicating the current Helm major version`)
f.Int64VarP(&p.timeout, "timeout", "t", 30, "The duration (in seconds) Helm will wait to get response from chartmuseum")

f.Parse(args)
err := f.Parse(args)
if err != nil {
return nil
}

v2settings.AddFlags(f)
v2settings.Init(f)
Expand Down Expand Up @@ -183,7 +185,7 @@ func (p *pushCmd) setAccessTokenFromConfigFile() {
return
}
var c config
yamlFile, err := ioutil.ReadFile(configPath)
yamlFile, err := os.ReadFile(configPath)
if err != nil {
return
}
Expand Down Expand Up @@ -312,7 +314,7 @@ func (p *pushCmd) push() error {
return err
}

// update context path if not overrided
// update context path if not override
if p.contextPath == "" {
index, err := helm.GetIndexByRepo(repo, getIndexDownloader(client))
if err != nil {
Expand All @@ -321,11 +323,16 @@ func (p *pushCmd) push() error {
client.Option(cm.ContextPath(index.ServerInfo.ContextPath))
}

tmp, err := ioutil.TempDir("", "helm-push-")
tmp, err := os.MkdirTemp("", "helm-push-")
if err != nil {
return err
}
defer os.RemoveAll(tmp)
defer func(path string) {
err := os.RemoveAll(path)
if err != nil {
fmt.Printf("Failed to remove temporary directory %s: %s", path, err)
}
}(tmp)

chartPackagePath, err := helm.CreateChartPackage(chart, tmp)
if err != nil {
Expand Down Expand Up @@ -396,7 +403,7 @@ func (p *pushCmd) download(fileURL string) error {

func handlePushResponse(resp *http.Response) error {
if resp.StatusCode != 201 && resp.StatusCode != 202 {
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand All @@ -407,7 +414,7 @@ func handlePushResponse(resp *http.Response) error {
}

func handleDownloadResponse(resp *http.Response) error {
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return err
Expand Down Expand Up @@ -437,7 +444,7 @@ func getIndexDownloader(client *cm.Client) helm.IndexDownloader {
return nil, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/chartmuseum/helm-push

go 1.17
go 1.18

require (
github.com/ghodss/yaml v1.0.0
Expand Down
687 changes: 0 additions & 687 deletions go.sum

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions pkg/chartmuseum/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chartmuseum
import (
"crypto/tls"
"encoding/base64"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -16,8 +16,13 @@ func TestDownloadFile(t *testing.T) {
w.WriteHeader(401)
} else {
w.WriteHeader(200)
w.Write([]byte("hello world"))
_, err := w.Write([]byte("hello world"))
if err != nil {
return
}

}

}))
defer ts.Close()

Expand All @@ -34,7 +39,7 @@ func TestDownloadFile(t *testing.T) {
if err != nil {
t.Fatal("error downloading testfile", err)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal("error reading response body", err)
}
Expand All @@ -60,7 +65,10 @@ func TestDownloadFileFromTlsServer(t *testing.T) {
w.WriteHeader(401)
} else {
w.WriteHeader(200)
w.Write([]byte("hello world"))
_, err := w.Write([]byte("hello world"))
if err != nil {
return
}
}
}))
cert, err := tls.LoadX509KeyPair(testServerCertPath, testServerKeyPath)
Expand Down Expand Up @@ -103,7 +111,7 @@ func TestDownloadFileFromTlsServer(t *testing.T) {
if err != nil {
t.Fatalf("[with ca file] error downloading testfile: %s", err)
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("[with ca file] error reading response body: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/chartmuseum/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -68,6 +67,6 @@ func setUploadChartPackageRequestBody(req *http.Request, chartPackagePath string
return err
}
req.Header.Set("Content-Type", w.FormDataContentType())
req.Body = ioutil.NopCloser(&body)
req.Body = io.NopCloser(&body)
return nil
}
4 changes: 2 additions & 2 deletions pkg/helm/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package helm

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/ghodss/yaml"
Expand All @@ -24,7 +24,7 @@ type (
func GetIndexByRepo(repo *Repo, downloadIndex IndexDownloader) (*Index, error) {
if repo.Config.Name != "" {
return GetIndexByDownloader(func() ([]byte, error) {
return ioutil.ReadFile(filepath.Join(repo.CachePath, fmt.Sprintf("%s-index.yaml", repo.Config.Name)))
return os.ReadFile(filepath.Join(repo.CachePath, fmt.Sprintf("%s-index.yaml", repo.Config.Name)))
})
}
return GetIndexByDownloader(downloadIndex)
Expand Down

0 comments on commit 97006ee

Please sign in to comment.