From fcf5e8c257a90545f8e5b1b49b32fbf746ce4701 Mon Sep 17 00:00:00 2001 From: Yan Song Date: Thu, 22 Dec 2022 06:47:31 +0000 Subject: [PATCH] nydusify: fix tests after refactoring And remove useless `registry` backend type. Signed-off-by: Yan Song --- contrib/nydusify/cmd/nydusify.go | 10 ++-- contrib/nydusify/examples/converter/main.go | 40 ++------------- contrib/nydusify/tests/nydusify.go | 55 +++------------------ 3 files changed, 16 insertions(+), 89 deletions(-) diff --git a/contrib/nydusify/cmd/nydusify.go b/contrib/nydusify/cmd/nydusify.go index d76ed2e2631..c90fdcd61bd 100644 --- a/contrib/nydusify/cmd/nydusify.go +++ b/contrib/nydusify/cmd/nydusify.go @@ -72,7 +72,7 @@ func getBackendConfig(c *cli.Context, required bool) (string, string, error) { } return "", "", nil } - possibleBackendTypes := []string{"registry", "oss", "s3"} + possibleBackendTypes := []string{"oss", "s3"} if !isPossibleValue(possibleBackendTypes, backendType) { return "", "", fmt.Errorf("--backend-type should be one of %v", possibleBackendTypes) } @@ -240,7 +240,7 @@ func main() { &cli.StringFlag{ Name: "backend-type", Value: "registry", - Usage: "Type of storage backend, possible values: 'registry', 'oss', 's3'", + Usage: "Type of storage backend, possible values: 'oss', 's3'", EnvVars: []string{"BACKEND_TYPE"}, }, &cli.StringFlag{ @@ -499,7 +499,7 @@ func main() { &cli.StringFlag{ Name: "backend-type", Value: "", - Usage: "Type of storage backend, enable verification of file data in Nydus image if specified, possible values: 'registry', 'oss', 's3'", + Usage: "Type of storage backend, enable verification of file data in Nydus image if specified, possible values: 'oss', 's3'", EnvVars: []string{"BACKEND_TYPE"}, }, &cli.StringFlag{ @@ -602,7 +602,7 @@ func main() { Name: "backend-type", Value: "", Required: true, - Usage: "Type of storage backend, possible values: 'registry', 'oss', 's3'", + Usage: "Type of storage backend, possible values: 'oss', 's3'", EnvVars: []string{"BACKEND_TYPE"}, }, &cli.StringFlag{ @@ -714,7 +714,7 @@ func main() { Name: "backend-type", Value: "oss", DefaultText: "oss", - Usage: "Type of storage backend, possible values: 'registry', 'oss', 's3'", + Usage: "Type of storage backend, possible values: 'oss', 's3'", EnvVars: []string{"BACKEND_TYPE"}, }, &cli.StringFlag{ diff --git a/contrib/nydusify/examples/converter/main.go b/contrib/nydusify/examples/converter/main.go index a6eea2af894..acfb70d388b 100644 --- a/contrib/nydusify/examples/converter/main.go +++ b/contrib/nydusify/examples/converter/main.go @@ -4,7 +4,6 @@ import ( "context" "github.com/dragonflyoss/image-service/contrib/nydusify/pkg/converter" - "github.com/dragonflyoss/image-service/contrib/nydusify/pkg/provider" ) func main() { @@ -13,37 +12,13 @@ func main() { nydusImagePath := "/path/to/nydus-image" source := "localhost:5000/ubuntu:latest" target := "localhost:5000/ubuntu:latest-nydus" - // Set to empty if no authorization be required - auth := "" - // Set to false if using https registry - insecure := true - - // Logger outputs Nydus image conversion progress - logger, err := provider.DefaultLogger() - if err != nil { - panic(err) - } - - // Create remote with auth string for registry communication - sourceRemote, err := provider.DefaultRemoteWithAuth(source, insecure, auth) - if err != nil { - panic(err) - } - // Or we can create with docker config - // sourceRemote, err := provider.DefaultRemote(source, insecure) - // if err != nil { - // panic(err) - // } - targetRemote, err := provider.DefaultRemoteWithAuth(target, insecure, auth) - if err != nil { - panic(err) - } opt := converter.Opt{ - Logger: logger, TargetPlatform: "linux/amd64", - SourceRemote: sourceRemote, - TargetRemote: targetRemote, + Source: source, + Target: target, + SourceInsecure: true, + TargetInsecure: true, WorkDir: workDir, PrefetchPatterns: "/", @@ -52,12 +27,7 @@ func main() { DockerV2Format: true, } - cvt, err := converter.New(opt) - if err != nil { - panic(err) - } - - if err := cvt.Convert(context.Background()); err != nil { + if err := converter.Convert(context.Background(), opt); err != nil { panic(err) } } diff --git a/contrib/nydusify/tests/nydusify.go b/contrib/nydusify/tests/nydusify.go index a7f00ffe5b2..6b0a0580948 100644 --- a/contrib/nydusify/tests/nydusify.go +++ b/contrib/nydusify/tests/nydusify.go @@ -6,10 +6,8 @@ package tests import ( "context" - "encoding/json" "os" "path/filepath" - "strings" "testing" "github.com/sirupsen/logrus" @@ -17,8 +15,6 @@ import ( "github.com/dragonflyoss/image-service/contrib/nydusify/pkg/checker" "github.com/dragonflyoss/image-service/contrib/nydusify/pkg/converter" - "github.com/dragonflyoss/image-service/contrib/nydusify/pkg/provider" - "github.com/dragonflyoss/image-service/contrib/nydusify/pkg/remote" ) var nydusImagePath string @@ -47,25 +43,12 @@ type Nydusify struct { workDir string } -func buildRegistryBackendConfig(registry *Registry, repo string) string { - config := make(map[string]string) - config["host"] = registry.host - config["repo"] = repo - config["scheme"] = "http" - if registry.authString != "" { - config["auth"] = registry.authString - } - configBytes, _ := json.Marshal(config) - return string(configBytes) -} - func NewNydusify(registry *Registry, source, target, cache string, chunkDictArgs string, fsVersion string) *Nydusify { - backendType := "registry" + backendType := "" if os.Getenv("BACKEND_TYPE") != "" { backendType = os.Getenv("BACKEND_TYPE") } - repoTag := strings.Split(target, ":") - backendConfig := buildRegistryBackendConfig(registry, repoTag[0]) + backendConfig := "" if os.Getenv("BACKEND_CONFIG") != "" { backendConfig = os.Getenv("BACKEND_CONFIG") } @@ -102,30 +85,12 @@ func (nydusify *Nydusify) Convert(t *testing.T) { buildCache = host + "/" + nydusify.Cache } - logger, err := provider.DefaultLogger() - assert.Nil(t, err) - - sourceRemote, err := provider.DefaultRemote(host+"/"+nydusify.Source, true) - assert.Nil(t, err) - - targetRemote, err := provider.DefaultRemote(host+"/"+nydusify.Target, true) - assert.Nil(t, err) - - var cacheRemote *remote.Remote - if buildCache != "" { - buildCache = host + "/" + nydusify.Cache - cacheRemote, err = provider.DefaultRemote(buildCache, true) - assert.Nil(t, err) - } - opt := converter.Opt{ - Logger: logger, - TargetPlatform: "linux/amd64", - SourceRemote: sourceRemote, - TargetRemote: targetRemote, + Source: host + "/" + nydusify.Source, + Target: host + "/" + nydusify.Target, - CacheRemote: cacheRemote, + CacheRef: buildCache, CacheMaxRecords: 10, CacheVersion: "v1", @@ -138,18 +103,10 @@ func (nydusify *Nydusify) Convert(t *testing.T) { BackendType: nydusify.backendType, BackendConfig: nydusify.backendConfig, - ChunkDict: converter.ChunkDictOpt{ - Args: nydusify.chunkDictArgs, - Insecure: false, - Platform: "linux/amd64", - }, FsVersion: nydusify.fsVersion, } - cvt, err := converter.New(opt) - assert.Nil(t, err) - - err = cvt.Convert(context.Background()) + err := converter.Convert(context.Background(), opt) assert.Nil(t, err) }