From bb83d5ce5b49aea1b9cfbaaf1c0b512f9207b78c Mon Sep 17 00:00:00 2001 From: Josh Wolf Date: Wed, 8 Dec 2021 09:25:45 -0700 Subject: [PATCH] allow file content to be passed a custom config --- pkg/content/file/file.go | 6 +++++- pkg/content/file/options.go | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/content/file/file.go b/pkg/content/file/file.go index db8715d..ad356b5 100644 --- a/pkg/content/file/file.go +++ b/pkg/content/file/file.go @@ -87,7 +87,11 @@ func (f *file) compute() error { return err } - cfg := f.client.Config(f.ref) + cfg := f.config + if cfg == nil { + cfg = f.client.Config(f.ref) + } + cfgDesc, err := partial.Descriptor(cfg) if err != nil { return err diff --git a/pkg/content/file/options.go b/pkg/content/file/options.go index 3f9661f..bc26b42 100644 --- a/pkg/content/file/options.go +++ b/pkg/content/file/options.go @@ -1,6 +1,9 @@ package file -import "github.com/rancherfederal/hauler/internal/getter" +import ( + "github.com/rancherfederal/hauler/internal/getter" + "github.com/rancherfederal/hauler/pkg/artifact" +) type Option func(*file) @@ -9,3 +12,15 @@ func WithClient(c *getter.Client) Option { f.client = c } } + +func WithConfig(obj interface{}, mediaType string) Option { + return func(f *file) { + f.config = artifact.ToConfig(obj, artifact.WithConfigMediaType(mediaType)) + } +} + +func WithAnnotations(m map[string]string) Option { + return func(f *file) { + f.annotations = m + } +}