Skip to content

Commit

Permalink
Merge pull request #33 from hypnoglow/refactor-internal
Browse files Browse the repository at this point in the history
Refactor internal
  • Loading branch information
hypnoglow authored Feb 12, 2018
2 parents 533f955 + fd75fb8 commit c79773d
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
mc mb helm-s3-minio/test-bucket
- run:
name: Run tests
command: ./sh/integration-tests.sh
command: ./hack/integration-tests.sh
release:
docker:
- image: circleci/golang:1.9
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ dep:

.PHONY: build
build:
@./sh/build.sh $(CURDIR) $(PKG)
@./hack/build.sh $(CURDIR) $(PKG)

.PHONY: install
install:
@./sh/install.sh
@./hack/install.sh

.PHONY: test
test:
go test ./...

.PHONY: test-integration
test-integration:
@./sh/integration-tests-local.sh
@./hack/integration-tests-local.sh
8 changes: 4 additions & 4 deletions cmd/helms3/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/internal/awss3"
"github.com/hypnoglow/helm-s3/internal/awsutil"
"github.com/hypnoglow/helm-s3/internal/helmutil"
"github.com/hypnoglow/helm-s3/internal/index"
"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/pkg/helmutil"
)

type deleteAction struct {
Expand Down Expand Up @@ -65,7 +65,7 @@ func (act deleteAction) Run(ctx context.Context) error {
return errors.WithMessage(err, "upload new index to s3")
}

if err := helmutil.UpdateLocalIndex(act.repoName, idx); err != nil {
if err := idx.WriteFile(repoEntry.Cache, 0644); err != nil {
return errors.WithMessage(err, "update local index")
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/helms3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/internal/awss3"
"github.com/hypnoglow/helm-s3/internal/awsutil"
"github.com/hypnoglow/helm-s3/internal/index"
"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
)

type initAction struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/helms3/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/internal/awss3"
"github.com/hypnoglow/helm-s3/internal/awsutil"
)

type proxyCmd struct {
Expand Down
8 changes: 4 additions & 4 deletions cmd/helms3/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/provenance"

"github.com/hypnoglow/helm-s3/internal/awss3"
"github.com/hypnoglow/helm-s3/internal/awsutil"
"github.com/hypnoglow/helm-s3/internal/helmutil"
"github.com/hypnoglow/helm-s3/internal/index"
"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/pkg/helmutil"
)

type pushAction struct {
Expand Down Expand Up @@ -101,7 +101,7 @@ func (act pushAction) Run(ctx context.Context) error {
return errors.WithMessage(err, "upload index to s3")
}

if err := helmutil.UpdateLocalIndex(act.repoName, idx); err != nil {
if err := idx.WriteFile(repoEntry.Cache, 0644); err != nil {
return errors.WithMessage(err, "update local index")
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/helms3/reindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/internal/awss3"
"github.com/hypnoglow/helm-s3/internal/awsutil"
"github.com/hypnoglow/helm-s3/internal/helmutil"
"github.com/hypnoglow/helm-s3/internal/index"
"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/pkg/helmutil"
)

type reindexAction struct {
Expand Down Expand Up @@ -55,7 +55,7 @@ func (act reindexAction) Run(ctx context.Context) error {
return errors.Wrap(err, "upload index to the repository")
}

if err := helmutil.UpdateLocalIndex(act.repoName, idx); err != nil {
if err := idx.WriteFile(repoEntry.Cache, 0644); err != nil {
return errors.WithMessage(err, "update local index")
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 8 additions & 21 deletions pkg/helmutil/repo_entry.go → internal/helmutil/repo_entry.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
package helmutil

import (
"io/ioutil"
"os"

"github.com/pkg/errors"
"k8s.io/helm/pkg/helm/environment"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/repo"

"github.com/hypnoglow/helm-s3/internal/index"
)

const (
envHelmHome = "HELM_HOME"
)

// LookupRepoEntry returns an entry from helm's repositories.yaml file by name.
func LookupRepoEntry(name string) (*repo.Entry, error) {
func getHome() helmpath.Home {
h := helmpath.Home(environment.DefaultHelmHome)
if os.Getenv(envHelmHome) != "" {
h = helmpath.Home(os.Getenv(envHelmHome))
}

return h
}

// LookupRepoEntry returns an entry from helm's repositories.yaml file by name.
func LookupRepoEntry(name string) (*repo.Entry, error) {
h := getHome()

repoFile, err := repo.LoadRepositoriesFile(h.RepositoryFile())
if err != nil {
return nil, errors.Wrap(err, "load repo file")
Expand All @@ -36,19 +39,3 @@ func LookupRepoEntry(name string) (*repo.Entry, error) {

return nil, errors.Errorf("repo with name %s not found, try `helm repo add %s <uri>`", name, name)
}

// UpdateLocalIndex rewrites index file for repository named repoName with idx
// contents.
func UpdateLocalIndex(repoName string, idx *index.Index) error {
entry, err := LookupRepoEntry(repoName)
if err != nil {
return err
}

b, err := idx.MarshalBinary()
if err != nil {
return err
}

return ioutil.WriteFile(entry.Cache, b, 0644)
}

0 comments on commit c79773d

Please sign in to comment.