Fix CLI pkg getsrc returns deploy archive instead of source archive (#2941)

* CLI command `pkg getsrc` returns deploy archive

```
Fix CLI command to return source archive instead of deploy archive.
If source archive is not available then return deploy archive.
```

* Add e2e tests for `fission package` CLI commands
* Cleanup environments created for pkg test
* Fix unit test failures


---------

Signed-off-by: Md Soharab Ansari <soharab.ansari@infracloud.io>
This commit is contained in:
soharab-ic
2024-05-16 18:29:58 +05:30
committed by GitHub
parent 9cea0d2b32
commit 8bfe2d0ed1
3 changed files with 86 additions and 10 deletions
+11 -10
View File
@@ -29,10 +29,7 @@ import (
"github.com/fission/fission/pkg/fission-cli/cmd"
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
)
const (
deployArchive = iota
"github.com/fission/fission/pkg/fission-cli/util"
)
type GetSubCommand struct {
@@ -40,15 +37,19 @@ type GetSubCommand struct {
name string
namespace string
output string
archiveType int
archiveType string
}
func GetSrc(input cli.Input) error {
return (&GetSubCommand{}).do(input)
opts := &GetSubCommand{}
opts.archiveType = util.SOURCE_ARCHIVE
return opts.do(input)
}
func GetDeploy(input cli.Input) error {
return (&GetSubCommand{}).do(input)
opts := &GetSubCommand{}
opts.archiveType = util.DEPLOY_ARCHIVE
return opts.do(input)
}
func (opts *GetSubCommand) do(input cli.Input) error {
@@ -78,13 +79,13 @@ func (opts *GetSubCommand) run(input cli.Input) error {
var reader io.Reader
archive := pkg.Spec.Source
if opts.archiveType == deployArchive {
if opts.archiveType == util.DEPLOY_ARCHIVE || archive.Type == "" {
archive = pkg.Spec.Deployment
}
if pkg.Spec.Deployment.Type == fv1.ArchiveTypeLiteral {
if archive.Type == fv1.ArchiveTypeLiteral {
reader = bytes.NewReader(archive.Literal)
} else if pkg.Spec.Deployment.Type == fv1.ArchiveTypeUrl {
} else if archive.Type == fv1.ArchiveTypeUrl {
readCloser, err := pkgutil.DownloadStrorageURL(input.Context(), opts.Client(), archive.URL)
if err != nil {
+2
View File
@@ -24,6 +24,8 @@ const (
FISSION_AUTH_TOKEN = "FISSION_AUTH_TOKEN"
FISSION_STORAGE_URI = "/v1/archive"
FISSION_DEFAULT_NAMESPACE = "fission"
SOURCE_ARCHIVE = "source"
DEPLOY_ARCHIVE = "deploy"
)
const (
+73
View File
@@ -361,6 +361,79 @@ func TestFissionCLI(t *testing.T) {
})
t.Run("package", func(t *testing.T) {
testPkgName := "test-pkg"
envName := "test-env"
envName2 := "test-env-2"
t.Run("create", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "env", "create", "--name", envName, "--image", "fission/python-env")
require.NoError(t, err)
_, err = cli.ExecCommand(f, ctx, "pkg", "create", "--name", testPkgName, "--code", "./hello.js", "--env", envName)
require.NoError(t, err)
pkg, err := fissionClient.CoreV1().Packages(metav1.NamespaceDefault).Get(ctx, testPkgName, metav1.GetOptions{})
require.NoError(t, err)
require.NotNil(t, pkg)
require.Equal(t, testPkgName, pkg.Name)
require.Equal(t, envName, pkg.Spec.Environment.Name)
})
t.Run("list", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "pkg", "list")
require.NoError(t, err)
})
t.Run("info", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "pkg", "info", "--name", testPkgName)
require.NoError(t, err)
})
t.Run("getsrc", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "pkg", "getsrc", "--name", testPkgName)
require.NoError(t, err)
})
t.Run("getdeploy", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "pkg", "getdeploy", "--name", testPkgName)
require.NoError(t, err)
})
t.Run("rebuild", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "pkg", "rebuild", "--name", testPkgName)
require.Error(t, err)
})
t.Run("update", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "env", "create", "--name", envName2, "--image", "fission/python-env:v2")
require.NoError(t, err)
_, err = cli.ExecCommand(f, ctx, "pkg", "update", "--name", testPkgName, "--code", "./hello.js", "--env", envName2)
require.NoError(t, err)
pkg, err := fissionClient.CoreV1().Packages(metav1.NamespaceDefault).Get(ctx, testPkgName, metav1.GetOptions{})
require.NoError(t, err)
require.NotNil(t, pkg)
require.Equal(t, testPkgName, pkg.Name)
require.Equal(t, envName2, pkg.Spec.Environment.Name)
})
t.Run("delete", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "pkg", "delete", "--name", testPkgName)
require.NoError(t, err)
_, err = fissionClient.CoreV1().Packages(metav1.NamespaceDefault).Get(ctx, testPkgName, metav1.GetOptions{})
require.Error(t, err)
_, err = cli.ExecCommand(f, ctx, "env", "delete", "--name", envName)
require.NoError(t, err)
_, err = cli.ExecCommand(f, ctx, "env", "delete", "--name", envName2)
require.NoError(t, err)
})
})
t.Run("check", func(t *testing.T) {
_, err := cli.ExecCommand(f, ctx, "check")
require.NoError(t, err)