Add tests for preupgradchecks and spec/archive CLI (#2874)
* Add tests for preupgradchecks * Add spec tests * Add package archive tests * Wait for cleanup * Fix test and coverage --------- Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -76,5 +77,11 @@ type (
|
||||
|
||||
// Duration returns time duration of given flag.
|
||||
Duration(key string) time.Duration
|
||||
|
||||
// Stdout returns io.Writer for stdout.
|
||||
Stdout() io.Writer
|
||||
|
||||
// Stderr returns io.Writer for stderr.
|
||||
Stderr() io.Writer
|
||||
}
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ package cobra
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -311,3 +312,11 @@ func (u Cli) Duration(key string) time.Duration {
|
||||
v, _ := u.c.Flags().GetDuration(key)
|
||||
return v
|
||||
}
|
||||
|
||||
func (u Cli) Stdout() io.Writer {
|
||||
return u.c.OutOrStdout()
|
||||
}
|
||||
|
||||
func (u Cli) Stderr() io.Writer {
|
||||
return u.c.OutOrStderr()
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package dummy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
fCli "github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
@@ -169,3 +171,11 @@ func (u Cli) Duration(key string) time.Duration {
|
||||
}
|
||||
return val.(time.Duration)
|
||||
}
|
||||
|
||||
func (u Cli) Stdout() io.Writer {
|
||||
return os.Stdout
|
||||
}
|
||||
|
||||
func (u Cli) Stderr() io.Writer {
|
||||
return os.Stderr
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Deleted archive with id: %s", archiveID)
|
||||
fmt.Printf("Deleted archive with id: %s\n", archiveID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -66,12 +66,11 @@ func (opts *GetURLSubCommand) do(input cli.Input) error {
|
||||
storageType := resp.Header.Get("X-FISSION-STORAGETYPE")
|
||||
|
||||
if storageType == "local" {
|
||||
storageSvc, err := util.GetSvcName(input.Context(), opts.Client().KubernetesClient, "fission-storage")
|
||||
storagesvcURL, err := util.GetStorageURL(input.Context(), opts.Client())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
storagesvcURL := "http://" + storageSvc
|
||||
client := storagesvcClient.MakeClient(storagesvcURL)
|
||||
client := storagesvcClient.MakeClient(storagesvcURL.String())
|
||||
fmt.Printf("URL: %s", client.GetUrl(archiveID))
|
||||
} else if storageType == "s3" {
|
||||
storageBucket := resp.Header.Get("X-FISSION-BUCKET")
|
||||
|
||||
@@ -49,7 +49,6 @@ func (opts *UploadSubCommand) do(input cli.Input) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("File successfully uploaded with ID: %s ", archiveID)
|
||||
|
||||
fmt.Fprintf(input.Stdout(), "File successfully uploaded with ID: %s\n", archiveID)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -124,15 +124,6 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
// For Specs, the spec validate checks for function reference
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
|
||||
htTrigger, err := opts.Client().FissionClientSet.CoreV1().HTTPTriggers(m.Namespace).Get(input.Context(), m.Name, metav1.GetOptions{})
|
||||
if err != nil && !kerrors.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
if htTrigger.Name != "" && htTrigger.Namespace != "" {
|
||||
return errors.New("duplicate trigger exists, choose a different name or leave it empty for fission to auto-generate it")
|
||||
}
|
||||
|
||||
specDir := util.GetSpecDir(input)
|
||||
specIgnore := util.GetSpecIgnore(input)
|
||||
fr, err := spec.ReadSpecs(specDir, specIgnore, false)
|
||||
|
||||
@@ -51,7 +51,6 @@ func UploadArchiveFile(ctx context.Context, client cmd.Client, fileName string)
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
|
||||
storagesvcURL, err := util.GetStorageURL(ctx, client)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error getting fission storage service URL")
|
||||
@@ -105,12 +104,11 @@ func getArchiveURL(ctx context.Context, client cmd.Client, archiveID string, ser
|
||||
storageType := resp.Header.Get("X-FISSION-STORAGETYPE")
|
||||
|
||||
if storageType == "local" {
|
||||
storageSvc, err := util.GetSvcName(ctx, client.KubernetesClient, "fission-storage")
|
||||
storagesvcURL, err := util.GetStorageURL(ctx, client)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
storagesvcURL := "http://" + storageSvc
|
||||
client := storageSvcClient.MakeClient(storagesvcURL)
|
||||
client := storageSvcClient.MakeClient(storagesvcURL.String())
|
||||
return client.GetUrl(archiveID), nil
|
||||
} else if storageType == "s3" {
|
||||
storageBucket := resp.Header.Get("X-FISSION-BUCKET")
|
||||
@@ -166,23 +164,19 @@ func DownloadURL(fileUrl string) (io.ReadCloser, error) {
|
||||
|
||||
func DownloadStrorageURL(ctx context.Context, client cmd.Client, fileUrl string) (io.ReadCloser, error) {
|
||||
var resp *http.Response
|
||||
storageSvc, err := util.GetSvcName(ctx, client.KubernetesClient, "fission-storage")
|
||||
storagesvcURL, err := util.GetStorageURL(ctx, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if strings.HasPrefix(fileUrl, "http://"+storageSvc+"/v1/archive?id=") {
|
||||
if strings.HasPrefix(fileUrl, storagesvcURL.String()+"/v1/archive?id=") {
|
||||
url, err := url.Parse(fileUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := url.Query().Get("id")
|
||||
storageAccessURL, err := util.GetStorageURL(ctx, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := storageSvcClient.MakeClient(storageAccessURL.String())
|
||||
client := storageSvcClient.MakeClient(storagesvcURL.String())
|
||||
resp, err = client.GetFile(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -448,6 +448,10 @@ func ApplyLabelsAndAnnotations(input cli.Input, objectMeta *metav1.ObjectMeta) e
|
||||
}
|
||||
|
||||
func GetStorageURL(ctx context.Context, client cmd.Client) (*url.URL, error) {
|
||||
storagesvcURL := os.Getenv("FISSION_STORAGESVC_URL")
|
||||
if len(storagesvcURL) > 0 {
|
||||
return url.Parse(storagesvcURL)
|
||||
}
|
||||
storageLocalPort, err := SetupPortForward(ctx, client, GetFissionNamespace(), "application=fission-storage")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -507,28 +511,6 @@ func ConfigMapExists(ctx context.Context, m *metav1.ObjectMeta, kClient kubernet
|
||||
return err
|
||||
}
|
||||
|
||||
func GetSvcName(ctx context.Context, kClient kubernetes.Interface, application string) (string, error) {
|
||||
var podNamespace = os.Getenv("POD_NAMESPACE")
|
||||
if podNamespace == "" {
|
||||
podNamespace = "fission"
|
||||
}
|
||||
|
||||
appLabelSelector := "application=" + application
|
||||
|
||||
services, err := kClient.CoreV1().Services(podNamespace).List(ctx, metav1.ListOptions{
|
||||
LabelSelector: appLabelSelector,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(services.Items) > 1 || len(services.Items) == 0 {
|
||||
return "", errors.Errorf("more than one service found for application=%s", application)
|
||||
}
|
||||
service := services.Items[0]
|
||||
return service.Name + "." + podNamespace, nil
|
||||
}
|
||||
|
||||
// FunctionPodLogs : Get logs for a function directly from pod
|
||||
func FunctionPodLogs(ctx context.Context, fnName, ns string, client cmd.Client) (err error) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user