Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow relocating images with relok8s lib #115

Merged
merged 2 commits into from
Nov 30, 2021
Merged

Conversation

tompizmor
Copy link
Member

@tompizmor tompizmor commented Nov 30, 2021

This PR adds a new feature to charts-syncer.

It is possible to do a full relocation of the chart (including container images) thanks to the integration with the relok8s library.

For that we should only add relocateContainerImages: true to our config file. However, in order to relok8s to work properly, it requires that the source chart includes an image hints file. Currently, this file should be called .relok8s-images.yaml and should be packaged inside the chart. If this file is not found, the sync for that specific chart will be skipped.

If relocateContainerImages is not set or set to false, charts-syncer will continue working as of today. This is, it will sync chart packages (but no container images) if source charts fulfil the documented requirements

Usage:

$ charts-syncer sync --config ./dist/config-chartmuseum-chartmuseum-relok8s.yaml

I1130 15:34:35.841626   49696 sync.go:32] Using config file: "./dist/config-chartmuseum-chartmuseum-relok8s.yaml"
I1130 15:34:35.868143   49696 sync.go:45] There is 1 chart out of sync!
I1130 15:34:35.868158   49696 sync.go:53] Syncing "apache-8.9.3" chart...
.relok8s-images.yaml hints file found
Computing relocation...

Relocating [email protected]...
Pushing demo.goharbor.io/tpizarro/containers/apache:2.4.51-debian-10-r39...
Done
Pushing demo.goharbor.io/tpizarro/containers/git:2.34.0-debian-10-r0...
Done
Pushing demo.goharbor.io/tpizarro/containers/apache-exporter:0.10.1-debian-10-r56...
Done
Done
/var/folders/23/7yxk2qds2rndbq5t5_r1wnzh0000gp/T/charts-syncer002263068/apache-8.9.3.relocated.tgz

Copy link

@migmartri migmartri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, could you add an issue about documenting this feature?

klog.Errorf("unable to build %q chart dependencies: %+v", id, err)
errs = multierror.Append(errs, errors.Trace(err))
if s.relocateContainerImages {
packagedChartPath, err = s.SyncWithRelok8s(ch, outdir)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how you encapsulated the methods SyncWithRelok8s and SyncWithChartsSyncer :)

@@ -133,3 +109,90 @@ func (s *Syncer) SyncPendingCharts(names ...string) error {

return errors.Trace(errs)
}

func (s *Syncer) SyncWithRelok8s(chart *Chart, outdir string) (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a comment on top of this method explaining what it does, its requirements and so on


func (s *Syncer) SyncWithRelok8s(chart *Chart, outdir string) (string, error) {
outputChartPath := filepath.Join(outdir, "%s-%s.relocated.tgz")
packagedChartPath := filepath.Join(outdir, fmt.Sprintf("%s-%s.relocated.tgz", chart.Name, chart.Version))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a TODO comment saying to change it once vmware-tanzu/asset-relocation-tool-for-kubernetes#94 is fixed

Target: mover.Target{
Rules: mover.RewriteRules{
Registry: s.target.GetContainerRegistry(),
RepositoryPrefix: s.target.GetContainerRepository(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now add ForcePush if you update to v0.3.45

Copy link

@migmartri migmartri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants