Skip to content

Commit

Permalink
Support limiting the container platfoms to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
juamedgod committed Feb 26, 2024
1 parent 9a06c41 commit 6ec5ea4
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 57 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Sync chart packages and associated container images between chart repositories
+ [Sync all charts](#sync-all-helm-charts)
+ [Sync all charts from specific date](#sync-all-charts-from-specific-date)
- [Advanced Usage](#advanced-usage)
+ [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)
- [Configuration](#configuration)
Expand Down Expand Up @@ -50,6 +51,32 @@ $ charts-syncer sync --latest-version-only

## Advanced Usage

### Sync only specific container platforms

By default, all container platforms are sync-ed to the destination registry, but this behavior can by tweaked by defining a list of platforms to sync:

```yaml
#
# Example config file
#
source:
repo:
kind: OCI
url: http://localhost:8080
target:
# Container images registry authn
repo:
kind: OCI
url: http://localhost:9090/charts

containerPlatforms:
- linux/amd64

charts:
- redis
- mariadb
```
### Sync Helm Charts and Container Images to different registries
By default, charts-syncer syncs Helm Charts packages and their container images to the same registry specified in the `target.repo.url` property. If you require to configure a different destination registry for the images, this can be configured in the `target.containers.url` property:
Expand Down
120 changes: 66 additions & 54 deletions api/config.pb.go

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

2 changes: 2 additions & 0 deletions api/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ message Config {
Target target = 2;
// Helm Charts to include during sync
repeated string charts = 3;
// Container platforms to sync
repeated string container_platforms = 4;
// Opposite of charts property. It indicates the list of charts to skip during sync
repeated string skip_charts = 5;
}
Expand Down
1 change: 1 addition & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func newSyncCmd() *cobra.Command {
syncer.WithDryRun(rootDryRun),
syncer.WithFromDate(syncFromDate),
syncer.WithWorkdir(syncWorkdir),
syncer.WithContainerPlatforms(c.GetContainerPlatforms()),
syncer.WithInsecure(rootInsecure),
syncer.WithLatestVersionOnly(syncLatestVersionOnly),
syncer.WithSkipCharts(c.SkipCharts),
Expand Down
12 changes: 10 additions & 2 deletions pkg/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

// Config is the configuration object for the client package
type Config struct {
Logger log.SectionLogger
WorkDir string
Logger log.SectionLogger
WorkDir string
ContainerPlatforms []string
}

// Option is a function that modifies the Config
Expand All @@ -22,6 +23,13 @@ func WithWorkDir(workdir string) func(*Config) {
}
}

// WithContainerPlatforms sets the container platforms to sync
func WithContainerPlatforms(containerPlatforms []string) func(*Config) {
return func(c *Config) {
c.ContainerPlatforms = containerPlatforms
}
}

// WithLogger sets the logger
func WithLogger(logger log.SectionLogger) 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
outputFile, err := wrap.Chart(tgz, wrap.WithFetchArtifacts(true),
wrap.WithInsecure(t.insecure), wrap.WithTempDirectory(wrapWorkdir),
wrap.WithAuth(t.username, t.password),
wrap.WithPlatforms(cfg.ContainerPlatforms),
wrap.WithContainerRegistryAuth(t.containersUsername, t.containersPassword),
wrap.WithOutputFile(destWrap),
wrap.WithLogger(l))
Expand Down
2 changes: 1 addition & 1 deletion pkg/syncer/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Syncer) syncChart(ch *Chart, l log.SectionLogger) error {

wrappedChartPath, err := s.cli.src.Wrap(ch.TgzPath,
filepath.Join(workdir, "wraps", fmt.Sprintf("%s-%s.wrap.tgz", ch.Name, ch.Version)),
config.WithLogger(l), config.WithWorkDir(workdir),
config.WithLogger(l), config.WithWorkDir(workdir), config.WithContainerPlatforms(s.containerPlatforms),
)
if err != nil {
return errors.Annotatef(err, "unable to move chart %q with charts-syncer", id)
Expand Down
10 changes: 10 additions & 0 deletions pkg/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Syncer struct {
// list of charts to skip
skipCharts []string

// list of container platforms to sync
containerPlatforms []string
// TODO(jdrios): Cache index in local filesystem to speed
// up re-runs
index ChartIndex
Expand Down Expand Up @@ -164,3 +166,11 @@ func WithSkipCharts(charts []string) Option {
s.skipCharts = charts
}
}

// WithContainerPlatforms configures the syncer to sync chart containers for only
// the specified list of platforms. Leaving a blank list syncs all.
func WithContainerPlatforms(platforms []string) Option {
return func(s *Syncer) {
s.containerPlatforms = platforms
}
}

0 comments on commit 6ec5ea4

Please sign in to comment.