From 2761a7200771756f0671d17eb9791797274489e1 Mon Sep 17 00:00:00 2001 From: Yuvraj Date: Thu, 9 Sep 2021 14:41:41 +0530 Subject: [PATCH] added support for helm (#177) * added support for the helm Signed-off-by: Yuvraj --- .../config/subcommand/sandbox/config_flags.go | 4 +- .../subcommand/sandbox/sandbox_config.go | 8 +- flytectl/cmd/sandbox/sandbox.go | 2 +- flytectl/cmd/sandbox/start.go | 114 +++++++++--------- flytectl/cmd/sandbox/start_test.go | 75 ++++++++---- flytectl/pkg/docker/docker_util.go | 7 +- flytectl/pkg/util/githubutil/githubutil.go | 43 +++---- .../pkg/util/githubutil/githubutil_test.go | 27 ++--- 8 files changed, 154 insertions(+), 126 deletions(-) diff --git a/flytectl/cmd/config/subcommand/sandbox/config_flags.go b/flytectl/cmd/config/subcommand/sandbox/config_flags.go index 7126d6a2e3..ca50e9ad28 100755 --- a/flytectl/cmd/config/subcommand/sandbox/config_flags.go +++ b/flytectl/cmd/config/subcommand/sandbox/config_flags.go @@ -50,7 +50,7 @@ func (Config) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) - cmdFlags.StringVar(&DefaultConfig.Source, fmt.Sprintf("%v%v", prefix, "source"), DefaultConfig.Source, " Path of your source code") - cmdFlags.StringVar(&DefaultConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultConfig.Version, "Version of flyte") + cmdFlags.StringVar(&DefaultConfig.Source, fmt.Sprintf("%v%v", prefix, "source"), DefaultConfig.Source, "Path of your source code") + cmdFlags.StringVar(&DefaultConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultConfig.Version, "Version of flyte. Only support v0.10.0+ flyte release") return cmdFlags } diff --git a/flytectl/cmd/config/subcommand/sandbox/sandbox_config.go b/flytectl/cmd/config/subcommand/sandbox/sandbox_config.go index 5d3bfa9184..7005b031b1 100644 --- a/flytectl/cmd/config/subcommand/sandbox/sandbox_config.go +++ b/flytectl/cmd/config/subcommand/sandbox/sandbox_config.go @@ -7,6 +7,10 @@ var ( //Config type Config struct { - Source string `json:"source" pflag:",Path of your source code"` - Version string `json:"version" pflag:",Version of flyte"` + Source string `json:"source" pflag:",Path of your source code"` + + // Flytectl sandbox only support flyte version available in Github release https://github.com/flyteorg/flyte/tags + // Flytectl sandbox will only work for v0.10.0+ + // Default value dind represent the latest release + Version string `json:"version" pflag:",Version of flyte. Only support v0.10.0+ flyte release"` } diff --git a/flytectl/cmd/sandbox/sandbox.go b/flytectl/cmd/sandbox/sandbox.go index 9be32bbba4..b269f378be 100644 --- a/flytectl/cmd/sandbox/sandbox.go +++ b/flytectl/cmd/sandbox/sandbox.go @@ -56,7 +56,7 @@ func CreateSandboxCommand() *cobra.Command { Long: statusLong}, "exec": {CmdFunc: sandboxClusterExec, Aliases: []string{}, ProjectDomainNotRequired: true, Short: execShort, - Long: execLong, PFlagProvider: sandboxConfig.DefaultConfig}, + Long: execLong}, } cmdcore.AddCommands(sandbox, sandboxResourcesFuncs) diff --git a/flytectl/cmd/sandbox/start.go b/flytectl/cmd/sandbox/start.go index c5559988fe..b36324be14 100644 --- a/flytectl/cmd/sandbox/start.go +++ b/flytectl/cmd/sandbox/start.go @@ -9,17 +9,15 @@ import ( "path/filepath" "time" + "github.com/flyteorg/flytectl/clierrors" + "github.com/flyteorg/flytectl/pkg/util/githubutil" + "github.com/avast/retry-go" "github.com/olekukonko/tablewriter" corev1api "k8s.io/api/core/v1" corev1 "k8s.io/client-go/kubernetes/typed/core/v1" - "github.com/flyteorg/flytectl/pkg/util/githubutil" - - "github.com/flyteorg/flytestdlib/logger" - "github.com/docker/docker/api/types/mount" - "github.com/flyteorg/flytectl/clierrors" "github.com/flyteorg/flytectl/pkg/configutil" "github.com/flyteorg/flytectl/pkg/k8s" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -28,7 +26,6 @@ import ( sandboxConfig "github.com/flyteorg/flytectl/cmd/config/subcommand/sandbox" cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/flyteorg/flytectl/pkg/docker" - f "github.com/flyteorg/flytectl/pkg/filesystemutils" "github.com/flyteorg/flytectl/pkg/util" ) @@ -47,23 +44,22 @@ Mount your source code repository inside sandbox bin/flytectl sandbox start --source=$HOME/flyteorg/flytesnacks -Run specific version of flyte, Only available after v0.13.0+ +Run specific version of flyte. flytectl sandbox only support flyte version available in Github release https://github.com/flyteorg/flyte/tags :: bin/flytectl sandbox start --version=v0.14.0 +Note: Flytectl sandbox will only work for v0.10.0+ + Usage ` - k8sEndpoint = "https://127.0.0.1:30086" - flyteMinimumVersionSupported = "v0.13.0" - generatedManifest = "/flyteorg/share/flyte_generated.yaml" - flyteNamespace = "flyte" - diskPressureTaint = "node.kubernetes.io/disk-pressure" - taintEffect = "NoSchedule" -) - -var ( - flyteManifest = f.FilePathJoin(f.UserHomeDir(), ".flyte", "flyte_generated.yaml") + k8sEndpoint = "https://127.0.0.1:30086" + flyteNamespace = "flyte" + flyteRepository = "flyte" + dind = "dind" + sandboxSupportedVersion = "v0.10.0" + diskPressureTaint = "node.kubernetes.io/disk-pressure" + taintEffect = "NoSchedule" ) type ExecResult struct { @@ -86,23 +82,23 @@ func startSandboxCluster(ctx context.Context, args []string, cmdCtx cmdCore.Comm docker.WaitForSandbox(reader, docker.SuccessMessage) } - var k8sClient k8s.K8s - err = retry.Do( - func() error { - k8sClient, err = k8s.GetK8sClient(docker.Kubeconfig, k8sEndpoint) + if reader != nil { + var k8sClient k8s.K8s + err = retry.Do( + func() error { + k8sClient, err = k8s.GetK8sClient(docker.Kubeconfig, k8sEndpoint) + return err + }, + retry.Attempts(10), + ) + if err != nil { return err - }, - retry.Attempts(10), - ) - if err != nil { - return err - } - - if err := watchFlyteDeployment(ctx, k8sClient.CoreV1()); err != nil { - return err + } + if err := watchFlyteDeployment(ctx, k8sClient.CoreV1()); err != nil { + return err + } + util.PrintSandboxMessage() } - - util.PrintSandboxMessage() return nil } @@ -113,7 +109,7 @@ func startSandbox(ctx context.Context, cli docker.Docker, reader io.Reader) (*bu if err.Error() != clierrors.ErrSandboxExists { return nil, err } - fmt.Printf("Existing details of your sandbox:") + fmt.Printf("Existing details of your sandbox") util.PrintSandboxMessage() return nil, nil } @@ -137,35 +133,18 @@ func startSandbox(ctx context.Context, cli docker.Docker, reader io.Reader) (*bu volumes = append(volumes, *vol) } - if len(sandboxConfig.DefaultConfig.Version) > 0 { - isGreater, err := util.IsVersionGreaterThan(sandboxConfig.DefaultConfig.Version, flyteMinimumVersionSupported) - if err != nil { - return nil, err - } - if !isGreater { - logger.Infof(ctx, "version flag only supported after with flyte %s+ release", flyteMinimumVersionSupported) - return nil, fmt.Errorf("version flag only supported after with flyte %s+ release", flyteMinimumVersionSupported) - } - if err := githubutil.GetFlyteManifest(sandboxConfig.DefaultConfig.Version, flyteManifest); err != nil { - return nil, err - } - - if vol, err := mountVolume(flyteManifest, generatedManifest); err != nil { - return nil, err - } else if vol != nil { - volumes = append(volumes, *vol) - } - + image, err := getSandboxImage(sandboxConfig.DefaultConfig.Version) + if err != nil { + return nil, err } - - fmt.Printf("%v pulling docker image %s\n", emoji.Whale, docker.ImageName) - if err := docker.PullDockerImage(ctx, cli, docker.ImageName); err != nil { + fmt.Printf("%v pulling docker image for release %s\n", emoji.Whale, image) + if err := docker.PullDockerImage(ctx, cli, image); err != nil { return nil, err } fmt.Printf("%v booting Flyte-sandbox container\n", emoji.FactoryWorker) exposedPorts, portBindings, _ := docker.GetSandboxPorts() - ID, err := docker.StartContainer(ctx, cli, volumes, exposedPorts, portBindings, docker.FlyteSandboxClusterName, docker.ImageName) + ID, err := docker.StartContainer(ctx, cli, volumes, exposedPorts, portBindings, docker.FlyteSandboxClusterName, image) if err != nil { fmt.Printf("%v Something went wrong: Failed to start Sandbox container %v, Please check your docker client and try again. \n", emoji.GrimacingFace, emoji.Whale) return nil, err @@ -179,6 +158,29 @@ func startSandbox(ctx context.Context, cli docker.Docker, reader io.Reader) (*bu return logReader, nil } +func getSandboxImage(version string) (string, error) { + // Latest release will use image cr.flyte.org/flyteorg/flyte-sandbox:dind + // In case of version flytectl will use cr.flyte.org/flyteorg/flyte-sandbox:dind-{SHA} + + var tag = dind + if len(version) > 0 { + isGreater, err := util.IsVersionGreaterThan(version, sandboxSupportedVersion) + if err != nil { + return "", err + } + if !isGreater { + return "", fmt.Errorf("version flag only supported with flyte %s+ release", sandboxSupportedVersion) + } + sha, err := githubutil.GetSHAFromVersion(version, flyteRepository) + if err != nil { + return "", err + } + tag = fmt.Sprintf("%s-%s", dind, sha) + } + + return docker.GetSandboxImage(tag), nil +} + func mountVolume(file, destination string) (*mount.Mount, error) { if len(file) > 0 { source, err := filepath.Abs(file) diff --git a/flytectl/cmd/sandbox/start_test.go b/flytectl/cmd/sandbox/start_test.go index f2b43ff8da..0d0331968c 100644 --- a/flytectl/cmd/sandbox/start_test.go +++ b/flytectl/cmd/sandbox/start_test.go @@ -10,6 +10,8 @@ import ( "strings" "testing" + "github.com/flyteorg/flytectl/pkg/util/githubutil" + "github.com/flyteorg/flytectl/pkg/k8s" "github.com/docker/docker/api/types" @@ -85,10 +87,11 @@ func TestStartSandboxFunc(t *testing.T) { ctx := context.Background() mockDocker := &mocks.Docker{} errCh := make(chan error) + sandboxConfig.DefaultConfig.Version = "" bodyStatus := make(chan container.ContainerWaitOKBody) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -118,7 +121,7 @@ func TestStartSandboxFunc(t *testing.T) { bodyStatus := make(chan container.ContainerWaitOKBody) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -155,6 +158,7 @@ func TestStartSandboxFunc(t *testing.T) { bodyStatus := make(chan container.ContainerWaitOKBody) mockDocker := &mocks.Docker{} sandboxConfig.DefaultConfig.Source = f.UserHomeDir() + sandboxConfig.DefaultConfig.Version = "" volumes := docker.Volumes volumes = append(volumes, mount.Mount{ Type: mount.TypeBind, @@ -163,7 +167,7 @@ func TestStartSandboxFunc(t *testing.T) { }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -192,6 +196,7 @@ func TestStartSandboxFunc(t *testing.T) { bodyStatus := make(chan container.ContainerWaitOKBody) mockDocker := &mocks.Docker{} sandboxConfig.DefaultConfig.Source = "../" + sandboxConfig.DefaultConfig.Version = "" absPath, err := filepath.Abs(sandboxConfig.DefaultConfig.Source) assert.Nil(t, err) volumes := docker.Volumes @@ -202,7 +207,7 @@ func TestStartSandboxFunc(t *testing.T) { }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -232,15 +237,14 @@ func TestStartSandboxFunc(t *testing.T) { mockDocker := &mocks.Docker{} sandboxConfig.DefaultConfig.Version = "v0.15.0" sandboxConfig.DefaultConfig.Source = "" + + sha, err := githubutil.GetSHAFromVersion(sandboxConfig.DefaultConfig.Version, "flyte") + assert.Nil(t, err) + volumes := docker.Volumes - volumes = append(volumes, mount.Mount{ - Type: mount.TypeBind, - Source: flyteManifest, - Target: generatedManifest, - }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(fmt.Sprintf("%s-%s", dind, sha)), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -260,7 +264,7 @@ func TestStartSandboxFunc(t *testing.T) { Follow: true, }).Return(nil, nil) mockDocker.OnContainerWaitMatch(ctx, mock.Anything, container.WaitConditionNotRunning).Return(bodyStatus, errCh) - _, err := startSandbox(ctx, mockDocker, os.Stdin) + _, err = startSandbox(ctx, mockDocker, os.Stdin) assert.Nil(t, err) }) t.Run("Failed run sandbox cluster with wrong version", func(t *testing.T) { @@ -271,14 +275,9 @@ func TestStartSandboxFunc(t *testing.T) { sandboxConfig.DefaultConfig.Version = "v0.1444.0" sandboxConfig.DefaultConfig.Source = "" volumes := docker.Volumes - volumes = append(volumes, mount.Mount{ - Type: mount.TypeBind, - Source: flyteManifest, - Target: generatedManifest, - }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -316,7 +315,7 @@ func TestStartSandboxFunc(t *testing.T) { }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -353,7 +352,7 @@ func TestStartSandboxFunc(t *testing.T) { }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -393,7 +392,7 @@ func TestStartSandboxFunc(t *testing.T) { sandboxConfig.DefaultConfig.Version = "" mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -430,7 +429,7 @@ func TestStartSandboxFunc(t *testing.T) { }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -459,6 +458,7 @@ func TestStartSandboxFunc(t *testing.T) { bodyStatus := make(chan container.ContainerWaitOKBody) mockDocker := &mocks.Docker{} sandboxConfig.DefaultConfig.Source = f.UserHomeDir() + sandboxConfig.DefaultConfig.Version = "" volumes := docker.Volumes volumes = append(volumes, mount.Mount{ Type: mount.TypeBind, @@ -467,7 +467,7 @@ func TestStartSandboxFunc(t *testing.T) { }) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -510,7 +510,7 @@ func TestStartSandboxFunc(t *testing.T) { bodyStatus := make(chan container.ContainerWaitOKBody) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -534,6 +534,7 @@ func TestStartSandboxFunc(t *testing.T) { mockDocker.OnContainerWaitMatch(ctx, mock.Anything, container.WaitConditionNotRunning).Return(bodyStatus, errCh) docker.Client = mockDocker sandboxConfig.DefaultConfig.Source = "" + sandboxConfig.DefaultConfig.Version = "" err = startSandboxCluster(ctx, []string{}, cmdCtx) assert.Nil(t, err) }) @@ -546,7 +547,7 @@ func TestStartSandboxFunc(t *testing.T) { bodyStatus := make(chan container.ContainerWaitOKBody) mockDocker.OnContainerCreate(ctx, &container.Config{ Env: docker.Environment, - Image: docker.ImageName, + Image: docker.GetSandboxImage(dind), Tty: false, ExposedPorts: p1, }, &container.HostConfig{ @@ -674,3 +675,29 @@ func TestGetNodeTaintStatus(t *testing.T) { assert.Equal(t, true, c) }) } + +func TestGetSandboxImage(t *testing.T) { + t.Run("Get Latest sandbox", func(t *testing.T) { + image, err := getSandboxImage("") + assert.Nil(t, err) + assert.Equal(t, docker.GetSandboxImage(dind), image) + }) + + t.Run("Get sandbox image with version ", func(t *testing.T) { + image, err := getSandboxImage("v0.14.0") + assert.Nil(t, err) + assert.Equal(t, true, strings.HasPrefix(image, docker.ImageName)) + }) + t.Run("Get sandbox image with wrong version ", func(t *testing.T) { + _, err := getSandboxImage("v100.1.0") + assert.NotNil(t, err) + }) + t.Run("Get sandbox image with wrong version ", func(t *testing.T) { + _, err := getSandboxImage("aaaaaa") + assert.NotNil(t, err) + }) + t.Run("Get sandbox image with version that is not supported", func(t *testing.T) { + _, err := getSandboxImage("v0.10.0") + assert.NotNil(t, err) + }) +} diff --git a/flytectl/pkg/docker/docker_util.go b/flytectl/pkg/docker/docker_util.go index de19ce15a0..1d3baabed5 100644 --- a/flytectl/pkg/docker/docker_util.go +++ b/flytectl/pkg/docker/docker_util.go @@ -24,7 +24,7 @@ import ( var ( Kubeconfig = f.FilePathJoin(f.UserHomeDir(), ".flyte", "k3s", "k3s.yaml") SuccessMessage = "Deploying Flyte..." - ImageName = "cr.flyte.org/flyteorg/flyte-sandbox:dind" + ImageName = "cr.flyte.org/flyteorg/flyte-sandbox" FlyteSandboxClusterName = "flyte-sandbox" Environment = []string{"SANDBOX=1", "KUBERNETES_API_PORT=30086", "FLYTE_HOST=localhost:30081", "FLYTE_AWS_ENDPOINT=http://localhost:30084"} Source = "/root" @@ -179,3 +179,8 @@ func InspectExecResp(ctx context.Context, cli Docker, containerID string) error } return nil } + +// GetSandboxImage will return the sandbox image with tag +func GetSandboxImage(tag string) string { + return fmt.Sprintf("%s:%s", ImageName, tag) +} diff --git a/flytectl/pkg/util/githubutil/githubutil.go b/flytectl/pkg/util/githubutil/githubutil.go index c3ed9b8b52..ba51c160db 100644 --- a/flytectl/pkg/util/githubutil/githubutil.go +++ b/flytectl/pkg/util/githubutil/githubutil.go @@ -2,6 +2,7 @@ package githubutil import ( "context" + "net/http" "path/filepath" "runtime" "strings" @@ -14,7 +15,6 @@ import ( "github.com/flyteorg/flytectl/pkg/util" "fmt" - "io/ioutil" "github.com/google/go-github/v37/github" ) @@ -47,9 +47,14 @@ var ( arch = platformutil.Arch(runtime.GOARCH) ) +//GetGHClient will return github client +func GetGHClient() *github.Client { + return github.NewClient(&http.Client{}) +} + // GetLatestVersion returns the latest version of provided repository func GetLatestVersion(repository string) (*github.RepositoryRelease, error) { - client := github.NewClient(nil) + client := GetGHClient() release, _, err := client.Repositories.GetLatestRelease(context.Background(), owner, repository) if err != nil { return nil, err @@ -68,7 +73,7 @@ func getFlytectlAssetName() string { // CheckVersionExist returns the provided version release if version exist in repository func CheckVersionExist(version, repository string) (*github.RepositoryRelease, error) { - client := github.NewClient(nil) + client := GetGHClient() release, _, err := client.Repositories.GetReleaseByTag(context.Background(), owner, repository, version) if err != nil { return nil, err @@ -76,6 +81,16 @@ func CheckVersionExist(version, repository string) (*github.RepositoryRelease, e return release, err } +// GetSHAFromVersion returns sha commit hash against a release +func GetSHAFromVersion(version, repository string) (string, error) { + client := GetGHClient() + sha, _, err := client.Repositories.GetCommitSHA1(context.Background(), owner, repository, version, "") + if err != nil { + return "", err + } + return sha, err +} + // GetAssetsFromRelease returns the asset from github release func GetAssetsFromRelease(version, assets, repository string) (*github.ReleaseAsset, error) { release, err := CheckVersionExist(version, repository) @@ -90,28 +105,6 @@ func GetAssetsFromRelease(version, assets, repository string) (*github.ReleaseAs return nil, fmt.Errorf("assest is not found in %s[%s] release", repository, version) } -// GetFlyteManifest will write the flyte manifest in a file -func GetFlyteManifest(version string, target string) error { - asset, err := GetAssetsFromRelease(version, sandboxManifest, flyte) - if err != nil { - return err - } - response, err := util.SendRequest("GET", asset.GetBrowserDownloadURL(), nil) - if err != nil { - return err - } - defer response.Body.Close() - data, err := ioutil.ReadAll(response.Body) - if err != nil { - return err - } - if err := util.WriteIntoFile(data, target); err != nil { - return err - } - return nil - -} - // GetUpgradeMessage return the upgrade message func GetUpgradeMessage(latest string, goos platformutil.Platform) (string, error) { isGreater, err := util.IsVersionGreaterThan(latest, stdlibversion.Version) diff --git a/flytectl/pkg/util/githubutil/githubutil_test.go b/flytectl/pkg/util/githubutil/githubutil_test.go index 05566121b9..2f2eb64345 100644 --- a/flytectl/pkg/util/githubutil/githubutil_test.go +++ b/flytectl/pkg/util/githubutil/githubutil_test.go @@ -42,6 +42,18 @@ func TestCheckVersionExist(t *testing.T) { }) } +func TestGetSHAFromVersion(t *testing.T) { + t.Run("Invalid Tag", func(t *testing.T) { + _, err := GetSHAFromVersion("v100.0.0", "flyte") + assert.NotNil(t, err) + }) + t.Run("Valid Tag", func(t *testing.T) { + release, err := GetSHAFromVersion("v0.15.0", "flyte") + assert.Nil(t, err) + assert.Greater(t, len(release), 0) + }) +} + func TestGetAssetsFromRelease(t *testing.T) { t.Run("Successful get assets", func(t *testing.T) { assets, err := GetAssetsFromRelease("v0.15.0", sandboxManifest, flyte) @@ -62,21 +74,6 @@ func TestGetAssetsFromRelease(t *testing.T) { }) } -func TestGetFlyteManifest(t *testing.T) { - t.Run("Successful get manifest", func(t *testing.T) { - err := GetFlyteManifest("v0.15.0", "test.yaml") - assert.Nil(t, err) - }) - t.Run("Failed get manifest with wrong name", func(t *testing.T) { - err := GetFlyteManifest("v100.15.0", "test.yaml") - assert.NotNil(t, err) - }) - t.Run("Failed get manifest with wrong name", func(t *testing.T) { - err := GetFlyteManifest("v0.12.0", "test.yaml") - assert.NotNil(t, err) - }) -} - func TestGetAssetsName(t *testing.T) { t.Run("Get Assets name", func(t *testing.T) { expected := fmt.Sprintf("flytectl_%s_386.tar.gz", strings.Title(runtime.GOOS))