From 08a2b2814b36766546c127543de22590e53199a2 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 10 Oct 2024 08:31:45 +0200 Subject: [PATCH 1/3] Rename oci.go to download.go This is about downloading OCI artifacts, so it seems to be a more appropriate name. Signed-off-by: Tom Wieczorek --- internal/oci/{oci.go => download.go} | 0 internal/oci/{oci_test.go => download_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename internal/oci/{oci.go => download.go} (100%) rename internal/oci/{oci_test.go => download_test.go} (100%) diff --git a/internal/oci/oci.go b/internal/oci/download.go similarity index 100% rename from internal/oci/oci.go rename to internal/oci/download.go diff --git a/internal/oci/oci_test.go b/internal/oci/download_test.go similarity index 100% rename from internal/oci/oci_test.go rename to internal/oci/download_test.go From de26f2e792afcd218b16e8445dd44ac5bf547c66 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 10 Oct 2024 08:43:52 +0200 Subject: [PATCH 2/3] Remove the unused file store in a temp folder The download works without it since efc3f72bb. Signed-off-by: Tom Wieczorek --- internal/oci/download.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/internal/oci/download.go b/internal/oci/download.go index 2e003eace085..ccf0a1a812ba 100644 --- a/internal/oci/download.go +++ b/internal/oci/download.go @@ -22,11 +22,9 @@ import ( "fmt" "io" "net/http" - "os" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras-go/v2/content" - "oras.land/oras-go/v2/content/file" "oras.land/oras-go/v2/registry" "oras.land/oras-go/v2/registry/remote" "oras.land/oras-go/v2/registry/remote/auth" @@ -59,12 +57,6 @@ func Download(ctx context.Context, url string, target io.Writer, options ...Down return fmt.Errorf("failed to parse artifact reference: %w", err) } - tmpdir, err := os.MkdirTemp("", "k0s-oci-artifact-*") - if err != nil { - return fmt.Errorf("failed to create temp dir: %w", err) - } - defer func() { _ = os.RemoveAll(tmpdir) }() - repo, err := remote.NewRepository(url) if err != nil { return fmt.Errorf("failed to create repository: %w", err) @@ -74,12 +66,6 @@ func Download(ctx context.Context, url string, target io.Writer, options ...Down repo.PlainHTTP = true } - fs, err := file.New(tmpdir) - if err != nil { - return fmt.Errorf("failed to create file store: %w", err) - } - defer fs.Close() - transp := http.DefaultTransport.(*http.Transport).Clone() if opts.insecureSkipTLSVerify { transp.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} From 2abd4d141346c548f5d8bc94090f93a72a2f03cb Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 10 Oct 2024 09:38:52 +0200 Subject: [PATCH 3/3] Close the test HTTP server when the tests are complete Signed-off-by: Tom Wieczorek --- internal/oci/download_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/oci/download_test.go b/internal/oci/download_test.go index 37f9208b04f8..cc7512311cd9 100644 --- a/internal/oci/download_test.go +++ b/internal/oci/download_test.go @@ -186,6 +186,7 @@ func startOCIMockServer(t *testing.T, tname string, test testFile) string { w.WriteHeader(http.StatusNotFound) }), ) + t.Cleanup(server.Close) u, err := url.Parse(server.URL) require.NoError(t, err)