Skip to content

Commit

Permalink
Adding skipImages option
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
  • Loading branch information
gregsidelinger committed Aug 29, 2024
1 parent 19e6eb4 commit 19fd002
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 57 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Sync chart packages and associated container images between chart repositories
+ [Sync all charts from specific date](#sync-all-charts-from-specific-date)
- [Advanced Usage](#advanced-usage)
+ [Skip syncing artifacts](#skip-syncing-artifacts)
+ [Skip syncing images](#skip-syncing-images)
+ [Sync only specific container platforms](#sync-only-specific-container-platforms)
+ [Sync Helm Charts and Container Images to different registries](#sync-helm-charts-and-container-images-to-different-registries)
+ [Sync charts between repositories without direct connectivity](#sync-charts-between-repositories-without-direct-connectivity)
Expand Down Expand Up @@ -116,6 +117,24 @@ containerPlatforms:
- linux/amd64
```

### Skip syncing images

By default images referenced in charts will be synced and their refences in the chart will be updated to the target repo. If you want to disable this behavior, you can opt out by setting `skipImages` to true:

```yaml
source:
repo:
kind: OCI
url: http://localhost:8080
target:
repo:
kind: OCI
url: http://localhost:9090/charts
charts:
- redis
skipImages: true
```

### Sync Helm Charts and Container Images to different registries

Expand Down
115 changes: 63 additions & 52 deletions api/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ message Config {
repeated string skip_charts = 5;
// Do not sync chart and container artifacts (signatures and metadata)
bool skip_artifacts = 6;

// Do not sync chart images
bool skip_images = 7;
}

// SourceRepo contains the required information of the source chart repository
Expand Down
2 changes: 2 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ func newSyncCmd() *cobra.Command {
syncer.WithInsecure(rootInsecure),
syncer.WithLatestVersionOnly(syncLatestVersionOnly),
syncer.WithSkipArtifacts(c.GetSkipArtifacts()),
syncer.WithSkipImages(c.GetSkipImages()),
syncer.WithSkipCharts(c.SkipCharts),
syncer.WithUsePlainHTTP(usePlainHTTP),

syncer.WithLogger(l),
}
s, err := syncer.New(c.GetSource(), c.GetTarget(), syncerOptions...)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (

require (
github.com/stretchr/testify v1.8.4
github.com/vmware-labs/distribution-tooling-for-helm v0.4.1
github.com/vmware-labs/distribution-tooling-for-helm v0.4.2
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ github.com/transparency-dev/merkle v0.0.2 h1:Q9nBoQcZcgPamMkGn7ghV8XiTZ/kRxn1yCG
github.com/transparency-dev/merkle v0.0.2/go.mod h1:pqSy+OXefQ1EDUVmAJ8MUhHB9TXGuzVAT58PqBoHz1A=
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
github.com/vmware-labs/distribution-tooling-for-helm v0.4.1 h1:FyjGJKQcq42YJxOV8O/GYlZUSDSBZoXF/c9KL55IDRc=
github.com/vmware-labs/distribution-tooling-for-helm v0.4.1/go.mod h1:g0GJbeBmn5XouR6SBBIDiHdDNxJqViu+ayXUfOC8k+I=
github.com/vmware-labs/distribution-tooling-for-helm v0.4.2 h1:sdTGUuge9HFMPf+mkGmLbT6tzt3wIr+/4lxsBAThfuo=
github.com/vmware-labs/distribution-tooling-for-helm v0.4.2/go.mod h1:foYuz1d7XJIbZOnXob0jx5ir+VwyXnyxzKIalKOUYPA=
github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk=
github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ=
github.com/vmware-tanzu/carvel-imgpkg v0.38.3 h1:vVnqCPFEZ2NQcoTywg/va91qRyCuu46wBYAETqoyez4=
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Config struct {
WorkDir string
ContainerPlatforms []string
SkipArtifacts bool
SkipImages bool
}

// Option is a function that modifies the Config
Expand All @@ -31,6 +32,13 @@ func WithSkipArtifacts(skipArtifacts bool) func(*Config) {
}
}

// WithSkipImages sets the skip image flag
func WithSkipImages(skipImages bool) func(*Config) {
return func(c *Config) {
c.SkipImages = skipImages
}
}

// WithContainerPlatforms sets the container platforms to sync
func WithContainerPlatforms(containerPlatforms []string) func(*Config) {
return func(c *Config) {
Expand Down
1 change: 1 addition & 0 deletions pkg/client/source/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (t *Source) Wrap(tgz, destWrap string, opts ...config.Option) (string, erro
fetchArtifacts := !cfg.SkipArtifacts

outputFile, err := wrap.Chart(tgz, wrap.WithFetchArtifacts(fetchArtifacts),
wrap.WithSkipPullImages(cfg.SkipImages),
wrap.WithInsecure(t.insecure), wrap.WithTempDirectory(wrapWorkdir),
wrap.WithAuth(t.username, t.password),
wrap.WithPlatforms(cfg.ContainerPlatforms),
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/target/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func (t *Target) Unwrap(file string, _ *chart.Metadata, opts ...config.Option) e
unwrap.WithLogger(cfg.Logger),
unwrap.WithAuth(t.username, t.password), unwrap.WithInsecure(t.insecure),
unwrap.WithContainerRegistryAuth(t.containersUsername, t.containersPassword),
unwrap.WithSkipImageRelocation(cfg.SkipImages),
unwrap.WithSkipPullImages(cfg.SkipImages),
); err != nil {
return errors.Trace(err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/syncer/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (s *Syncer) syncChart(ch *Chart, l log.SectionLogger) error {
filepath.Join(workdir, "wraps", fmt.Sprintf("%s-%s.wrap.tgz", ch.Name, ch.Version)),
config.WithLogger(l), config.WithWorkDir(workdir),
config.WithContainerPlatforms(s.containerPlatforms), config.WithSkipArtifacts(s.skipArtifacts),
config.WithSkipImages(s.skipImages),
)
if err != nil {
return errors.Annotatef(err, "unable to move chart %q with charts-syncer", id)
Expand All @@ -57,7 +58,7 @@ func (s *Syncer) syncChart(ch *Chart, l log.SectionLogger) error {

klog.V(3).Infof("Uploading %q chart...", id)

if err := s.cli.dst.Unwrap(wrappedChartPath, metadata, config.WithLogger(l), config.WithWorkDir(workdir)); err != nil {
if err := s.cli.dst.Unwrap(wrappedChartPath, metadata, config.WithLogger(l), config.WithWorkDir(workdir), config.WithSkipImages(s.skipImages)); err != nil {
klog.Errorf("unable to upload %q chart: %+v", id, err)
return errors.Trace(err)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type Syncer struct {
// skip syncing artifacts
skipArtifacts bool

// skip syncing images
skipImages bool

// Storage directory for required artifacts
workdir string

Expand Down Expand Up @@ -101,6 +104,13 @@ func WithSkipArtifacts(skip bool) Option {
}
}

// WithSkipImages configures the syncer to skip syncing images
func WithSkipImages(skip bool) Option {
return func(s *Syncer) {
s.skipImages = skip
}
}

// WithWorkdir configures the syncer to store artifacts in a specific directory.
func WithWorkdir(dir string) Option {
return func(s *Syncer) {
Expand Down

0 comments on commit 19fd002

Please sign in to comment.