Skip to content

Commit

Permalink
Merge pull request #95 from hypnoglow/helm3-support-part1
Browse files Browse the repository at this point in the history
Add minimal Helm v3 support
  • Loading branch information
hypnoglow authored Nov 26, 2019
2 parents f6299a6 + 85542d3 commit ed937f0
Show file tree
Hide file tree
Showing 21 changed files with 1,424 additions and 80 deletions.
68 changes: 65 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- run:
name: Install helm, install plugin
command: |
curl -sSL https://storage.googleapis.com/kubernetes-helm/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar xz
curl -sSL https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar xz
mv linux-amd64/helm ${GOPATH}/bin/helm
rm -rf linux-amd64
helm init --client-only
Expand All @@ -111,10 +111,12 @@ jobs:
mc mb helm-s3-minio/test-bucket
- run:
name: Run (legacy) integration tests
command: ./hack/integration-tests.sh
command: |
./hack/integration-tests.sh
- run:
name: Run e2e tests
command: go test -v ./tests/e2e/...
command: |
go test -v ./tests/e2e/...
test-install:
docker:
- image: circleci/buildpack-deps:stretch-curl
Expand Down Expand Up @@ -182,6 +184,28 @@ jobs:
version: 18.06.0-ce
- build_push_docker_image:
helm_version: 2.15.2
docker-helm-2_16:
docker:
- image: circleci/buildpack-deps:stretch
working_directory: ~/workspace/helm-s3
steps:
- attach_workspace:
at: ~/workspace
- setup_remote_docker:
version: 18.06.0-ce
- build_push_docker_image:
helm_version: 2.16.1
docker-helm-3_0:
docker:
- image: circleci/buildpack-deps:stretch
working_directory: ~/workspace/helm-s3
steps:
- attach_workspace:
at: ~/workspace
- setup_remote_docker:
version: 18.06.0-ce
- build_push_docker_image:
helm_version: 3.0.0

workflows:
version: 2
Expand Down Expand Up @@ -219,6 +243,24 @@ workflows:
filters:
branches:
only: master
- docker-helm-2_16:
requires:
- dep
- test-unit
- test-integration-and-e2e
- test-install
filters:
branches:
only: master
- docker-helm-3_0:
requires:
- dep
- test-unit
- test-integration-and-e2e
- test-install
filters:
branches:
only: master
# release-pipeline runs only on tags.
release-pipeline:
jobs:
Expand Down Expand Up @@ -254,12 +296,32 @@ workflows:
only: /.*/
branches:
ignore: /.*/
- docker-helm-2_16:
requires:
- dep
- test-install
filters:
tags:
only: /.*/
branches:
ignore: /.*/
- docker-helm-3_0:
requires:
- dep
- test-install
filters:
tags:
only: /.*/
branches:
ignore: /.*/
- release:
requires:
- dep
- test-install
- docker-helm-2_14
- docker-helm-2_15
- docker-helm-2_16
- docker-helm-3_0
filters:
tags:
only: /.*/
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ linters:
enable-all: true
disable:
- lll
- funlen
- gochecknoglobals
- wsl

issues:
new-from-rev: master
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The Helm plugin that provides s3 protocol support.
This allows you to have private Helm chart repositories hosted on Amazon S3. Refer to [this article](https://andrewlock.net/how-to-create-a-helm-chart-repository-using-amazon-s3/)
written by [@andrewlock](https://github.com/andrewlock) to get a detailed use case overview.

⚠️ Due to breaking changes, Helm v3 is not supported yet in this plugin (WIP). We plan to add support for Helm v3 to the next plugin release.
Also, this plugin will continue supporting Helm v2 until its sunset.

## Install

The installation itself is simple as:
Expand Down
6 changes: 3 additions & 3 deletions cmd/helms3/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (act deleteAction) Run(ctx context.Context) error {
storage := awss3.New(sess)

// Fetch current index.
b, err := storage.FetchRaw(ctx, repoEntry.URL+"/index.yaml")
b, err := storage.FetchRaw(ctx, repoEntry.IndexURL())
if err != nil {
return errors.WithMessage(err, "fetch current repo index")
}
Expand Down Expand Up @@ -61,11 +61,11 @@ func (act deleteAction) Run(ctx context.Context) error {
if err := storage.Delete(ctx, uri); err != nil {
return errors.WithMessage(err, "delete chart file from s3")
}
if err := storage.PutIndex(ctx, repoEntry.URL, act.acl, idxReader); err != nil {
if err := storage.PutIndex(ctx, repoEntry.URL(), act.acl, idxReader); err != nil {
return errors.WithMessage(err, "upload new index to s3")
}

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

Expand Down
3 changes: 3 additions & 0 deletions cmd/helms3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"time"

"github.com/hypnoglow/helm-s3/internal/helmutil"
"gopkg.in/alecthomas/kingpin.v2"
)

Expand Down Expand Up @@ -48,6 +49,8 @@ type Action interface {
}

func main() {
helmutil.SetupHelm()

log.SetFlags(0)

if len(os.Args) == 5 && !isAction(os.Args[1]) {
Expand Down
14 changes: 7 additions & 7 deletions cmd/helms3/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (act pushAction) Run(ctx context.Context) error {
return err
}

if cachedIndex, err := repo.LoadIndexFile(repoEntry.Cache); err == nil {
if cachedIndex, err := repo.LoadIndexFile(repoEntry.CacheFile()); err == nil {
// if cached index exists, check if the same chart version exists in it.
if cachedIndex.Has(chart.Metadata.Name, chart.Metadata.Version) {
if act.ignoreIfExists {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (act pushAction) Run(ctx context.Context) error {
return errors.Wrap(err, "encode chart metadata to json")
}

exists, err := storage.Exists(ctx, repoEntry.URL+"/"+fname)
exists, err := storage.Exists(ctx, repoEntry.URL()+"/"+fname)
if err != nil {
return errors.WithMessage(err, "check if chart already exists in the repository")
}
Expand All @@ -126,7 +126,7 @@ func (act pushAction) Run(ctx context.Context) error {
}

if !act.dryRun {
if _, err := storage.PutChart(ctx, repoEntry.URL+"/"+fname, fchart, string(serializedChartMeta), act.acl, hash, act.contentType); err != nil {
if _, err := storage.PutChart(ctx, repoEntry.URL()+"/"+fname, fchart, string(serializedChartMeta), act.acl, hash, act.contentType); err != nil {
return errors.WithMessage(err, "upload chart to s3")
}
}
Expand All @@ -137,7 +137,7 @@ func (act pushAction) Run(ctx context.Context) error {

// Fetch current index, update it and upload it back.

b, err := storage.FetchRaw(ctx, repoEntry.URL+"/index.yaml")
b, err := storage.FetchRaw(ctx, repoEntry.IndexURL())
if err != nil {
return errors.WithMessage(err, "fetch current repo index")
}
Expand All @@ -147,7 +147,7 @@ func (act pushAction) Run(ctx context.Context) error {
return errors.WithMessage(err, "load index from downloaded file")
}

if err := idx.AddOrReplace(chart.GetMetadata(), fname, repoEntry.URL, hash); err != nil {
if err := idx.AddOrReplace(chart.GetMetadata(), fname, repoEntry.URL(), hash); err != nil {
return errors.WithMessage(err, "add/replace chart in the index")
}
idx.SortEntries()
Expand All @@ -158,11 +158,11 @@ func (act pushAction) Run(ctx context.Context) error {
}

if !act.dryRun {
if err := storage.PutIndex(ctx, repoEntry.URL, act.acl, idxReader); err != nil {
if err := storage.PutIndex(ctx, repoEntry.URL(), act.acl, idxReader); err != nil {
return errors.WithMessage(err, "upload index to s3")
}

if err := idx.WriteFile(repoEntry.Cache, 0644); err != nil {
if err := idx.WriteFile(repoEntry.CacheFile(), 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 @@ -28,13 +28,13 @@ func (act reindexAction) Run(ctx context.Context) error {
}
storage := awss3.New(sess)

items, errs := storage.Traverse(ctx, repoEntry.URL)
items, errs := storage.Traverse(ctx, repoEntry.URL())

builtIndex := make(chan *index.Index, 1)
go func() {
idx := index.New()
for item := range items {
idx.Add(item.Meta, item.Filename, repoEntry.URL, item.Hash)
idx.Add(item.Meta, item.Filename, repoEntry.URL(), item.Hash)
}
idx.SortEntries()

Expand All @@ -52,11 +52,11 @@ func (act reindexAction) Run(ctx context.Context) error {
return errors.Wrap(err, "get index reader")
}

if err := storage.PutIndex(ctx, repoEntry.URL, act.acl, r); err != nil {
if err := storage.PutIndex(ctx, repoEntry.URL(), act.acl, r); err != nil {
return errors.Wrap(err, "upload index to the repository")
}

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

Expand Down
19 changes: 6 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@ module github.com/hypnoglow/helm-s3

go 1.12

// See: https://github.com/helm/helm/issues/6994
replace github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309

require (
github.com/BurntSushi/toml v0.3.0 // indirect
github.com/Masterminds/semver v1.5.0
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/aws/aws-sdk-go v1.19.49
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/ghodss/yaml v1.0.0
github.com/gobwas/glob v0.2.2 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/minio/minio-go/v6 v6.0.40
github.com/pkg/errors v0.8.1
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
github.com/spf13/pflag v1.0.0 // indirect
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/ini.v1 v1.49.0 // indirect
k8s.io/apimachinery v0.0.0-20180112112505-c33db96a31b6 // indirect
k8s.io/client-go v6.0.0+incompatible // indirect
k8s.io/helm v2.14.3+incompatible
helm.sh/helm/v3 v3.0.0
k8s.io/helm v2.16.1+incompatible
)
Loading

0 comments on commit ed937f0

Please sign in to comment.