From 59ff02b52b1ccc324b828f86f0bd333d3afc0d25 Mon Sep 17 00:00:00 2001 From: Adam Martin Date: Sat, 10 Feb 2024 22:38:11 -0500 Subject: [PATCH] add annotations for registry Signed-off-by: Adam Martin --- cmd/hauler/cli/store/sync.go | 15 ++++++++++++--- pkg/consts/consts.go | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/hauler/cli/store/sync.go b/cmd/hauler/cli/store/sync.go index c0ae6c6..ce01153 100644 --- a/cmd/hauler/cli/store/sync.go +++ b/cmd/hauler/cli/store/sync.go @@ -8,12 +8,11 @@ import ( "os" "strings" + "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "helm.sh/helm/v3/pkg/action" "k8s.io/apimachinery/pkg/util/yaml" - "github.com/mitchellh/go-homedir" - "github.com/rancherfederal/hauler/pkg/store" "github.com/rancherfederal/hauler/pkg/apis/hauler.cattle.io/v1alpha1" tchart "github.com/rancherfederal/hauler/pkg/collection/chart" "github.com/rancherfederal/hauler/pkg/collection/imagetxt" @@ -22,6 +21,8 @@ import ( "github.com/rancherfederal/hauler/pkg/content" "github.com/rancherfederal/hauler/pkg/cosign" "github.com/rancherfederal/hauler/pkg/log" + "github.com/rancherfederal/hauler/pkg/reference" + "github.com/rancherfederal/hauler/pkg/store" ) type SyncOpts struct { @@ -174,7 +175,15 @@ func processContent(ctx context.Context, fi *os.File, o *SyncOpts, s *store.Layo } l.Debugf("platform for image [%s]", platform) - + // Check if the user provided a registry. If a registry is provided in the annotation, use it for the images that don't have a registry in their ref name. + if a[consts.ImageAnnotationRegistry] != "" { + newRef,_ := reference.Parse(i.Name) + if newRef.Context().RegistryStr() == "" { + newRef,_ = reference.Relocate(i.Name, a[consts.ImageAnnotationRegistry]) + } + i.Name = newRef.Name() + } + err = storeImage(ctx, s, i, platform) if err != nil { return err diff --git a/pkg/consts/consts.go b/pkg/consts/consts.go index 6af0075..a3853e2 100644 --- a/pkg/consts/consts.go +++ b/pkg/consts/consts.go @@ -53,4 +53,5 @@ const ( CarbideRegistry = "rgcrprod.azurecr.us" ImageAnnotationKey = "hauler.dev/key" ImageAnnotationPlatform = "hauler.dev/platform" + ImageAnnotationRegistry = "hauler.dev/registry" )