From c341929a57fd56bd64223b0454168c50971b1a8d Mon Sep 17 00:00:00 2001 From: Josh Wolf Date: Tue, 25 Jan 2022 08:07:43 -0700 Subject: [PATCH] add optional args to file name generation and discovery --- cmd/hauler/cli/store/add.go | 7 ++++++- go.mod | 2 +- go.sum | 4 ++-- pkg/apis/hauler.cattle.io/v1alpha1/file.go | 7 +++---- pkg/collection/k3s/k3s.go | 4 ++-- testdata/contents.yaml | 7 ++++--- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cmd/hauler/cli/store/add.go b/cmd/hauler/cli/store/add.go index 6513bbb..666839b 100644 --- a/cmd/hauler/cli/store/add.go +++ b/cmd/hauler/cli/store/add.go @@ -4,6 +4,7 @@ import ( "context" "github.com/google/go-containerregistry/pkg/name" + "github.com/rancherfederal/ocil/pkg/artifacts/file/getter" "github.com/spf13/cobra" "helm.sh/helm/v3/pkg/action" @@ -39,7 +40,11 @@ func AddFileCmd(ctx context.Context, o *AddFileOpts, s *store.Layout, reference func storeFile(ctx context.Context, s *store.Layout, fi v1alpha1.File) error { l := log.FromContext(ctx) - f := file.NewFile(fi.Path) + copts := getter.ClientOptions{ + NameOverride: fi.Name, + } + + f := file.NewFile(fi.Path, file.WithClient(getter.NewClient(copts))) ref, err := reference.NewTagged(f.Name(fi.Path), reference.DefaultTag) if err != nil { return err diff --git a/go.mod b/go.mod index 0c62d6f..6c27b0d 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/mholt/archiver/v3 v3.5.1 github.com/opencontainers/image-spec v1.0.2 github.com/pkg/errors v0.9.1 - github.com/rancherfederal/ocil v0.1.8 + github.com/rancherfederal/ocil v0.1.9 github.com/rs/zerolog v1.26.0 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.3.0 diff --git a/go.sum b/go.sum index b86d455..f8d90f6 100644 --- a/go.sum +++ b/go.sum @@ -961,8 +961,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/rancherfederal/ocil v0.1.8 h1:jVYD/AY7ipXgKepdZDDG1mxMOxCk/KIDdZw2qsseR+c= -github.com/rancherfederal/ocil v0.1.8/go.mod h1:l4d1cHHfdXDGtio32AYDjG6n1i1JxQK+kAom0cVf0SY= +github.com/rancherfederal/ocil v0.1.9 h1:pmiUQCh2HTIMDD9tDj/UqBAAxq4yloLFgd2WnrZnQgc= +github.com/rancherfederal/ocil v0.1.9/go.mod h1:l4d1cHHfdXDGtio32AYDjG6n1i1JxQK+kAom0cVf0SY= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/pkg/apis/hauler.cattle.io/v1alpha1/file.go b/pkg/apis/hauler.cattle.io/v1alpha1/file.go index b28e821..6601674 100644 --- a/pkg/apis/hauler.cattle.io/v1alpha1/file.go +++ b/pkg/apis/hauler.cattle.io/v1alpha1/file.go @@ -21,8 +21,7 @@ type File struct { // Path is the path to the file contents, can be a local or remote path Path string `json:"path"` - // Reference is an optionally defined reference to the contents within the store - // If not specified, this will be generated as follows: - // hauler/:latest - Reference string `json:"reference,omitempty"` + // Name is an optional field specifying the name of the file when specified, + // it will override any dynamic name discovery from Path + Name string `json:"name,omitempty"` } diff --git a/pkg/collection/k3s/k3s.go b/pkg/collection/k3s/k3s.go index e8688be..28aae22 100644 --- a/pkg/collection/k3s/k3s.go +++ b/pkg/collection/k3s/k3s.go @@ -106,8 +106,8 @@ func (k *k3s) executable() error { } func (k *k3s) bootstrap() error { - namedBootstrapUrl := fmt.Sprintf("%s?filename=%s", bootstrapUrl, "k3s-init.sh") - f := file.NewFile(namedBootstrapUrl) + c := getter.NewClient(getter.ClientOptions{NameOverride: "k3s-init.sh"}) + f := file.NewFile(bootstrapUrl, file.WithClient(c)) ref := fmt.Sprintf("%s/k3s-init.sh:%s", reference.DefaultNamespace, reference.DefaultTag) k.contents[ref] = f diff --git a/testdata/contents.yaml b/testdata/contents.yaml index 6a51974..e150a2c 100644 --- a/testdata/contents.yaml +++ b/testdata/contents.yaml @@ -7,15 +7,16 @@ spec: # hauler can save/redistribute files on disk (be careful! paths are relative) - path: testdata/contents.yaml - # TODO: when directories are specified, they will be archived and stored as a file -# - path: testdata/ + # when directories are specified, the directory contents will be archived and stored + - path: testdata/ # hauler can also fetch remote content, and will "smartly" identify filenames _when possible_ # filename below = "k3s-images.txt" - path: "https://github.com/k3s-io/k3s/releases/download/v1.22.2%2Bk3s2/k3s-images.txt" - # when filenames are not appropriate, a name should be specified + # when discovered filenames are not desired, a file name can be specified - path: https://get.k3s.io + name: k3s-init.sh --- apiVersion: content.hauler.cattle.io/v1alpha1