Skip to content

Commit

Permalink
feat(create, pusblish): add support for customer Helm charts (#105)
Browse files Browse the repository at this point in the history
* feat: helm support and release image pinning

* fix: updated go.sum
  • Loading branch information
jpower432 authored Oct 7, 2021
1 parent 11d38e4 commit 8d23bee
Show file tree
Hide file tree
Showing 23 changed files with 822 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Replace this value with a real registry host, or create a `docker.io/library/reg
1. Create then publish to your mirror registry:
```sh
./bin/oc-bundle create full --config imageset-config.yaml --dir test-create --output archives --log-level debug
./bin/oc-bundle publish --archive archives --dir test-publish --to-mirror reg.mirror.com
./bin/oc-bundle publish --archive archives --dir test-publish --to-mirror reg.mirror.com --output results
```

For configuration and options, see the [expanded overview](./docs/overview.md) and [usage](./docs/usage.md) docs.
Expand Down
10 changes: 10 additions & 0 deletions data/imageset-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ mirror:
- name: nginx
additionalimages:
- name: registry.redhat.io/ubi8/ubi:latest
helm:
local:
- name: podinfo
path: /test/podinfo-5.0.0.tar.gz
repos:
- name: podinfo
url: https://stefanprodan.github.io/podinfo
charts:
- name: podinfo
version: 5.0.0
blockedimages:
- name: alpine
- name: redis
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/blang/semver/v4 v4.0.0
github.com/bshuster-repo/logrus-logstash-hook v1.0.2 // indirect
github.com/containerd/containerd v1.5.2
github.com/containerd/containerd v1.5.4
github.com/containers/image/v5 v5.15.2
github.com/docker/distribution v2.7.1+incompatible
github.com/go-git/go-git/v5 v5.4.2
Expand All @@ -28,13 +28,14 @@ require (
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.7.0
k8s.io/apimachinery v0.22.1
k8s.io/cli-runtime v0.22.0
k8s.io/cli-runtime v0.22.1
k8s.io/client-go v0.22.1
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.9.0
k8s.io/kubectl v0.22.0
rsc.io/letsencrypt v0.0.3 // indirect
k8s.io/kubectl v0.22.1
sigs.k8s.io/kustomize/kyaml v0.11.0
sigs.k8s.io/yaml v1.2.0
)

Expand Down
112 changes: 109 additions & 3 deletions go.sum

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"runtime"
"strings"

"github.com/RedHatGov/bundle/pkg/config"
"github.com/RedHatGov/bundle/pkg/config/v1alpha1"
"github.com/mholt/archiver/v3"
"github.com/sirupsen/logrus"

"github.com/RedHatGov/bundle/pkg/config"
"github.com/RedHatGov/bundle/pkg/config/v1alpha1"
)

type Archiver interface {
Expand Down Expand Up @@ -227,7 +228,7 @@ func blobInArchive(file string) string {

func includeFile(fpath string) bool {
split := strings.Split(filepath.Clean(fpath), string(filepath.Separator))
return split[0] == config.InternalDir || split[0] == config.PublishDir || split[0] == "catalogs"
return split[0] == config.InternalDir || split[0] == config.PublishDir || split[0] == "catalogs" || split[0] == config.HelmDir
}

func shouldRemove(fpath string, info fs.FileInfo) bool {
Expand Down
5 changes: 2 additions & 3 deletions pkg/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"testing"

"github.com/RedHatGov/bundle/pkg/bundle"
"github.com/RedHatGov/bundle/pkg/config"
"github.com/RedHatGov/bundle/pkg/config/v1alpha1"
)
Expand Down Expand Up @@ -57,8 +56,8 @@ func Test_SplitArchive(t *testing.T) {

packager := NewPackager(tt.manifests, tt.blobs)

if err := bundle.MakeCreateDirs(testdir); err != nil {
t.Fatal(err)
if err := os.MkdirAll(filepath.Join(testdir, config.SourceDir), os.ModePerm); err != nil {
t.Fail()
}

cwd, err := os.Getwd()
Expand Down
17 changes: 11 additions & 6 deletions pkg/bundle/additional.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bundle

import (
"context"
"fmt"
"path/filepath"

Expand All @@ -23,7 +24,7 @@ func NewAdditionalOptions(ro cli.RootOptions) *AdditionalOptions {
}

// GetAdditional downloads specified images in the imageset-config.yaml under mirror.additonalImages
func (o *AdditionalOptions) GetAdditional(_ v1alpha1.PastMirror, cfg v1alpha1.ImageSetConfiguration) (image.AssociationSet, error) {
func (o *AdditionalOptions) GetAdditional(cfg v1alpha1.ImageSetConfiguration, imageList []v1alpha1.AdditionalImages) (image.AssociationSet, error) {

opts := mirror.NewMirrorImageOptions(o.IOStreams)
opts.DryRun = o.DryRun
Expand All @@ -32,12 +33,12 @@ func (o *AdditionalOptions) GetAdditional(_ v1alpha1.PastMirror, cfg v1alpha1.Im
opts.FileDir = filepath.Join(o.Dir, config.SourceDir)
opts.FilterOptions = o.FilterOptions

logrus.Infof("Downloading %d image(s) to %s", len(cfg.Mirror.AdditionalImages), opts.FileDir)
logrus.Infof("Downloading %d image(s) to %s", len(imageList), opts.FileDir)

var mappings []mirror.Mapping
images := make([]string, len(cfg.Mirror.AdditionalImages))
assocMappings := make(map[string]string, len(cfg.Mirror.AdditionalImages))
for i, img := range cfg.Mirror.AdditionalImages {
images := make([]string, len(imageList))
assocMappings := make(map[string]string, len(imageList))
for i, img := range imageList {

// If the pullSecret is not empty create a cached context
// else let `oc mirror` use the default docker config location
Expand Down Expand Up @@ -74,7 +75,11 @@ func (o *AdditionalOptions) GetAdditional(_ v1alpha1.PastMirror, cfg v1alpha1.Im

// Add mapping and image for image association.
// The registry component is not included in the final path.
srcImage := srcRef.Ref.String()
srcImage, err := pinImages(context.TODO(), srcRef.Ref.Exact(), "", o.SkipTLS)
if err != nil {
return nil, err
}

dstRef.Ref.Registry = ""
assocMappings[srcImage] = dstRef.String()
images[i] = srcImage
Expand Down
9 changes: 6 additions & 3 deletions pkg/bundle/additional_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bundle

import (
"context"
"os"
"testing"

Expand All @@ -16,7 +17,6 @@ import (

func Test_GetAdditional(t *testing.T) {

mirror := v1alpha1.PastMirror{}
cfg := v1alpha1.ImageSetConfiguration{}
cfg.Mirror = v1alpha1.Mirror{
BlockedImages: []v1alpha1.BlockedImages{
Expand All @@ -39,9 +39,12 @@ func Test_GetAdditional(t *testing.T) {
}
opts := NewAdditionalOptions(ro)

assocs, err := opts.GetAdditional(mirror, cfg)
assocs, err := opts.GetAdditional(cfg, cfg.Mirror.AdditionalImages)
require.NoError(t, err)

testerImg, err := pinImages(context.TODO(), "quay.io/estroz/pull-tester-additional:latest", "", false)
require.NoError(t, err)
if assert.Len(t, assocs, 1) {
require.Contains(t, assocs, "quay.io/estroz/pull-tester-additional:latest")
require.Contains(t, assocs, testerImg)
}
}
22 changes: 20 additions & 2 deletions pkg/bundle/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ func (o *Options) RunFull(ctx context.Context, flags *pflag.FlagSet) error {

if len(cfg.Mirror.AdditionalImages) != 0 {
opts := bundle.NewAdditionalOptions(*o.RootOptions)
assocs, err := opts.GetAdditional(run, cfg)
assocs, err := opts.GetAdditional(cfg, cfg.Mirror.AdditionalImages)
if err != nil {
return meta, run, err
}
allAssocs.Merge(assocs)
}

if len(cfg.Mirror.Helm.Local) != 0 || len(cfg.Mirror.Helm.Repos) != 0 {
opts := bundle.NewHelmOptions(*o.RootOptions)
assocs, err := opts.PullCharts(cfg)
if err != nil {
return meta, run, err
}
Expand Down Expand Up @@ -142,7 +151,16 @@ func (o *Options) RunDiff(ctx context.Context, flags *pflag.FlagSet) error {

if len(cfg.Mirror.AdditionalImages) != 0 {
opts := bundle.NewAdditionalOptions(*o.RootOptions)
assocs, err := opts.GetAdditional(lastRun, cfg)
assocs, err := opts.GetAdditional(cfg, cfg.Mirror.AdditionalImages)
if err != nil {
return meta, run, err
}
allAssocs.Merge(assocs)
}

if len(cfg.Mirror.Helm.Local) != 0 || len(cfg.Mirror.Helm.Repos) != 0 {
opts := bundle.NewHelmOptions(*o.RootOptions)
assocs, err := opts.PullCharts(cfg)
if err != nil {
return meta, run, err
}
Expand Down
Loading

0 comments on commit 8d23bee

Please sign in to comment.