Make CLI functions return error instead of fatal out (#1379)
Before this PR, CLI functions fatal out when encountering error instead of returning it. Such behavior makes it hard to reuse the functions nor writing unit tests. This PR aims to make functions return errors instead of error out.
This commit is contained in:
@@ -17,11 +17,16 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
fcli "github.com/fission/fission/pkg/fission-cli"
|
fcli "github.com/fission/fission/pkg/fission-cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fcli.NewCliApp().Run(os.Args)
|
err := fcli.NewCliApp().Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error: %v\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-46
@@ -20,7 +20,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/urfavecli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/urfavecli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/canaryconfig"
|
"github.com/fission/fission/pkg/fission-cli/cmd/canaryconfig"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/environment"
|
"github.com/fission/fission/pkg/fission-cli/cmd/environment"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/function"
|
"github.com/fission/fission/pkg/fission-cli/cmd/function"
|
||||||
@@ -45,24 +43,17 @@ import (
|
|||||||
"github.com/fission/fission/pkg/fission-cli/cmd/support"
|
"github.com/fission/fission/pkg/fission-cli/cmd/support"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/timetrigger"
|
"github.com/fission/fission/pkg/fission-cli/cmd/timetrigger"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/version"
|
"github.com/fission/fission/pkg/fission-cli/cmd/version"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||||
"github.com/fission/fission/pkg/info"
|
"github.com/fission/fission/pkg/info"
|
||||||
"github.com/fission/fission/pkg/plugin"
|
"github.com/fission/fission/pkg/plugin"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cliHook(c *cli.Context) error {
|
func cliHook(c *cli.Context) error {
|
||||||
log.Verbosity = c.Int("verbosity")
|
consolemsg.Verbosity = c.Int("verbosity")
|
||||||
log.Verbose(2, "Verbosity = 2")
|
consolemsg.Verbose(2, "Verbosity = 2")
|
||||||
|
return flagValueParser(c.Args())
|
||||||
err := flagValueParser(c.Args())
|
|
||||||
if err != nil {
|
|
||||||
// The cli package wont't print out error, as a workaround we need to
|
|
||||||
// fatal here instead of return it.
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCliApp() *cli.App {
|
func NewCliApp() *cli.App {
|
||||||
@@ -81,9 +72,9 @@ func NewCliApp() *cli.App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.StringFlag{Name: cmd.FISSION_SERVER, Value: "", Usage: "Fission server URL"},
|
cli.StringFlag{Name: flag.FISSION_SERVER, Value: "", Usage: "Fission server URL"},
|
||||||
cli.IntFlag{Name: cmd.GLOBAL_VERBOSITY, Value: 1, Usage: "CLI verbosity (0 is quiet, 1 is the default, 2 is verbose.)"},
|
cli.IntFlag{Name: flag.GLOBAL_VERBOSITY, Value: 1, Usage: "CLI verbosity (0 is quiet, 1 is the default, 2 is verbose.)"},
|
||||||
cli.BoolFlag{Name: cmd.GLOBAL_PLUGIN, Hidden: true},
|
cli.BoolFlag{Name: flag.GLOBAL_PLUGIN, Hidden: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
// all resource create commands accept --spec
|
// all resource create commands accept --spec
|
||||||
@@ -91,7 +82,7 @@ func NewCliApp() *cli.App {
|
|||||||
|
|
||||||
// namespace reference for all objects
|
// namespace reference for all objects
|
||||||
fnNamespaceFlag := cli.StringFlag{Name: "fnNamespace, fns", Value: metav1.NamespaceDefault, Usage: "Namespace for function object"}
|
fnNamespaceFlag := cli.StringFlag{Name: "fnNamespace, fns", Value: metav1.NamespaceDefault, Usage: "Namespace for function object"}
|
||||||
envNamespaceFlag := cli.StringFlag{Name: cmd.GetCliFlagName(cmd.ENVIRONMENT_NAMESPACE, cmd.ENVIRONMENT_NAMESPACE_ALIAS), Value: metav1.NamespaceDefault, Usage: "Namespace for environment object"}
|
envNamespaceFlag := cli.StringFlag{Name: flag.GetCliFlagName(flag.ENVIRONMENT_NAMESPACE, flag.ENVIRONMENT_NAMESPACE_ALIAS), Value: metav1.NamespaceDefault, Usage: "Namespace for environment object"}
|
||||||
pkgNamespaceFlag := cli.StringFlag{Name: "pkgNamespace, pkgns", Value: metav1.NamespaceDefault, Usage: "Namespace for package object"}
|
pkgNamespaceFlag := cli.StringFlag{Name: "pkgNamespace, pkgns", Value: metav1.NamespaceDefault, Usage: "Namespace for package object"}
|
||||||
triggerNamespaceFlag := cli.StringFlag{Name: "triggerNamespace, triggerns", Value: metav1.NamespaceDefault, Usage: "Namespace for trigger object"}
|
triggerNamespaceFlag := cli.StringFlag{Name: "triggerNamespace, triggerns", Value: metav1.NamespaceDefault, Usage: "Namespace for trigger object"}
|
||||||
recorderNamespaceFlag := cli.StringFlag{Name: "recorderNamespace, recorderns", Value: metav1.NamespaceDefault, Usage: "Namespace for recorder object"}
|
recorderNamespaceFlag := cli.StringFlag{Name: "recorderNamespace, recorderns", Value: metav1.NamespaceDefault, Usage: "Namespace for recorder object"}
|
||||||
@@ -102,13 +93,13 @@ func NewCliApp() *cli.App {
|
|||||||
htUrlFlag := cli.StringFlag{Name: "url", Usage: "URL pattern (See gorilla/mux supported patterns)"}
|
htUrlFlag := cli.StringFlag{Name: "url", Usage: "URL pattern (See gorilla/mux supported patterns)"}
|
||||||
|
|
||||||
// Resource & scale related flags (Used in env and function)
|
// Resource & scale related flags (Used in env and function)
|
||||||
minCpu := cli.IntFlag{Name: cmd.RUNTIME_MINCPU, Usage: "Minimum CPU to be assigned to pod (In millicore, minimum 1)"}
|
minCpu := cli.IntFlag{Name: flag.RUNTIME_MINCPU, Usage: "Minimum CPU to be assigned to pod (In millicore, minimum 1)"}
|
||||||
maxCpu := cli.IntFlag{Name: cmd.RUNTIME_MAXCPU, Usage: "Maximum CPU to be assigned to pod (In millicore, minimum 1)"}
|
maxCpu := cli.IntFlag{Name: flag.RUNTIME_MAXCPU, Usage: "Maximum CPU to be assigned to pod (In millicore, minimum 1)"}
|
||||||
minMem := cli.IntFlag{Name: cmd.RUNTIME_MINMEMORY, Usage: "Minimum memory to be assigned to pod (In megabyte)"}
|
minMem := cli.IntFlag{Name: flag.RUNTIME_MINMEMORY, Usage: "Minimum memory to be assigned to pod (In megabyte)"}
|
||||||
maxMem := cli.IntFlag{Name: cmd.RUNTIME_MAXMEMORY, Usage: "Maximum memory to be assigned to pod (In megabyte)"}
|
maxMem := cli.IntFlag{Name: flag.RUNTIME_MAXMEMORY, Usage: "Maximum memory to be assigned to pod (In megabyte)"}
|
||||||
minScale := cli.IntFlag{Name: cmd.RUNTIME_MINSCALE, Usage: "Minimum number of pods (Uses resource inputs to configure HPA)"}
|
minScale := cli.IntFlag{Name: flag.RUNTIME_MINSCALE, Usage: "Minimum number of pods (Uses resource inputs to configure HPA)"}
|
||||||
maxScale := cli.IntFlag{Name: cmd.RUNTIME_MAXSCALE, Usage: "Maximum number of pods (Uses resource inputs to configure HPA)"}
|
maxScale := cli.IntFlag{Name: flag.RUNTIME_MAXSCALE, Usage: "Maximum number of pods (Uses resource inputs to configure HPA)"}
|
||||||
targetcpu := cli.IntFlag{Name: cmd.RUNTIME_TARGETCPU, Usage: "Target average CPU usage percentage across pods for scaling"}
|
targetcpu := cli.IntFlag{Name: flag.RUNTIME_TARGETCPU, Usage: "Target average CPU usage percentage across pods for scaling"}
|
||||||
specializationTimeoutFlag := cli.IntFlag{Name: "specializationtimeout, st", Value: 120, Usage: "Timeout for newdeploy to wait for function pod creation"}
|
specializationTimeoutFlag := cli.IntFlag{Name: "specializationtimeout, st", Value: 120, Usage: "Timeout for newdeploy to wait for function pod creation"}
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
@@ -230,15 +221,15 @@ func NewCliApp() *cli.App {
|
|||||||
reqIDFlag := cli.StringFlag{Name: "reqUID", Usage: "Replay a particular request by providing the reqUID (to view reqUIDs, do 'fission records view')"}
|
reqIDFlag := cli.StringFlag{Name: "reqUID", Usage: "Replay a particular request by providing the reqUID (to view reqUIDs, do 'fission records view')"}
|
||||||
|
|
||||||
// environments
|
// environments
|
||||||
envNameFlag := cli.StringFlag{Name: cmd.RESOURCE_NAME, Usage: "Environment name"}
|
envNameFlag := cli.StringFlag{Name: flag.RESOURCE_NAME, Usage: "Environment name"}
|
||||||
envPoolsizeFlag := cli.IntFlag{Name: cmd.ENVIRONMENT_POOLSIZE, Value: 3, Usage: "Size of the pool"}
|
envPoolsizeFlag := cli.IntFlag{Name: flag.ENVIRONMENT_POOLSIZE, Value: 3, Usage: "Size of the pool"}
|
||||||
envImageFlag := cli.StringFlag{Name: cmd.ENVIRONMENT_IMAGE, Usage: "Environment image URL"}
|
envImageFlag := cli.StringFlag{Name: flag.ENVIRONMENT_IMAGE, Usage: "Environment image URL"}
|
||||||
envBuilderImageFlag := cli.StringFlag{Name: cmd.ENVIRONMENT_BUILDER, Usage: "Environment builder image URL (optional)"}
|
envBuilderImageFlag := cli.StringFlag{Name: flag.ENVIRONMENT_BUILDER, Usage: "Environment builder image URL (optional)"}
|
||||||
envBuildCmdFlag := cli.StringFlag{Name: cmd.ENVIRONMENT_BUILDCOMMAND, Usage: "Build command for environment builder to build source package (optional)"}
|
envBuildCmdFlag := cli.StringFlag{Name: flag.ENVIRONMENT_BUILDCOMMAND, Usage: "Build command for environment builder to build source package (optional)"}
|
||||||
envKeepArchiveFlag := cli.BoolFlag{Name: cmd.ENVIRONMENT_KEEPARCHIVE, Usage: "Keep the archive instead of extracting it into a directory (optional, defaults to false)"}
|
envKeepArchiveFlag := cli.BoolFlag{Name: flag.ENVIRONMENT_KEEPARCHIVE, Usage: "Keep the archive instead of extracting it into a directory (optional, defaults to false)"}
|
||||||
envExternalNetworkFlag := cli.BoolFlag{Name: cmd.ENVIRONMENT_EXTERNAL_NETWORK, Usage: "Allow environment access external network when istio feature enabled (optional, defaults to false)"}
|
envExternalNetworkFlag := cli.BoolFlag{Name: flag.ENVIRONMENT_EXTERNAL_NETWORK, Usage: "Allow environment access external network when istio feature enabled (optional, defaults to false)"}
|
||||||
envTerminationGracePeriodFlag := cli.Int64Flag{Name: cmd.GetCliFlagName(cmd.ENVIRONMENT_GRACE_PERIOD, cmd.ENVIRONMENT_GRACE_PERIOD_ALIAS), Value: 360, Usage: "The grace time (in seconds) for pod to perform connection draining before termination (optional)"}
|
envTerminationGracePeriodFlag := cli.Int64Flag{Name: flag.GetCliFlagName(flag.ENVIRONMENT_GRACE_PERIOD, flag.ENVIRONMENT_GRACE_PERIOD_ALIAS), Value: 360, Usage: "The grace time (in seconds) for pod to perform connection draining before termination (optional)"}
|
||||||
envVersionFlag := cli.IntFlag{Name: cmd.ENVIRONMENT_VERSION, Value: 1, Usage: "Environment API version (1 means v1 interface)"}
|
envVersionFlag := cli.IntFlag{Name: flag.ENVIRONMENT_VERSION, Value: 1, Usage: "Environment API version (1 means v1 interface)"}
|
||||||
envSubcommands := []cli.Command{
|
envSubcommands := []cli.Command{
|
||||||
{Name: "create", Aliases: []string{"add"}, Usage: "Add an environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag, envPoolsizeFlag, envImageFlag, envBuilderImageFlag, envBuildCmdFlag, envKeepArchiveFlag, minCpu, maxCpu, minMem, maxMem, envVersionFlag, envExternalNetworkFlag, envTerminationGracePeriodFlag, specSaveFlag}, Action: urfavecli.Wrapper(environment.Create)},
|
{Name: "create", Aliases: []string{"add"}, Usage: "Add an environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag, envPoolsizeFlag, envImageFlag, envBuilderImageFlag, envBuildCmdFlag, envKeepArchiveFlag, minCpu, maxCpu, minMem, maxMem, envVersionFlag, envExternalNetworkFlag, envTerminationGracePeriodFlag, specSaveFlag}, Action: urfavecli.Wrapper(environment.Create)},
|
||||||
{Name: "get", Usage: "Get environment details", Flags: []cli.Flag{envNameFlag, envNamespaceFlag}, Action: urfavecli.Wrapper(environment.Get)},
|
{Name: "get", Usage: "Get environment details", Flags: []cli.Flag{envNameFlag, envNamespaceFlag}, Action: urfavecli.Wrapper(environment.Get)},
|
||||||
@@ -353,39 +344,37 @@ func handleNoCommand(ctx *cli.Context) error {
|
|||||||
Usage: ctx.App.Usage,
|
Usage: ctx.App.Usage,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Failed to marshal plugin metadata to JSON: %v", err))
|
return errors.Errorf("Failed to marshal plugin metadata to JSON: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Println(string(bs))
|
fmt.Println(string(bs))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(ctx.Args()) > 0 {
|
if len(ctx.Args()) > 0 {
|
||||||
handleCommandNotFound(ctx, ctx.Args().First())
|
return handleCommandNotFound(ctx, ctx.Args().First())
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cli.ShowAppHelp(ctx)
|
return cli.ShowAppHelp(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCommandNotFound(ctx *cli.Context, subCommand string) {
|
func handleCommandNotFound(ctx *cli.Context, subCommand string) error {
|
||||||
pmd, err := plugin.Find(subCommand)
|
pmd, err := plugin.Find(subCommand)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err {
|
switch err {
|
||||||
case plugin.ErrPluginNotFound:
|
case plugin.ErrPluginNotFound:
|
||||||
url, ok := plugin.SearchRegistries(subCommand)
|
url, ok := plugin.SearchRegistries(subCommand)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("No help topic for '" + subCommand + "'")
|
return errors.New("No help topic for '" + subCommand + "'")
|
||||||
}
|
}
|
||||||
log.Fatal(fmt.Sprintf(`Command '%v' is not installed.
|
return errors.Errorf(`Command '%v' is not installed.
|
||||||
It is available to download at '%v'.
|
It is available to download at '%v'.
|
||||||
|
|
||||||
To install it for your local Fission CLI:
|
To install it for your local Fission CLI:
|
||||||
1. Download the plugin binary for your OS from the URL
|
1. Download the plugin binary for your OS from the URL
|
||||||
2. Ensure that the plugin binary is executable: chmod +x <binary>
|
2. Ensure that the plugin binary is executable: chmod +x <binary>
|
||||||
2. Add the plugin binary to your $PATH: mv <binary> /usr/local/bin/fission-%v`, subCommand, url, subCommand))
|
2. Add the plugin binary to your $PATH: mv <binary> /usr/local/bin/fission-%v`, subCommand, url, subCommand)
|
||||||
default:
|
default:
|
||||||
log.Fatal("Error occurred when invoking " + subCommand + ": " + err.Error())
|
return errors.Wrap(err, "Error occurred when invoking "+subCommand)
|
||||||
}
|
}
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebuild global arguments string (urfave/cli does not have an option to get the raw input of the global flags)
|
// Rebuild global arguments string (urfave/cli does not have an option to get the raw input of the global flags)
|
||||||
@@ -403,8 +392,10 @@ To install it for your local Fission CLI:
|
|||||||
|
|
||||||
err = plugin.Exec(pmd, args)
|
err = plugin.Exec(pmd, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func flagValueParser(args []string) error {
|
func flagValueParser(args []string) error {
|
||||||
@@ -442,8 +433,7 @@ func flagValueParser(args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(errorFlags) > 0 {
|
if len(errorFlags) > 0 {
|
||||||
e := fmt.Sprintf("Unable to parse flags: %v\nThe argument should have only one input value. Please quote the input value if it contains wildcard characters(*).", strings.Join(errorFlags[:], ", "))
|
return errors.Errorf("Unable to parse flags: %v\nThe argument should have only one input value. Please quote the input value if it contains wildcard characters(*).", strings.Join(errorFlags[:], ", "))
|
||||||
return errors.New(e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package urfavecli
|
package urfavecli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@@ -39,13 +38,7 @@ func Parse(c *cli.Context) fCli.Input {
|
|||||||
|
|
||||||
func Wrapper(action cmd.CommandAction) func(*cli.Context) error {
|
func Wrapper(action cmd.CommandAction) func(*cli.Context) error {
|
||||||
return func(c *cli.Context) error {
|
return func(c *cli.Context) error {
|
||||||
e := action(Cli{c: c})
|
return action(Cli{c: c})
|
||||||
// Urfave cli doesn't exit with error code even error is not nil.
|
|
||||||
// We have to check whether error is empty and print error log here.
|
|
||||||
if e != nil {
|
|
||||||
log.Fatalf("%v", e)
|
|
||||||
}
|
|
||||||
return e
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
@@ -36,8 +35,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -68,7 +71,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check that the trigger exists in the same namespace.
|
// check that the trigger exists in the same namespace.
|
||||||
m, err := cmd.GetMetadata("httptrigger", "fnNamespace", flags)
|
m, err := util.GetMetadata("httptrigger", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error finding http trigger in given namespace")
|
return errors.Wrap(err, "error finding http trigger in given namespace")
|
||||||
}
|
}
|
||||||
@@ -101,7 +104,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
return errors.Wrap(err, "error checking functions existence")
|
return errors.Wrap(err, "error checking functions existence")
|
||||||
}
|
}
|
||||||
|
|
||||||
canaryMetadata, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
canaryMetadata, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -31,14 +31,18 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.run(flags)
|
return opts.run(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *DeleteSubCommand) run(flags cli.Input) error {
|
func (opts *DeleteSubCommand) run(flags cli.Input) error {
|
||||||
metadata, err := cmd.GetMetadata("name", "canaryNamespace", flags)
|
metadata, err := util.GetMetadata("name", "canaryNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSubCommand struct {
|
type GetSubCommand struct {
|
||||||
@@ -33,14 +33,18 @@ type GetSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Get(flags cli.Input) error {
|
func Get(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetSubCommand{
|
opts := GetSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.run(flags)
|
return opts.run(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *GetSubCommand) run(flags cli.Input) error {
|
func (opts *GetSubCommand) run(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "canaryNamespace", flags)
|
m, err := util.GetMetadata("name", "canaryNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListSubCommand struct {
|
type ListSubCommand struct {
|
||||||
@@ -34,8 +34,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateSubCommand struct {
|
type UpdateSubCommand struct {
|
||||||
@@ -34,8 +34,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -50,7 +54,7 @@ func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
|||||||
|
|
||||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||||
// get the current config
|
// get the current config
|
||||||
m, err := cmd.GetMetadata("name", "canaryNamespace", flags)
|
m, err := util.GetMetadata("name", "canaryNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,8 +38,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -65,7 +69,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
// run write the resource to a spec file or create a fission CRD with remote fission server.
|
// run write the resource to a spec file or create a fission CRD with remote fission server.
|
||||||
// It also prints warning/error if necessary.
|
// It also prints warning/error if necessary.
|
||||||
func (opts *CreateSubCommand) run(flags cli.Input) error {
|
func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata(cmd.RESOURCE_NAME, cmd.ENVIRONMENT_NAMESPACE, flags)
|
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -73,22 +77,26 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if len(envList) > 0 {
|
} else if len(envList) > 0 {
|
||||||
log.Verbose(2, "%d environment(s) are present in the %s namespace. "+
|
consolemsg.Verbose(2, "%d environment(s) are present in the %s namespace. "+
|
||||||
"These environments are not isolated from each other; use separate namespaces if you need isolation.",
|
"These environments are not isolated from each other; use separate namespaces if you need isolation.",
|
||||||
len(envList), m.Namespace)
|
len(envList), m.Namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're writing a spec, don't call the API
|
// if we're writing a spec, don't call the API
|
||||||
// save to spec file
|
// save to spec file
|
||||||
if flags.Bool(cmd.SPEC_SPEC) {
|
if flags.Bool(flag.SPEC_SPEC) {
|
||||||
specFile := fmt.Sprintf("env-%v.yaml", m.Name)
|
specFile := fmt.Sprintf("env-%v.yaml", m.Name)
|
||||||
err = spec.SpecSave(*opts.env, specFile)
|
err = spec.SpecSave(*opts.env, specFile)
|
||||||
util.CheckErr(err, "create environment spec")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating environment spec")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = opts.client.EnvironmentCreate(opts.env)
|
_, err = opts.client.EnvironmentCreate(opts.env)
|
||||||
util.CheckErr(err, "create environment")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating environment")
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("environment '%v' created\n", m.Name)
|
fmt.Printf("environment '%v' created\n", m.Name)
|
||||||
return nil
|
return nil
|
||||||
@@ -98,36 +106,36 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
|
|||||||
func createEnvironmentFromCmd(flags cli.Input) (*fv1.Environment, error) {
|
func createEnvironmentFromCmd(flags cli.Input) (*fv1.Environment, error) {
|
||||||
e := &multierror.Error{}
|
e := &multierror.Error{}
|
||||||
|
|
||||||
envNamespace := flags.String(cmd.ENVIRONMENT_NAMESPACE)
|
envNamespace := flags.String(flag.ENVIRONMENT_NAMESPACE)
|
||||||
envBuildCmd := flags.String(cmd.ENVIRONMENT_BUILDCOMMAND)
|
envBuildCmd := flags.String(flag.ENVIRONMENT_BUILDCOMMAND)
|
||||||
envExternalNetwork := flags.Bool(cmd.ENVIRONMENT_EXTERNAL_NETWORK)
|
envExternalNetwork := flags.Bool(flag.ENVIRONMENT_EXTERNAL_NETWORK)
|
||||||
keepArchive := flags.Bool(cmd.ENVIRONMENT_KEEPARCHIVE)
|
keepArchive := flags.Bool(flag.ENVIRONMENT_KEEPARCHIVE)
|
||||||
|
|
||||||
envName := flags.String(cmd.RESOURCE_NAME)
|
envName := flags.String(flag.RESOURCE_NAME)
|
||||||
if len(envName) == 0 {
|
if len(envName) == 0 {
|
||||||
e = multierror.Append(e, errors.New("Need a name, use --name."))
|
e = multierror.Append(e, errors.New("Need a name, use --name."))
|
||||||
}
|
}
|
||||||
|
|
||||||
envImg := flags.String(cmd.ENVIRONMENT_IMAGE)
|
envImg := flags.String(flag.ENVIRONMENT_IMAGE)
|
||||||
if len(envImg) == 0 {
|
if len(envImg) == 0 {
|
||||||
e = multierror.Append(e, errors.New("Need an image, use --image."))
|
e = multierror.Append(e, errors.New("Need an image, use --image."))
|
||||||
}
|
}
|
||||||
|
|
||||||
envGracePeriod := flags.Int64(cmd.ENVIRONMENT_GRACE_PERIOD)
|
envGracePeriod := flags.Int64(flag.ENVIRONMENT_GRACE_PERIOD)
|
||||||
if envGracePeriod <= 0 {
|
if envGracePeriod <= 0 {
|
||||||
envGracePeriod = 360
|
envGracePeriod = 360
|
||||||
}
|
}
|
||||||
|
|
||||||
envVersion := flags.Int(cmd.ENVIRONMENT_VERSION)
|
envVersion := flags.Int(flag.ENVIRONMENT_VERSION)
|
||||||
// Environment API interface version is not specified and
|
// Environment API interface version is not specified and
|
||||||
// builder image is empty, set default interface version
|
// builder image is empty, set default interface version
|
||||||
if envVersion == 0 {
|
if envVersion == 0 {
|
||||||
envVersion = 1
|
envVersion = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
envBuilderImg := flags.String(cmd.ENVIRONMENT_BUILDER)
|
envBuilderImg := flags.String(flag.ENVIRONMENT_BUILDER)
|
||||||
if len(envBuilderImg) > 0 {
|
if len(envBuilderImg) > 0 {
|
||||||
if !flags.IsSet(cmd.ENVIRONMENT_VERSION) {
|
if !flags.IsSet(flag.ENVIRONMENT_VERSION) {
|
||||||
// TODO: remove set env version to 2 silently, we need to warn user to set it explicitly.
|
// TODO: remove set env version to 2 silently, we need to warn user to set it explicitly.
|
||||||
envVersion = 2
|
envVersion = 2
|
||||||
}
|
}
|
||||||
@@ -137,13 +145,13 @@ func createEnvironmentFromCmd(flags cli.Input) (*fv1.Environment, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
poolsize := 3
|
poolsize := 3
|
||||||
if flags.IsSet(cmd.ENVIRONMENT_POOLSIZE) {
|
if flags.IsSet(flag.ENVIRONMENT_POOLSIZE) {
|
||||||
poolsize = flags.Int(cmd.ENVIRONMENT_POOLSIZE)
|
poolsize = flags.Int(flag.ENVIRONMENT_POOLSIZE)
|
||||||
// TODO: remove silently version 3 assignment, we need to warn user to set it explicitly.
|
// TODO: remove silently version 3 assignment, we need to warn user to set it explicitly.
|
||||||
envVersion = 3
|
envVersion = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceReq, err := cmd.GetResourceReqs(flags, nil)
|
resourceReq, err := util.GetResourceReqs(flags, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e = multierror.Append(e, err)
|
e = multierror.Append(e, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ package environment
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,20 +32,26 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata(cmd.RESOURCE_NAME, cmd.ENVIRONMENT_NAMESPACE, flags)
|
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = opts.client.EnvironmentDelete(m)
|
err = opts.client.EnvironmentDelete(m)
|
||||||
util.CheckErr(err, "delete environment")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error deleting environment")
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("environment '%v' deleted\n", m.Name)
|
fmt.Printf("environment '%v' deleted\n", m.Name)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,20 +34,26 @@ type GetSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Get(flags cli.Input) error {
|
func Get(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetSubCommand{
|
opts := GetSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *GetSubCommand) do(flags cli.Input) error {
|
func (opts *GetSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata(cmd.RESOURCE_NAME, cmd.ENVIRONMENT_NAMESPACE, flags)
|
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
env, err := opts.client.EnvironmentGet(m)
|
env, err := opts.client.EnvironmentGet(m)
|
||||||
util.CheckErr(err, "get environment")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error getting environment")
|
||||||
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,17 +34,23 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *ListSubCommand) do(flags cli.Input) error {
|
func (opts *ListSubCommand) do(flags cli.Input) error {
|
||||||
envNamespace := flags.String(cmd.ENVIRONMENT_NAMESPACE)
|
envNamespace := flags.String(flag.ENVIRONMENT_NAMESPACE)
|
||||||
|
|
||||||
envs, err := opts.client.EnvironmentList(envNamespace)
|
envs, err := opts.client.EnvironmentList(envNamespace)
|
||||||
util.CheckErr(err, "list environments")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error listing environments")
|
||||||
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "IMAGE", "BUILDER_IMAGE", "POOLSIZE", "MINCPU", "MAXCPU", "MINMEMORY", "MAXMEMORY", "EXTNET", "GRACETIME")
|
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "IMAGE", "BUILDER_IMAGE", "POOLSIZE", "MINCPU", "MAXCPU", "MINMEMORY", "MAXMEMORY", "EXTNET", "GRACETIME")
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ limitations under the License.
|
|||||||
package environment
|
package environment
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,8 +35,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -50,13 +54,15 @@ func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata(cmd.RESOURCE_NAME, cmd.ENVIRONMENT_NAMESPACE, flags)
|
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
env, err := opts.client.EnvironmentGet(m)
|
env, err := opts.client.EnvironmentGet(m)
|
||||||
util.CheckErr(err, "find environment")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error finding environment")
|
||||||
|
}
|
||||||
|
|
||||||
env, err = updateExistingEnvironmentWithCmd(env, flags)
|
env, err = updateExistingEnvironmentWithCmd(env, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,7 +75,9 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
|
|
||||||
func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
||||||
_, err := opts.client.EnvironmentUpdate(opts.env)
|
_, err := opts.client.EnvironmentUpdate(opts.env)
|
||||||
util.CheckErr(err, "update environment")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error updating environment")
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("environment '%v' updated\n", opts.env.Metadata.Name)
|
fmt.Printf("environment '%v' updated\n", opts.env.Metadata.Name)
|
||||||
return nil
|
return nil
|
||||||
@@ -79,10 +87,10 @@ func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
|||||||
func updateExistingEnvironmentWithCmd(env *fv1.Environment, flags cli.Input) (*fv1.Environment, error) {
|
func updateExistingEnvironmentWithCmd(env *fv1.Environment, flags cli.Input) (*fv1.Environment, error) {
|
||||||
e := &multierror.Error{}
|
e := &multierror.Error{}
|
||||||
|
|
||||||
envImg := flags.String(cmd.ENVIRONMENT_IMAGE)
|
envImg := flags.String(flag.ENVIRONMENT_IMAGE)
|
||||||
envBuilderImg := flags.String(cmd.ENVIRONMENT_BUILDER)
|
envBuilderImg := flags.String(flag.ENVIRONMENT_BUILDER)
|
||||||
envBuildCmd := flags.String(cmd.ENVIRONMENT_BUILDCOMMAND)
|
envBuildCmd := flags.String(flag.ENVIRONMENT_BUILDCOMMAND)
|
||||||
envExternalNetwork := flags.Bool(cmd.ENVIRONMENT_EXTERNAL_NETWORK)
|
envExternalNetwork := flags.Bool(flag.ENVIRONMENT_EXTERNAL_NETWORK)
|
||||||
|
|
||||||
if len(envImg) == 0 && len(envBuilderImg) == 0 && len(envBuildCmd) == 0 {
|
if len(envImg) == 0 && len(envBuilderImg) == 0 && len(envBuildCmd) == 0 {
|
||||||
e = multierror.Append(e, errors.New("need --image to specify env image, or use --builder to specify env builder, or use --buildcmd to specify new build command"))
|
e = multierror.Append(e, errors.New("need --image to specify env image, or use --builder to specify env builder, or use --buildcmd to specify new build command"))
|
||||||
@@ -103,23 +111,23 @@ func updateExistingEnvironmentWithCmd(env *fv1.Environment, flags cli.Input) (*f
|
|||||||
env.Spec.Builder.Command = envBuildCmd
|
env.Spec.Builder.Command = envBuildCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.IsSet(cmd.ENVIRONMENT_POOLSIZE) {
|
if flags.IsSet(flag.ENVIRONMENT_POOLSIZE) {
|
||||||
env.Spec.Poolsize = flags.Int(cmd.ENVIRONMENT_POOLSIZE)
|
env.Spec.Poolsize = flags.Int(flag.ENVIRONMENT_POOLSIZE)
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.IsSet(cmd.ENVIRONMENT_GRACE_PERIOD) {
|
if flags.IsSet(flag.ENVIRONMENT_GRACE_PERIOD) {
|
||||||
env.Spec.TerminationGracePeriod = flags.Int64(cmd.ENVIRONMENT_GRACE_PERIOD)
|
env.Spec.TerminationGracePeriod = flags.Int64(flag.ENVIRONMENT_GRACE_PERIOD)
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.IsSet(cmd.ENVIRONMENT_KEEPARCHIVE) {
|
if flags.IsSet(flag.ENVIRONMENT_KEEPARCHIVE) {
|
||||||
env.Spec.KeepArchive = flags.Bool(cmd.ENVIRONMENT_KEEPARCHIVE)
|
env.Spec.KeepArchive = flags.Bool(flag.ENVIRONMENT_KEEPARCHIVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
env.Spec.AllowAccessToExternalNetwork = envExternalNetwork
|
env.Spec.AllowAccessToExternalNetwork = envExternalNetwork
|
||||||
|
|
||||||
if flags.IsSet(cmd.RUNTIME_MINCPU) || flags.IsSet(cmd.RUNTIME_MAXCPU) ||
|
if flags.IsSet(flag.RUNTIME_MINCPU) || flags.IsSet(flag.RUNTIME_MAXCPU) ||
|
||||||
flags.IsSet(cmd.RUNTIME_MINMEMORY) || flags.IsSet(cmd.RUNTIME_MAXMEMORY) ||
|
flags.IsSet(flag.RUNTIME_MINMEMORY) || flags.IsSet(flag.RUNTIME_MAXMEMORY) ||
|
||||||
flags.IsSet(cmd.RUNTIME_MINSCALE) || flags.IsSet(cmd.RUNTIME_MAXSCALE) {
|
flags.IsSet(flag.RUNTIME_MINSCALE) || flags.IsSet(flag.RUNTIME_MAXSCALE) {
|
||||||
e = multierror.Append(e, errors.New("updating resource limits/requests for existing environments is currently unsupported; re-create the environment instead"))
|
e = multierror.Append(e, errors.New("updating resource limits/requests for existing environments is currently unsupported; re-create the environment instead"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ import (
|
|||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
ferror "github.com/fission/fission/pkg/error"
|
ferror "github.com/fission/fission/pkg/error"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
||||||
_package "github.com/fission/fission/pkg/fission-cli/cmd/package"
|
_package "github.com/fission/fission/pkg/fission-cli/cmd/package"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,8 +50,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -79,10 +83,10 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
toSpec = true
|
toSpec = true
|
||||||
opts.specFile = fmt.Sprintf("function-%v.yaml", fnName)
|
opts.specFile = fmt.Sprintf("function-%v.yaml", fnName)
|
||||||
}
|
}
|
||||||
specDir := cmd.GetSpecDir(flags)
|
specDir := util.GetSpecDir(flags)
|
||||||
|
|
||||||
// check for unique function names within a namespace
|
// check for unique function names within a namespace
|
||||||
metadata, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
metadata, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -110,7 +114,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
resourceReq, err := cmd.GetResourceReqs(flags, &apiv1.ResourceRequirements{})
|
resourceReq, err := util.GetResourceReqs(flags, &apiv1.ResourceRequirements{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -129,7 +133,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
pkgMetadata = &pkg.Metadata
|
pkgMetadata = &pkg.Metadata
|
||||||
envName = pkg.Spec.Environment.Name
|
envName = pkg.Spec.Environment.Name
|
||||||
if envName != flags.String("env") {
|
if envName != flags.String("env") {
|
||||||
log.Warn("Function's environment is different than package's environment, package's environment will be used for creating function")
|
consolemsg.Warn("Function's environment is different than package's environment, package's environment will be used for creating function")
|
||||||
}
|
}
|
||||||
envNamespace = pkg.Spec.Environment.Namespace
|
envNamespace = pkg.Spec.Environment.Namespace
|
||||||
} else {
|
} else {
|
||||||
@@ -147,7 +151,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNotFound {
|
if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNotFound {
|
||||||
log.Warn(fmt.Sprintf("Environment \"%v\" does not exist. Please create the environment before executing the function. \nFor example: `fission env create --name %v --envns %v --image <image>`\n", envName, envName, envNamespace))
|
consolemsg.Warn(fmt.Sprintf("Environment \"%v\" does not exist. Please create the environment before executing the function. \nFor example: `fission env create --name %v --envns %v --image <image>`\n", envName, envName, envNamespace))
|
||||||
} else {
|
} else {
|
||||||
return errors.Wrap(err, "error retrieving environment information")
|
return errors.Wrap(err, "error retrieving environment information")
|
||||||
}
|
}
|
||||||
@@ -192,7 +196,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
log.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
consolemsg.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||||
} else {
|
} else {
|
||||||
return errors.Wrap(err, "error checking secret")
|
return errors.Wrap(err, "error checking secret")
|
||||||
}
|
}
|
||||||
@@ -216,7 +220,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
log.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
consolemsg.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
||||||
} else {
|
} else {
|
||||||
return errors.Wrap(err, "error checking configmap")
|
return errors.Wrap(err, "error checking configmap")
|
||||||
}
|
}
|
||||||
@@ -353,7 +357,7 @@ func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrate
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flags.IsSet("mincpu") || flags.IsSet("maxcpu") || flags.IsSet("minmemory") || flags.IsSet("maxmemory") {
|
if flags.IsSet("mincpu") || flags.IsSet("maxcpu") || flags.IsSet("minmemory") || flags.IsSet("maxmemory") {
|
||||||
log.Warn("To limit CPU/Memory for function with executor type \"poolmgr\", please specify resources limits when creating environment")
|
consolemsg.Warn("To limit CPU/Memory for function with executor type \"poolmgr\", please specify resources limits when creating environment")
|
||||||
}
|
}
|
||||||
strategy = &fv1.InvokeStrategy{
|
strategy = &fv1.InvokeStrategy{
|
||||||
StrategyType: fv1.StrategyTypeExecution,
|
StrategyType: fv1.StrategyTypeExecution,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -31,14 +31,18 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSubCommand struct {
|
type GetSubCommand struct {
|
||||||
@@ -32,14 +32,18 @@ type GetSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Get(flags cli.Input) error {
|
func Get(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetSubCommand{
|
opts := GetSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *GetSubCommand) do(flags cli.Input) error {
|
func (opts *GetSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetMetaSubCommand struct {
|
type GetMetaSubCommand struct {
|
||||||
@@ -33,14 +33,18 @@ type GetMetaSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetMeta(flags cli.Input) error {
|
func GetMeta(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetMetaSubCommand{
|
opts := GetMetaSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *GetMetaSubCommand) do(flags cli.Input) error {
|
func (opts *GetMetaSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListSubCommand struct {
|
type ListSubCommand struct {
|
||||||
@@ -34,8 +34,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/logdb"
|
"github.com/fission/fission/pkg/fission-cli/logdb"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
@@ -35,14 +34,18 @@ type LogSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Log(flags cli.Input) error {
|
func Log(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := LogSubCommand{
|
opts := LogSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *LogSubCommand) do(flags cli.Input) error {
|
func (opts *LogSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -66,8 +69,13 @@ func (opts *LogSubCommand) do(flags cli.Input) error {
|
|||||||
return errors.Wrap(err, "error getting function")
|
return errors.Wrap(err, "error getting function")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server, err := util.GetApplicationUrl("application=fission-api")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// request the controller to establish a proxy server to the database.
|
// request the controller to establish a proxy server to the database.
|
||||||
logDB, err := logdb.GetLogDB(dbType, util.GetServerUrl())
|
logDB, err := logdb.GetLogDB(dbType, server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("failed to connect log database")
|
return errors.New("failed to connect log database")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
@@ -40,14 +39,18 @@ type TestSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test(flags cli.Input) error {
|
func Test(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := TestSubCommand{
|
opts := TestSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *TestSubCommand) do(flags cli.Input) error {
|
func (opts *TestSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -55,8 +58,10 @@ func (opts *TestSubCommand) do(flags cli.Input) error {
|
|||||||
routerURL := os.Getenv("FISSION_ROUTER")
|
routerURL := os.Getenv("FISSION_ROUTER")
|
||||||
if len(routerURL) == 0 {
|
if len(routerURL) == 0 {
|
||||||
// Portforward to the fission router
|
// Portforward to the fission router
|
||||||
localRouterPort := util.SetupPortForward(util.GetFissionNamespace(),
|
localRouterPort, err := util.SetupPortForward(util.GetFissionNamespace(), "application=fission-router")
|
||||||
"application=fission-router")
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
routerURL = "127.0.0.1:" + localRouterPort
|
routerURL = "127.0.0.1:" + localRouterPort
|
||||||
} else {
|
} else {
|
||||||
routerURL = strings.TrimPrefix(routerURL, "http://")
|
routerURL = strings.TrimPrefix(routerURL, "http://")
|
||||||
@@ -158,7 +163,12 @@ func printPodLogs(flags cli.Input) error {
|
|||||||
return errors.New("need --name argument.")
|
return errors.New("need --name argument.")
|
||||||
}
|
}
|
||||||
|
|
||||||
queryURL, err := url.Parse(util.GetServerUrl())
|
u, err := util.GetApplicationUrl("application=fission-api")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
queryURL, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error parsing the base URL")
|
return errors.Wrap(err, "error parsing the base URL")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
_package "github.com/fission/fission/pkg/fission-cli/cmd/package"
|
_package "github.com/fission/fission/pkg/fission-cli/cmd/package"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,8 +38,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -67,7 +71,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
fnNamespace := flags.String("fnNamespace")
|
fnNamespace := flags.String("fnNamespace")
|
||||||
|
|
||||||
m, err := cmd.GetMetadata("name", "fnNamespace", flags)
|
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -127,7 +131,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
Name: secretName,
|
Name: secretName,
|
||||||
})
|
})
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
log.Warn(fmt.Sprintf("secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
consolemsg.Warn(fmt.Sprintf("secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +155,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
Name: cfgMapName,
|
Name: cfgMapName,
|
||||||
})
|
})
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
log.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as the function", cfgMapName, fnNamespace))
|
consolemsg.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as the function", cfgMapName, fnNamespace))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +211,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resReqs, err := cmd.GetResourceReqs(flags, &function.Spec.Resources)
|
resReqs, err := util.GetResourceReqs(flags, &function.Spec.Resources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -267,7 +271,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if function.Spec.Environment.Name != pkg.Spec.Environment.Name {
|
if function.Spec.Environment.Name != pkg.Spec.Environment.Name {
|
||||||
log.Warn("Function's environment is different than package's environment, package's environment will be used for updating function")
|
consolemsg.Warn("Function's environment is different than package's environment, package's environment will be used for updating function")
|
||||||
function.Spec.Environment.Name = pkg.Spec.Environment.Name
|
function.Spec.Environment.Name = pkg.Spec.Environment.Name
|
||||||
function.Spec.Environment.Namespace = pkg.Spec.Environment.Namespace
|
function.Spec.Environment.Namespace = pkg.Spec.Environment.Namespace
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,8 @@ import (
|
|||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
ferror "github.com/fission/fission/pkg/error"
|
ferror "github.com/fission/fission/pkg/error"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,8 +40,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -101,7 +104,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
if !flags.Bool("spec") {
|
if !flags.Bool("spec") {
|
||||||
err = util.CheckFunctionExistence(opts.client, functionList, fnNamespace)
|
err = util.CheckFunctionExistence(opts.client, functionList, fnNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
consolemsg.Warn(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +118,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
|
|
||||||
host := flags.String("host")
|
host := flags.String("host")
|
||||||
if flags.IsSet("host") {
|
if flags.IsSet("host") {
|
||||||
log.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// just name triggers by uuid.
|
// just name triggers by uuid.
|
||||||
|
|||||||
@@ -19,13 +19,12 @@ package httptrigger
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -36,8 +35,12 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSubCommand struct {
|
type GetSubCommand struct {
|
||||||
@@ -38,8 +38,12 @@ type GetSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Get(flags cli.Input) error {
|
func Get(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetSubCommand{
|
opts := GetSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListSubCommand struct {
|
type ListSubCommand struct {
|
||||||
@@ -32,8 +32,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,8 +35,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -70,7 +73,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
functionList := flags.StringSlice("function")
|
functionList := flags.StringSlice("function")
|
||||||
err := util.CheckFunctionExistence(opts.client, functionList, triggerNamespace)
|
err := util.CheckFunctionExistence(opts.client, functionList, triggerNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
consolemsg.Warn(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var functionWeightsList []int
|
var functionWeightsList []int
|
||||||
@@ -93,7 +96,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
|||||||
|
|
||||||
if flags.IsSet("host") {
|
if flags.IsSet("host") {
|
||||||
ht.Spec.Host = flags.String("host")
|
ht.Spec.Host = flags.String("host")
|
||||||
log.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.IsSet("ingressrule") || flags.IsSet("ingressannotation") || flags.IsSet("ingresstls") {
|
if flags.IsSet("ingressrule") || flags.IsSet("ingressannotation") || flags.IsSet("ingresstls") {
|
||||||
|
|||||||
@@ -26,9 +26,8 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateSubCommand struct {
|
type CreateSubCommand struct {
|
||||||
@@ -37,8 +36,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -54,7 +57,7 @@ func (opts *CreateSubCommand) do(flags cli.Input) error {
|
|||||||
func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||||
fnName := flags.String("function")
|
fnName := flags.String("function")
|
||||||
if len(fnName) == 0 {
|
if len(fnName) == 0 {
|
||||||
log.Fatal("Need a function name to create a watch, use --function")
|
return errors.New("Need a function name to create a watch, use --function")
|
||||||
}
|
}
|
||||||
fnNamespace := flags.String("fnNamespace")
|
fnNamespace := flags.String("fnNamespace")
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -34,8 +34,12 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListSubCommand struct {
|
type ListSubCommand struct {
|
||||||
@@ -34,8 +34,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,8 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,8 +37,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -59,7 +62,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
fnName := flags.String("function")
|
fnName := flags.String("function")
|
||||||
if len(fnName) == 0 {
|
if len(fnName) == 0 {
|
||||||
log.Fatal("Need a function name to create a trigger, use --function")
|
return errors.New("Need a function name to create a trigger, use --function")
|
||||||
}
|
}
|
||||||
fnNamespace := flags.String("fnNamespace")
|
fnNamespace := flags.String("fnNamespace")
|
||||||
|
|
||||||
@@ -73,23 +76,21 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
mqType = types.MessageQueueTypeASQ
|
mqType = types.MessageQueueTypeASQ
|
||||||
case types.MessageQueueTypeKafka:
|
case types.MessageQueueTypeKafka:
|
||||||
mqType = types.MessageQueueTypeKafka
|
mqType = types.MessageQueueTypeKafka
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Fatal("Unknown message queue type, currently only \"nats-streaming, azure-storage-queue, kafka \" is supported")
|
return errors.New("Unknown message queue type, currently only \"nats-streaming, azure-storage-queue, kafka \" is supported")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check topic availability
|
// TODO: check topic availability
|
||||||
topic := flags.String("topic")
|
topic := flags.String("topic")
|
||||||
if len(topic) == 0 {
|
if len(topic) == 0 {
|
||||||
log.Fatal("Topic cannot be empty")
|
return errors.New("Topic cannot be empty")
|
||||||
}
|
}
|
||||||
respTopic := flags.String("resptopic")
|
respTopic := flags.String("resptopic")
|
||||||
|
|
||||||
if topic == respTopic {
|
if topic == respTopic {
|
||||||
// TODO maybe this should just be a warning, perhaps
|
// TODO maybe this should just be a warning, perhaps
|
||||||
// allow it behind a --force flag
|
// allow it behind a --force flag
|
||||||
log.Fatal("Listen topic should not equal to response topic")
|
return errors.New("Listen topic should not equal to response topic")
|
||||||
}
|
}
|
||||||
|
|
||||||
errorTopic := flags.String("errortopic")
|
errorTopic := flags.String("errortopic")
|
||||||
@@ -97,7 +98,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
maxRetries := flags.Int("maxretries")
|
maxRetries := flags.Int("maxretries")
|
||||||
|
|
||||||
if maxRetries < 0 {
|
if maxRetries < 0 {
|
||||||
log.Fatal("Maximum number of retries must be a natural number, default is 0")
|
return errors.New("Maximum number of retries must be a natural number, default is 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType := flags.String("contenttype")
|
contentType := flags.String("contenttype")
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -33,8 +33,12 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -48,7 +52,7 @@ func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
|
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "triggerns", flags)
|
m, err := util.GetMetadata("name", "triggerns", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListSubCommand struct {
|
type ListSubCommand struct {
|
||||||
@@ -34,8 +34,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateSubCommand struct {
|
type UpdateSubCommand struct {
|
||||||
@@ -33,8 +33,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -48,7 +52,7 @@ func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "triggerns", flags)
|
m, err := util.GetMetadata("name", "triggerns", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dchest/uniuri"
|
"github.com/dchest/uniuri"
|
||||||
|
"github.com/pkg/errors"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
cmdutils "github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,8 +39,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -60,7 +62,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
pkgNamespace := flags.String("pkgNamespace")
|
pkgNamespace := flags.String("pkgNamespace")
|
||||||
envName := flags.String("env")
|
envName := flags.String("env")
|
||||||
if len(envName) == 0 {
|
if len(envName) == 0 {
|
||||||
log.Fatal("Need --env argument.")
|
return errors.New("Need --env argument.")
|
||||||
}
|
}
|
||||||
envNamespace := flags.String("envNamespace")
|
envNamespace := flags.String("envNamespace")
|
||||||
srcArchiveFiles := flags.StringSlice("src")
|
srcArchiveFiles := flags.StringSlice("src")
|
||||||
@@ -69,7 +71,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
|||||||
keepURL := flags.Bool("keepurl")
|
keepURL := flags.Bool("keepurl")
|
||||||
|
|
||||||
if len(srcArchiveFiles) == 0 && len(deployArchiveFiles) == 0 {
|
if len(srcArchiveFiles) == 0 && len(deployArchiveFiles) == 0 {
|
||||||
log.Fatal("Need --src to specify source archive, or use --deploy to specify deployment archive.")
|
return errors.New("Need --src to specify source archive, or use --deploy to specify deployment archive.")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := CreatePackage(flags, opts.client, pkgNamespace, envName, envNamespace,
|
_, err := CreatePackage(flags, opts.client, pkgNamespace, envName, envNamespace,
|
||||||
@@ -132,19 +134,25 @@ func CreatePackage(flags cli.Input, client *client.Client, pkgNamespace string,
|
|||||||
|
|
||||||
if len(specFile) > 0 {
|
if len(specFile) > 0 {
|
||||||
// if a package sith the same spec exists, don't create a new spec file
|
// if a package sith the same spec exists, don't create a new spec file
|
||||||
fr, err := spec.ReadSpecs(cmdutils.GetSpecDir(flags))
|
fr, err := spec.ReadSpecs(util.GetSpecDir(flags))
|
||||||
util.CheckErr(err, "read specs")
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error reading specs")
|
||||||
|
}
|
||||||
if m := fr.SpecExists(pkg, false, true); m != nil {
|
if m := fr.SpecExists(pkg, false, true); m != nil {
|
||||||
fmt.Printf("Re-using previously created package %v\n", m.Name)
|
fmt.Printf("Re-using previously created package %v\n", m.Name)
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = spec.SpecSave(*pkg, specFile)
|
err = spec.SpecSave(*pkg, specFile)
|
||||||
util.CheckErr(err, "save package spec")
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error saving package spec")
|
||||||
|
}
|
||||||
return &pkg.Metadata, nil
|
return &pkg.Metadata, nil
|
||||||
} else {
|
} else {
|
||||||
pkgMetadata, err := client.PackageCreate(pkg)
|
pkgMetadata, err := client.PackageCreate(pkg)
|
||||||
util.CheckErr(err, "create package")
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error creating package")
|
||||||
|
}
|
||||||
fmt.Printf("Package '%v' created\n", pkgMetadata.GetName())
|
fmt.Printf("Package '%v' created\n", pkgMetadata.GetName())
|
||||||
return pkgMetadata, nil
|
return pkgMetadata, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
cmdutils "github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -36,8 +36,12 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmdutils.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
cmdutils "github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -45,16 +45,24 @@ type GetSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetSrc(flags cli.Input) error {
|
func GetSrc(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetSubCommand{
|
opts := GetSubCommand{
|
||||||
client: cmdutils.GetServer(flags),
|
client: c,
|
||||||
archiveType: sourceArchive,
|
archiveType: sourceArchive,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDeploy(flags cli.Input) error {
|
func GetDeploy(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetSubCommand{
|
opts := GetSubCommand{
|
||||||
client: cmdutils.GetServer(flags),
|
client: c,
|
||||||
archiveType: deployArchive,
|
archiveType: deployArchive,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
@@ -96,7 +104,10 @@ func (opts *GetSubCommand) run(flags cli.Input) error {
|
|||||||
if pkg.Spec.Deployment.Type == fv1.ArchiveTypeLiteral {
|
if pkg.Spec.Deployment.Type == fv1.ArchiveTypeLiteral {
|
||||||
reader = bytes.NewReader(archive.Literal)
|
reader = bytes.NewReader(archive.Literal)
|
||||||
} else if pkg.Spec.Deployment.Type == fv1.ArchiveTypeUrl {
|
} else if pkg.Spec.Deployment.Type == fv1.ArchiveTypeUrl {
|
||||||
readCloser := pkgutil.DownloadStoragesvcURL(opts.client, archive.URL)
|
readCloser, err := pkgutil.DownloadStoragesvcURL(opts.client, archive.URL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
defer readCloser.Close()
|
defer readCloser.Close()
|
||||||
reader = readCloser
|
reader = readCloser
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
cmdutils "github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,8 +36,12 @@ type InfoSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Info(flags cli.Input) error {
|
func Info(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := InfoSubCommand{
|
opts := InfoSubCommand{
|
||||||
client: cmdutils.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -54,7 +57,7 @@ func (opts *InfoSubCommand) do(flags cli.Input) error {
|
|||||||
func (opts *InfoSubCommand) complete(flags cli.Input) error {
|
func (opts *InfoSubCommand) complete(flags cli.Input) error {
|
||||||
opts.name = flags.String("name")
|
opts.name = flags.String("name")
|
||||||
if len(opts.name) == 0 {
|
if len(opts.name) == 0 {
|
||||||
log.Fatal("Need name of package, use --name")
|
return errors.New("Need name of package, use --name")
|
||||||
}
|
}
|
||||||
opts.namespace = flags.String("pkgNamespace")
|
opts.namespace = flags.String("pkgNamespace")
|
||||||
return nil
|
return nil
|
||||||
@@ -66,7 +69,7 @@ func (opts *InfoSubCommand) run(flags cli.Input) error {
|
|||||||
Name: opts.name,
|
Name: opts.name,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.CheckErr(err, fmt.Sprintf("find package %s", opts.name))
|
return errors.Wrapf(err, "error finding package %s", opts.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
cmdutils "github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListSubCommand struct {
|
type ListSubCommand struct {
|
||||||
@@ -38,8 +38,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmdutils.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func CreateArchive(client *client.Client, includeFiles []string, noZip bool, kee
|
|||||||
// Get files from inputs as number of files decide next steps
|
// Get files from inputs as number of files decide next steps
|
||||||
files, err := utils.FindAllGlobs([]string{path})
|
files, err := utils.FindAllGlobs([]string{path})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.CheckErr(err, "finding all globs")
|
return nil, errors.Wrap(err, "error finding all globs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
@@ -90,14 +90,18 @@ func CreateArchive(client *client.Client, includeFiles []string, noZip bool, kee
|
|||||||
|
|
||||||
// check if this AUS exists in the specs; if so, don't create a new one
|
// check if this AUS exists in the specs; if so, don't create a new one
|
||||||
fr, err := spec.ReadSpecs(specDir)
|
fr, err := spec.ReadSpecs(specDir)
|
||||||
util.CheckErr(err, "read specs")
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error reading specs")
|
||||||
|
}
|
||||||
if m := fr.SpecExists(aus, false, true); m != nil {
|
if m := fr.SpecExists(aus, false, true); m != nil {
|
||||||
fmt.Printf("Re-using previously created archive %v\n", m.Name)
|
fmt.Printf("Re-using previously created archive %v\n", m.Name)
|
||||||
aus.Name = m.Name
|
aus.Name = m.Name
|
||||||
} else {
|
} else {
|
||||||
// save the uploadspec
|
// save the uploadspec
|
||||||
err := spec.SpecSave(*aus, specFile)
|
err := spec.SpecSave(*aus, specFile)
|
||||||
util.CheckErr(err, fmt.Sprintf("write spec file %v", specFile))
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "write spec file %v", specFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the archive object
|
// create the archive object
|
||||||
@@ -118,11 +122,18 @@ func CreateArchive(client *client.Client, includeFiles []string, noZip bool, kee
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
// download the file before we archive it
|
// download the file before we archive it
|
||||||
dst := pkgutil.DownloadToTempFile(fileURL)
|
dst, err := pkgutil.DownloadToTempFile(fileURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
includeFiles = []string{dst}
|
includeFiles = []string{dst}
|
||||||
}
|
}
|
||||||
|
|
||||||
archivePath := makeArchiveFile("", includeFiles, noZip)
|
archivePath, err := makeArchiveFile("", includeFiles, noZip)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
return pkgutil.UploadArchiveFile(ctx, client, archivePath)
|
return pkgutil.UploadArchiveFile(ctx, client, archivePath)
|
||||||
}
|
}
|
||||||
@@ -134,7 +145,7 @@ func CreateArchive(client *client.Client, includeFiles []string, noZip bool, kee
|
|||||||
// returned as-is with no zipping. (This is used for compatibility
|
// returned as-is with no zipping. (This is used for compatibility
|
||||||
// with v1 envs.) noZip is IGNORED if there is more than one input
|
// with v1 envs.) noZip is IGNORED if there is more than one input
|
||||||
// file.
|
// file.
|
||||||
func makeArchiveFile(archiveNameHint string, archiveInput []string, noZip bool) string {
|
func makeArchiveFile(archiveNameHint string, archiveInput []string, noZip bool) (string, error) {
|
||||||
|
|
||||||
// Unique name for the archive
|
// Unique name for the archive
|
||||||
archiveName := archiveName(archiveNameHint, archiveInput)
|
archiveName := archiveName(archiveNameHint, archiveInput)
|
||||||
@@ -142,34 +153,34 @@ func makeArchiveFile(archiveNameHint string, archiveInput []string, noZip bool)
|
|||||||
// Get files from inputs as number of files decide next steps
|
// Get files from inputs as number of files decide next steps
|
||||||
files, err := utils.FindAllGlobs(archiveInput)
|
files, err := utils.FindAllGlobs(archiveInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.CheckErr(err, "finding all globs")
|
return "", errors.Wrap(err, "error finding all globs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have one file; if it's a zip file, no need to archive it
|
// We have one file; if it's a zip file, no need to archive it
|
||||||
if len(files) == 1 {
|
if len(files) == 1 {
|
||||||
// make sure it exists
|
// make sure it exists
|
||||||
if _, err := os.Stat(files[0]); err != nil {
|
if _, err := os.Stat(files[0]); err != nil {
|
||||||
util.CheckErr(err, fmt.Sprintf("open input file %v", files[0]))
|
return "", errors.Wrapf(err, "open input file %v", files[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's an existing zip file OR we're not supposed to zip it, don't do anything
|
// if it's an existing zip file OR we're not supposed to zip it, don't do anything
|
||||||
if archiver.Zip.Match(files[0]) || noZip {
|
if archiver.Zip.Match(files[0]) || noZip {
|
||||||
return files[0]
|
return files[0], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For anything else, create a new archive
|
// For anything else, create a new archive
|
||||||
tmpDir, err := utils.GetTempDir()
|
tmpDir, err := utils.GetTempDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.CheckErr(err, "create temporary archive directory")
|
return "", errors.Wrap(err, "error create temporary archive directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
archivePath, err := utils.MakeZipArchive(filepath.Join(tmpDir, archiveName), archiveInput...)
|
archivePath, err := utils.MakeZipArchive(filepath.Join(tmpDir, archiveName), archiveInput...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.CheckErr(err, "create archive file")
|
return "", errors.Wrap(err, "create archive file")
|
||||||
}
|
}
|
||||||
|
|
||||||
return archivePath
|
return archivePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name an archive
|
// Name an archive
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
cmdutils "github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RebuildSubCommand struct {
|
type RebuildSubCommand struct {
|
||||||
@@ -35,8 +35,12 @@ type RebuildSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Rebuild(flags cli.Input) error {
|
func Rebuild(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := RebuildSubCommand{
|
opts := RebuildSubCommand{
|
||||||
client: cmdutils.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateSubCommand struct {
|
type UpdateSubCommand struct {
|
||||||
@@ -43,8 +43,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
|
||||||
storageSvcClient "github.com/fission/fission/pkg/storagesvc/client"
|
storageSvcClient "github.com/fission/fission/pkg/storagesvc/client"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
"github.com/fission/fission/pkg/utils"
|
"github.com/fission/fission/pkg/utils"
|
||||||
@@ -46,18 +46,25 @@ func UploadArchiveFile(ctx context.Context, client *client.Client, fileName stri
|
|||||||
|
|
||||||
if size < types.ArchiveLiteralSizeLimit {
|
if size < types.ArchiveLiteralSizeLimit {
|
||||||
archive.Type = fv1.ArchiveTypeLiteral
|
archive.Type = fv1.ArchiveTypeLiteral
|
||||||
archive.Literal = GetContents(fileName)
|
archive.Literal, err = GetContents(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
u := strings.TrimSuffix(client.Url, "/") + "/proxy/storage"
|
u := strings.TrimSuffix(client.Url, "/") + "/proxy/storage"
|
||||||
ssClient := storageSvcClient.MakeClient(u)
|
ssClient := storageSvcClient.MakeClient(u)
|
||||||
|
|
||||||
// TODO add a progress bar
|
// TODO add a progress bar
|
||||||
id, err := ssClient.Upload(ctx, fileName, nil)
|
id, err := ssClient.Upload(ctx, fileName, nil)
|
||||||
util.CheckErr(err, fmt.Sprintf("upload file %v", fileName))
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error uploading file %v", fileName)
|
||||||
|
}
|
||||||
|
|
||||||
storageSvc, err := client.GetSvcURL("application=fission-storage")
|
storageSvc, err := client.GetSvcURL("application=fission-storage")
|
||||||
storageSvcURL := "http://" + storageSvc
|
storageSvcURL := "http://" + storageSvc
|
||||||
util.CheckErr(err, "get fission storage service name")
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error getting fission storage service name")
|
||||||
|
}
|
||||||
|
|
||||||
// We make a new client with actual URL of Storage service so that the URL is not
|
// We make a new client with actual URL of Storage service so that the URL is not
|
||||||
// pointing to 127.0.0.1 i.e. proxy. DON'T reuse previous ssClient
|
// pointing to 127.0.0.1 i.e. proxy. DON'T reuse previous ssClient
|
||||||
@@ -68,7 +75,9 @@ func UploadArchiveFile(ctx context.Context, client *client.Client, fileName stri
|
|||||||
archive.URL = archiveURL
|
archive.URL = archiveURL
|
||||||
|
|
||||||
csum, err := utils.GetFileChecksum(fileName)
|
csum, err := utils.GetFileChecksum(fileName)
|
||||||
util.CheckErr(err, fmt.Sprintf("calculate checksum for file %v", fileName))
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "calculate checksum for file %v", fileName)
|
||||||
|
}
|
||||||
|
|
||||||
archive.Checksum = *csum
|
archive.Checksum = *csum
|
||||||
}
|
}
|
||||||
@@ -76,32 +85,37 @@ func UploadArchiveFile(ctx context.Context, client *client.Client, fileName stri
|
|||||||
return &archive, nil
|
return &archive, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetContents(filePath string) []byte {
|
func GetContents(filePath string) ([]byte, error) {
|
||||||
var code []byte
|
code, err := ioutil.ReadFile(filePath)
|
||||||
var err error
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error reading %v", filePath)
|
||||||
code, err = ioutil.ReadFile(filePath)
|
}
|
||||||
util.CheckErr(err, fmt.Sprintf("read %v", filePath))
|
return code, nil
|
||||||
return code
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadToTempFile fetches archive file from arbitrary url
|
// DownloadToTempFile fetches archive file from arbitrary url
|
||||||
// and write it to temp file for further usage
|
// and write it to temp file for further usage
|
||||||
func DownloadToTempFile(fileUrl string) string {
|
func DownloadToTempFile(fileUrl string) (string, error) {
|
||||||
reader, err := DownloadURL(fileUrl)
|
reader, err := DownloadURL(fileUrl)
|
||||||
util.CheckErr(err, fmt.Sprintf("download from url: %v", fileUrl))
|
if err != nil {
|
||||||
|
return "", errors.Wrapf(err, "error downloading from url: %v", fileUrl)
|
||||||
|
}
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
tmpDir, err := utils.GetTempDir()
|
tmpDir, err := utils.GetTempDir()
|
||||||
util.CheckErr(err, "create temp directory")
|
if err != nil {
|
||||||
|
return "", errors.Wrapf(err, "error creating temp directory %v", tmpDir)
|
||||||
|
}
|
||||||
|
|
||||||
tmpFilename := uuid.NewV4().String()
|
tmpFilename := uuid.NewV4().String()
|
||||||
destination := filepath.Join(tmpDir, tmpFilename)
|
destination := filepath.Join(tmpDir, tmpFilename)
|
||||||
|
|
||||||
err = WriteArchiveToFile(destination, reader)
|
err = WriteArchiveToFile(destination, reader)
|
||||||
util.CheckErr(err, "write archive to file")
|
if err != nil {
|
||||||
|
return "", errors.Wrapf(err, "error writing archive to file %v", destination)
|
||||||
|
}
|
||||||
|
|
||||||
return destination
|
return destination, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadURL downloads file from given url
|
// DownloadURL downloads file from given url
|
||||||
@@ -146,16 +160,18 @@ func WriteArchiveToFile(fileName string, reader io.Reader) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DownloadStoragesvcURL downloads and return archive content with given storage service url
|
// DownloadStoragesvcURL downloads and return archive content with given storage service url
|
||||||
func DownloadStoragesvcURL(client *client.Client, fileUrl string) io.ReadCloser {
|
func DownloadStoragesvcURL(client *client.Client, fileUrl string) (io.ReadCloser, error) {
|
||||||
u, err := url.ParseRequestURI(fileUrl)
|
u, err := url.ParseRequestURI(fileUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace in-cluster storage service host with controller server url
|
// replace in-cluster storage service host with controller server url
|
||||||
fileDownloadUrl := strings.TrimSuffix(client.Url, "/") + "/proxy/storage/" + u.RequestURI()
|
fileDownloadUrl := strings.TrimSuffix(client.Url, "/") + "/proxy/storage/" + u.RequestURI()
|
||||||
reader, err := DownloadURL(fileDownloadUrl)
|
reader, err := DownloadURL(fileDownloadUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, fmt.Sprintf("error downloading from storage service url: %v", fileUrl))
|
||||||
|
}
|
||||||
|
|
||||||
util.CheckErr(err, fmt.Sprintf("download from storage service url: %v", fileUrl))
|
return reader, nil
|
||||||
return reader
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/plugin"
|
"github.com/fission/fission/pkg/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,8 +32,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := &ListSubCommand{
|
opts := &ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateSubCommand struct {
|
type CreateSubCommand struct {
|
||||||
@@ -37,8 +37,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -33,8 +33,12 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -48,7 +52,7 @@ func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
|
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "recorderns", flags)
|
m, err := util.GetMetadata("name", "recorderns", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSubCommand struct {
|
type GetSubCommand struct {
|
||||||
@@ -35,8 +35,12 @@ type GetSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Get(flags cli.Input) error {
|
func Get(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := GetSubCommand{
|
opts := GetSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListSubCommand struct {
|
type ListSubCommand struct {
|
||||||
@@ -33,8 +33,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateSubCommand struct {
|
type UpdateSubCommand struct {
|
||||||
@@ -35,8 +35,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
redisCache "github.com/fission/fission/pkg/redis/build/gen"
|
redisCache "github.com/fission/fission/pkg/redis/build/gen"
|
||||||
)
|
)
|
||||||
@@ -35,8 +34,12 @@ type ViewSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func View(flags cli.Input) error {
|
func View(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ViewSubCommand{
|
opts := ViewSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -68,71 +71,55 @@ func (opts *ViewSubCommand) run(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(function) != 0 {
|
if len(function) != 0 {
|
||||||
return recordsByFunction(function, verbosity, flags)
|
return recordsByFunction(opts.client, function, verbosity)
|
||||||
}
|
}
|
||||||
if len(trigger) != 0 {
|
if len(trigger) != 0 {
|
||||||
return recordsByTrigger(trigger, verbosity, flags)
|
return recordsByTrigger(opts.client, trigger, verbosity)
|
||||||
}
|
}
|
||||||
if len(from) != 0 && len(to) != 0 {
|
if len(from) != 0 && len(to) != 0 {
|
||||||
return recordsByTime(from, to, verbosity, flags)
|
return recordsByTime(opts.client, from, to, verbosity)
|
||||||
}
|
}
|
||||||
err := recordsAll(verbosity, flags)
|
err := recordsAll(opts.client, verbosity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error viewing records")
|
return errors.Wrap(err, "error viewing records")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordsAll(verbosity int, flags cli.Input) error {
|
func recordsAll(client *client.Client, verbosity int) error {
|
||||||
fc := util.GetApiClient(flags.GlobalString("server"))
|
records, err := client.RecordsAll()
|
||||||
|
|
||||||
records, err := fc.RecordsAll()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error viewing records")
|
return errors.Wrap(err, "error viewing records")
|
||||||
}
|
}
|
||||||
|
|
||||||
showRecords(records, verbosity)
|
showRecords(records, verbosity)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordsByTrigger(trigger string, verbosity int, flags cli.Input) error {
|
func recordsByTrigger(client *client.Client, trigger string, verbosity int) error {
|
||||||
fc := util.GetApiClient(flags.GlobalString("server"))
|
records, err := client.RecordsByTrigger(trigger)
|
||||||
|
|
||||||
records, err := fc.RecordsByTrigger(trigger)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error viewing records")
|
return errors.Wrap(err, "error viewing records")
|
||||||
}
|
}
|
||||||
|
|
||||||
showRecords(records, verbosity)
|
showRecords(records, verbosity)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: More accurate function name (function filter)
|
// TODO: More accurate function name (function filter)
|
||||||
func recordsByFunction(function string, verbosity int, flags cli.Input) error {
|
func recordsByFunction(client *client.Client, function string, verbosity int) error {
|
||||||
fc := util.GetApiClient(flags.GlobalString("server"))
|
records, err := client.RecordsByFunction(function)
|
||||||
|
|
||||||
records, err := fc.RecordsByFunction(function)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error viewing records")
|
return errors.Wrap(err, "error viewing records")
|
||||||
}
|
}
|
||||||
|
|
||||||
showRecords(records, verbosity)
|
showRecords(records, verbosity)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordsByTime(from string, to string, verbosity int, flags cli.Input) error {
|
func recordsByTime(client *client.Client, from string, to string, verbosity int) error {
|
||||||
fc := util.GetApiClient(flags.GlobalString("server"))
|
records, err := client.RecordsByTime(from, to)
|
||||||
|
|
||||||
records, err := fc.RecordsByTime(from, to)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error viewing records")
|
return errors.Wrap(err, "error viewing records")
|
||||||
}
|
}
|
||||||
|
|
||||||
showRecords(records, verbosity)
|
showRecords(records, verbosity)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReplaySubCommand struct {
|
type ReplaySubCommand struct {
|
||||||
@@ -33,8 +33,12 @@ type ReplaySubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Replay(flags cli.Input) error {
|
func Replay(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ReplaySubCommand{
|
opts := ReplaySubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
||||||
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
"github.com/fission/fission/pkg/utils"
|
"github.com/fission/fission/pkg/utils"
|
||||||
@@ -57,8 +57,12 @@ type ApplySubCommand struct {
|
|||||||
// etc, while doing an apply, they will get a partially applied deployment. However,
|
// etc, while doing an apply, they will get a partially applied deployment. However,
|
||||||
// they can retry their apply command once they're back online.
|
// they can retry their apply command once they're back online.
|
||||||
func Apply(flags cli.Input) error {
|
func Apply(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ApplySubCommand{
|
opts := ApplySubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -68,7 +72,7 @@ func (opts *ApplySubCommand) do(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (opts *ApplySubCommand) run(flags cli.Input) error {
|
func (opts *ApplySubCommand) run(flags cli.Input) error {
|
||||||
specDir := cmd.GetSpecDir(flags)
|
specDir := util.GetSpecDir(flags)
|
||||||
|
|
||||||
deleteResources := flags.Bool("delete")
|
deleteResources := flags.Bool("delete")
|
||||||
watchResources := flags.Bool("watch")
|
watchResources := flags.Bool("watch")
|
||||||
@@ -85,35 +89,50 @@ func (opts *ApplySubCommand) run(flags cli.Input) error {
|
|||||||
if watchResources {
|
if watchResources {
|
||||||
var err error
|
var err error
|
||||||
watcher, err = fsnotify.NewWatcher()
|
watcher, err = fsnotify.NewWatcher()
|
||||||
util.CheckErr(err, "create file watcher")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating file watcher")
|
||||||
|
}
|
||||||
|
|
||||||
// add watches
|
// add watches
|
||||||
rootDir := filepath.Clean(specDir + "/..")
|
rootDir := filepath.Clean(specDir + "/..")
|
||||||
err = filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
|
err = filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
|
||||||
util.CheckErr(err, "scan project files")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error scanning project files")
|
||||||
|
}
|
||||||
|
|
||||||
if ignoreFile(path) {
|
if ignoreFile(path) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = watcher.Add(path)
|
err = watcher.Add(path)
|
||||||
util.CheckErr(err, fmt.Sprintf("watch path %v", path))
|
if err != nil {
|
||||||
|
return errors.Wrap(err, fmt.Sprintf("error watching path %v", path))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
util.CheckErr(err, "scan files to watch")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error scanning files to watch")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// read all specs
|
// read all specs
|
||||||
fr, err := ReadSpecs(specDir)
|
fr, err := ReadSpecs(specDir)
|
||||||
util.CheckErr(err, "read specs")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error reading specs")
|
||||||
|
}
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
err = fr.Validate(flags)
|
err = fr.Validate(flags)
|
||||||
util.CheckErr(err, "validate specs")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error validating specs")
|
||||||
|
}
|
||||||
|
|
||||||
// make changes to the cluster based on the specs
|
// make changes to the cluster based on the specs
|
||||||
pkgMetas, as, err := applyResources(opts.client, specDir, fr, deleteResources)
|
pkgMetas, as, err := applyResources(opts.client, specDir, fr, deleteResources)
|
||||||
util.CheckErr(err, "apply specs")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error applying specs")
|
||||||
|
}
|
||||||
printApplyStatus(as)
|
printApplyStatus(as)
|
||||||
|
|
||||||
if watchResources || waitForBuild {
|
if watchResources || waitForBuild {
|
||||||
@@ -146,7 +165,6 @@ func (opts *ApplySubCommand) run(flags cli.Input) error {
|
|||||||
if ignoreFile(e.Name) {
|
if ignoreFile(e.Name) {
|
||||||
continue waitloop
|
continue waitloop
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Noticed a file change, reapplying specs...\n")
|
fmt.Printf("Noticed a file change, reapplying specs...\n")
|
||||||
|
|
||||||
// Builds that finish after this cancellation will be
|
// Builds that finish after this cancellation will be
|
||||||
@@ -154,11 +172,17 @@ func (opts *ApplySubCommand) run(flags cli.Input) error {
|
|||||||
pkgWatchCancel()
|
pkgWatchCancel()
|
||||||
|
|
||||||
err = waitForFileWatcherToSettleDown(watcher)
|
err = waitForFileWatcherToSettleDown(watcher)
|
||||||
util.CheckErr(err, "watching files")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error watching files")
|
||||||
|
}
|
||||||
break waitloop
|
break waitloop
|
||||||
|
|
||||||
case err := <-watcher.Errors:
|
case err := <-watcher.Errors:
|
||||||
util.CheckErr(err, "watching files")
|
pkgWatchCancel()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error watching files")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,7 +430,7 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
|
|||||||
absGlob := rootDir + "/" + relativeGlob
|
absGlob := rootDir + "/" + relativeGlob
|
||||||
f, err := filepath.Glob(absGlob)
|
f, err := filepath.Glob(absGlob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob))
|
consolemsg.Info(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
files = append(files, f...)
|
files = append(files, f...)
|
||||||
@@ -454,7 +478,10 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
|
|||||||
|
|
||||||
// figure out if we're making a literal or a URL-based archive
|
// figure out if we're making a literal or a URL-based archive
|
||||||
if size < types.ArchiveLiteralSizeLimit {
|
if size < types.ArchiveLiteralSizeLimit {
|
||||||
contents := pkgutil.GetContents(archiveFileName)
|
contents, err := pkgutil.GetContents(archiveFileName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &fv1.Archive{
|
return &fv1.Archive{
|
||||||
Type: fv1.ArchiveTypeLiteral,
|
Type: fv1.ArchiveTypeLiteral,
|
||||||
Literal: contents,
|
Literal: contents,
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ package spec
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,7 +68,10 @@ func (w *packageBuildWatcher) watch(ctx context.Context) {
|
|||||||
|
|
||||||
// pull list of packages (TODO: convert to watch)
|
// pull list of packages (TODO: convert to watch)
|
||||||
pkgs, err := w.fclient.PackageList(metav1.NamespaceAll)
|
pkgs, err := w.fclient.PackageList(metav1.NamespaceAll)
|
||||||
util.CheckErr(err, "Getting list of packages")
|
if err != nil {
|
||||||
|
fmt.Printf("Getting list of packages: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// find packages that (a) are in the app spec and (b) have an interesting
|
// find packages that (a) are in the app spec and (b) have an interesting
|
||||||
// build status (either succeeded or failed; not "none")
|
// build status (either succeeded or failed; not "none")
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ limitations under the License.
|
|||||||
package spec
|
package spec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,8 +30,12 @@ type DestroySubCommand struct {
|
|||||||
|
|
||||||
// Destroy destroys everything in the spec.
|
// Destroy destroys everything in the spec.
|
||||||
func Destroy(flags cli.Input) error {
|
func Destroy(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := &DestroySubCommand{
|
opts := &DestroySubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -41,11 +46,13 @@ func (opts *DestroySubCommand) do(flags cli.Input) error {
|
|||||||
|
|
||||||
func (opts *DestroySubCommand) run(flags cli.Input) error {
|
func (opts *DestroySubCommand) run(flags cli.Input) error {
|
||||||
// get specdir
|
// get specdir
|
||||||
specDir := cmd.GetSpecDir(flags)
|
specDir := util.GetSpecDir(flags)
|
||||||
|
|
||||||
// read everything
|
// read everything
|
||||||
fr, err := ReadSpecs(specDir)
|
fr, err := ReadSpecs(specDir)
|
||||||
util.CheckErr(err, "read specs")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error reading specs")
|
||||||
|
}
|
||||||
|
|
||||||
// set desired state to nothing, but keep the UID so "apply" can find it
|
// set desired state to nothing, but keep the UID so "apply" can find it
|
||||||
emptyFr := FissionResources{}
|
emptyFr := FissionResources{}
|
||||||
@@ -53,7 +60,9 @@ func (opts *DestroySubCommand) run(flags cli.Input) error {
|
|||||||
|
|
||||||
// "apply" the empty state
|
// "apply" the empty state
|
||||||
_, _, err = applyResources(opts.client, specDir, &emptyFr, true)
|
_, _, err = applyResources(opts.client, specDir, &emptyFr, true)
|
||||||
util.CheckErr(err, "delete resources")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error deleting resources")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
|
"github.com/pkg/errors"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
@@ -38,8 +38,12 @@ type InitSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Init(flags cli.Input) error {
|
func Init(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := InitSubCommand{
|
opts := InitSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -54,13 +58,15 @@ func (opts *InitSubCommand) do(flags cli.Input) error {
|
|||||||
|
|
||||||
func (opts *InitSubCommand) complete(flags cli.Input) error {
|
func (opts *InitSubCommand) complete(flags cli.Input) error {
|
||||||
// Figure out spec directory
|
// Figure out spec directory
|
||||||
specDir := cmd.GetSpecDir(flags)
|
specDir := util.GetSpecDir(flags)
|
||||||
|
|
||||||
name := flags.String("name")
|
name := flags.String("name")
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
// come up with a name using the current dir
|
// come up with a name using the current dir
|
||||||
dir, err := filepath.Abs(".")
|
dir, err := filepath.Abs(".")
|
||||||
util.CheckErr(err, "get current working directory")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error getting current working directory")
|
||||||
|
}
|
||||||
basename := filepath.Base(dir)
|
basename := filepath.Base(dir)
|
||||||
name = util.KubifyName(basename)
|
name = util.KubifyName(basename)
|
||||||
}
|
}
|
||||||
@@ -73,7 +79,9 @@ func (opts *InitSubCommand) complete(flags cli.Input) error {
|
|||||||
// Create spec dir
|
// Create spec dir
|
||||||
fmt.Printf("Creating fission spec directory '%v'\n", specDir)
|
fmt.Printf("Creating fission spec directory '%v'\n", specDir)
|
||||||
err := os.MkdirAll(specDir, 0755)
|
err := os.MkdirAll(specDir, 0755)
|
||||||
util.CheckErr(err, fmt.Sprintf("create spec directory '%v'", specDir))
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "create spec directory '%v'", specDir)
|
||||||
|
}
|
||||||
|
|
||||||
// Write the deployment config
|
// Write the deployment config
|
||||||
opts.deployConfig = &spectypes.DeploymentConfig{
|
opts.deployConfig = &spectypes.DeploymentConfig{
|
||||||
@@ -94,7 +102,7 @@ func (opts *InitSubCommand) complete(flags cli.Input) error {
|
|||||||
// run just initializes an empty spec directory and adds some
|
// run just initializes an empty spec directory and adds some
|
||||||
// sample YAMLs in there that might be useful.
|
// sample YAMLs in there that might be useful.
|
||||||
func (opts *InitSubCommand) run(flags cli.Input) error {
|
func (opts *InitSubCommand) run(flags cli.Input) error {
|
||||||
specDir := cmd.GetSpecDir(flags)
|
specDir := util.GetSpecDir(flags)
|
||||||
|
|
||||||
// Add a bit of documentation to the spec dir here
|
// Add a bit of documentation to the spec dir here
|
||||||
err := ioutil.WriteFile(filepath.Join(specDir, "README"), []byte(SPEC_README), 0644)
|
err := ioutil.WriteFile(filepath.Join(specDir, "README"), []byte(SPEC_README), 0644)
|
||||||
@@ -103,7 +111,9 @@ func (opts *InitSubCommand) run(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = writeDeploymentConfig(specDir, opts.deployConfig)
|
err = writeDeploymentConfig(specDir, opts.deployConfig)
|
||||||
util.CheckErr(err, "write deployment config")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error writing deployment config")
|
||||||
|
}
|
||||||
|
|
||||||
// Other possible things to do here:
|
// Other possible things to do here:
|
||||||
// - add example specs to the dir to make it easy to manually
|
// - add example specs to the dir to make it easy to manually
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ import (
|
|||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/generator/encoder"
|
"github.com/fission/fission/pkg/generator/encoder"
|
||||||
v1generator "github.com/fission/fission/pkg/generator/v1"
|
v1generator "github.com/fission/fission/pkg/generator/v1"
|
||||||
)
|
)
|
||||||
@@ -347,14 +347,17 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
|||||||
packages[MapKey(pkgMeta)] = true
|
packages[MapKey(pkgMeta)] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
client := cmd.GetServer(flags)
|
client, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for _, cm := range f.Spec.ConfigMaps {
|
for _, cm := range f.Spec.ConfigMaps {
|
||||||
_, err := client.ConfigMapGet(&metav1.ObjectMeta{
|
_, err := client.ConfigMapGet(&metav1.ObjectMeta{
|
||||||
Name: cm.Name,
|
Name: cm.Name,
|
||||||
Namespace: cm.Namespace,
|
Namespace: cm.Namespace,
|
||||||
})
|
})
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
log.Warn(fmt.Sprintf("Configmap %s is referred in the spec but not present in the cluster", cm.Name))
|
consolemsg.Warn(fmt.Sprintf("Configmap %s is referred in the spec but not present in the cluster", cm.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +367,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
|||||||
Namespace: s.Namespace,
|
Namespace: s.Namespace,
|
||||||
})
|
})
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
log.Warn(fmt.Sprintf("Secret %s is referred in the spec but not present in the cluster", s.Name))
|
consolemsg.Warn(fmt.Sprintf("Secret %s is referred in the spec but not present in the cluster", s.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -392,7 +395,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(t.Spec.Host) > 0 {
|
if len(t.Spec.Host) > 0 {
|
||||||
log.Warn(fmt.Sprintf("Host in HTTPTrigger spec.Host is now marked as deprecated, see 'help' for details"))
|
consolemsg.Warn(fmt.Sprintf("Host in HTTPTrigger spec.Host is now marked as deprecated, see 'help' for details"))
|
||||||
}
|
}
|
||||||
|
|
||||||
result = multierror.Append(result, t.Validate())
|
result = multierror.Append(result, t.Validate())
|
||||||
@@ -427,25 +430,25 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
|||||||
for _, e := range fr.Environments {
|
for _, e := range fr.Environments {
|
||||||
environments[fmt.Sprintf("%s:%s", e.Metadata.Name, e.Metadata.Namespace)] = struct{}{}
|
environments[fmt.Sprintf("%s:%s", e.Metadata.Name, e.Metadata.Namespace)] = struct{}{}
|
||||||
if ((e.Spec.Runtime.Container != nil) && (e.Spec.Runtime.PodSpec != nil)) || ((e.Spec.Builder.Container != nil) && (e.Spec.Builder.PodSpec != nil)) {
|
if ((e.Spec.Runtime.Container != nil) && (e.Spec.Runtime.PodSpec != nil)) || ((e.Spec.Builder.Container != nil) && (e.Spec.Builder.PodSpec != nil)) {
|
||||||
log.Warn("You have provided both - container spec and pod spec and while merging the pod spec will take precedence.")
|
consolemsg.Warn("You have provided both - container spec and pod spec and while merging the pod spec will take precedence.")
|
||||||
}
|
}
|
||||||
// Unlike CLI can change the environment version silently,
|
// Unlike CLI can change the environment version silently,
|
||||||
// we have to warn the user to modify spec file when this takes place.
|
// we have to warn the user to modify spec file when this takes place.
|
||||||
if e.Spec.Version < 3 && e.Spec.Poolsize != 0 {
|
if e.Spec.Version < 3 && e.Spec.Poolsize != 0 {
|
||||||
log.Warn("Poolsize can only be configured when environment version equals to 3, default poolsize 3 will be used for creating environment pool.")
|
consolemsg.Warn("Poolsize can only be configured when environment version equals to 3, default poolsize 3 will be used for creating environment pool.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fr.Functions {
|
for _, f := range fr.Functions {
|
||||||
if _, ok := environments[fmt.Sprintf("%s:%s", f.Spec.Environment.Name, f.Spec.Environment.Namespace)]; !ok {
|
if _, ok := environments[fmt.Sprintf("%s:%s", f.Spec.Environment.Name, f.Spec.Environment.Namespace)]; !ok {
|
||||||
log.Warn(fmt.Sprintf("Environment %s is referenced in function %s but not declared in specs", f.Spec.Environment.Name, f.Metadata.Name))
|
consolemsg.Warn(fmt.Sprintf("Environment %s is referenced in function %s but not declared in specs", f.Spec.Environment.Name, f.Metadata.Name))
|
||||||
}
|
}
|
||||||
strategy := f.Spec.InvokeStrategy.ExecutionStrategy
|
strategy := f.Spec.InvokeStrategy.ExecutionStrategy
|
||||||
if strategy.ExecutorType == fv1.ExecutorTypeNewdeploy && strategy.SpecializationTimeout < fv1.DefaultSpecializationTimeOut {
|
if strategy.ExecutorType == fv1.ExecutorTypeNewdeploy && strategy.SpecializationTimeout < fv1.DefaultSpecializationTimeOut {
|
||||||
log.Warn(fmt.Sprintf("SpecializationTimeout in function spec.InvokeStrategy.ExecutionStrategy should be a value equal to or greater than %v", fv1.DefaultSpecializationTimeOut))
|
consolemsg.Warn(fmt.Sprintf("SpecializationTimeout in function spec.InvokeStrategy.ExecutionStrategy should be a value equal to or greater than %v", fv1.DefaultSpecializationTimeOut))
|
||||||
}
|
}
|
||||||
if f.Spec.FunctionTimeout <= 0 {
|
if f.Spec.FunctionTimeout <= 0 {
|
||||||
log.Warn(fmt.Sprintf("FunctionTimeout in function spec should be a field which should have a value greater than 0"))
|
consolemsg.Warn(fmt.Sprintf("FunctionTimeout in function spec should be a field which should have a value greater than 0"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,7 +577,7 @@ func (fr *FissionResources) ParseYaml(b []byte, loc *Location) error {
|
|||||||
default:
|
default:
|
||||||
// no need to error out just because there's some extra files around;
|
// no need to error out just because there's some extra files around;
|
||||||
// also good for compatibility.
|
// also good for compatibility.
|
||||||
log.Warn(fmt.Sprintf("Ignoring unknown type %v in %v", tm.Kind, loc))
|
consolemsg.Warn(fmt.Sprintf("Ignoring unknown type %v in %v", tm.Kind, loc))
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to source map, check for duplicates
|
// add to source map, check for duplicates
|
||||||
|
|||||||
@@ -18,19 +18,17 @@ package spec
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,8 +39,12 @@ type ValidateSubCommand struct {
|
|||||||
// Validate parses a set of specs and checks for references to
|
// Validate parses a set of specs and checks for references to
|
||||||
// resources that don't exist.
|
// resources that don't exist.
|
||||||
func Validate(flags cli.Input) error {
|
func Validate(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := &ValidateSubCommand{
|
opts := &ValidateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -54,16 +56,16 @@ func (opts *ValidateSubCommand) do(flags cli.Input) error {
|
|||||||
func (opts *ValidateSubCommand) run(flags cli.Input) error {
|
func (opts *ValidateSubCommand) run(flags cli.Input) error {
|
||||||
|
|
||||||
// this will error on parse errors and on duplicates
|
// this will error on parse errors and on duplicates
|
||||||
specDir := cmd.GetSpecDir(flags)
|
specDir := util.GetSpecDir(flags)
|
||||||
fr, err := ReadSpecs(specDir)
|
fr, err := ReadSpecs(specDir)
|
||||||
util.CheckErr(err, "read specs")
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error reading specs")
|
||||||
|
}
|
||||||
|
|
||||||
// this does the rest of the checks, like dangling refs
|
// this does the rest of the checks, like dangling refs
|
||||||
err = fr.Validate(flags)
|
err = fr.Validate(flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error validating specs: %v", err)
|
return errors.Wrap(err, "error validating specs")
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -75,8 +77,8 @@ func ReadSpecs(specDir string) (*FissionResources, error) {
|
|||||||
|
|
||||||
// make sure spec directory exists before continue
|
// make sure spec directory exists before continue
|
||||||
if _, err := os.Stat(specDir); os.IsNotExist(err) {
|
if _, err := os.Stat(specDir); os.IsNotExist(err) {
|
||||||
log.Fatal(fmt.Sprintf("Spec directory %v doesn't exist. "+
|
return nil, errors.Errorf("Spec directory %v doesn't exist. "+
|
||||||
"Please check directory path or run \"fission spec init\" to create it.", specDir))
|
"Please check directory path or run \"fission spec init\" to create it.", specDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
fr := FissionResources{
|
fr := FissionResources{
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/support/resources"
|
"github.com/fission/fission/pkg/fission-cli/cmd/support/resources"
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/fission/fission/pkg/utils"
|
"github.com/fission/fission/pkg/utils"
|
||||||
@@ -43,8 +42,12 @@ type DumpSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Dump(flags cli.Input) error {
|
func Dump(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := &DumpSubCommand{
|
opts := &DumpSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -71,7 +74,10 @@ func (opts *DumpSubCommand) do(flags cli.Input) error {
|
|||||||
panic(errors.Wrap(err, "Error creating dump directory for dumping files"))
|
panic(errors.Wrap(err, "Error creating dump directory for dumping files"))
|
||||||
}
|
}
|
||||||
|
|
||||||
_, k8sClient := util.GetKubernetesClient()
|
_, k8sClient, err := util.GetKubernetesClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
ress := map[string]resources.Resource{
|
ress := map[string]resources.Resource{
|
||||||
// kubernetes info
|
// kubernetes info
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
case CrdEnvironment:
|
case CrdEnvironment:
|
||||||
items, err := res.client.EnvironmentList(metav1.NamespaceAll)
|
items, err := res.client.EnvironmentList(metav1.NamespaceAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
case CrdFunction:
|
case CrdFunction:
|
||||||
items, err := res.client.FunctionList(metav1.NamespaceAll)
|
items, err := res.client.FunctionList(metav1.NamespaceAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
case CrdPackage:
|
case CrdPackage:
|
||||||
items, err := res.client.PackageList(metav1.NamespaceAll)
|
items, err := res.client.PackageList(metav1.NamespaceAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
case CrdHttpTrigger:
|
case CrdHttpTrigger:
|
||||||
items, err := res.client.HTTPTriggerList(metav1.NamespaceAll)
|
items, err := res.client.HTTPTriggerList(metav1.NamespaceAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
case CrdKubeWatcher:
|
case CrdKubeWatcher:
|
||||||
items, err := res.client.WatchList(metav1.NamespaceAll)
|
items, err := res.client.WatchList(metav1.NamespaceAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
for _, mqType := range []string{types.MessageQueueTypeNats, types.MessageQueueTypeASQ} {
|
for _, mqType := range []string{types.MessageQueueTypeNats, types.MessageQueueTypeASQ} {
|
||||||
l, err := res.client.MessageQueueTriggerList(mqType, metav1.NamespaceAll)
|
l, err := res.client.MessageQueueTriggerList(mqType, metav1.NamespaceAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
triggers = append(triggers, l...)
|
triggers = append(triggers, l...)
|
||||||
@@ -131,7 +131,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
case CrdTimeTrigger:
|
case CrdTimeTrigger:
|
||||||
items, err := res.client.TimeTriggerList(metav1.NamespaceAll)
|
items, err := res.client.TimeTriggerList(metav1.NamespaceAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Info(fmt.Sprintf("Unknown type: %v", res.crdType))
|
consolemsg.Info(fmt.Sprintf("Unknown type: %v", res.crdType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -52,7 +52,7 @@ func NewKubernetesVersion(clientset *kubernetes.Clientset) Resource {
|
|||||||
func (res KubernetesVersion) Dump(dumpDir string) {
|
func (res KubernetesVersion) Dump(dumpDir string) {
|
||||||
serverVer, err := res.client.ServerVersion()
|
serverVer, err := res.client.ServerVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error setting up kubernetes client: %v", err))
|
consolemsg.Info(fmt.Sprintf("Error setting up kubernetes client: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
|||||||
case KubernetesService:
|
case KubernetesService:
|
||||||
objs, err := res.client.CoreV1().Services(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
objs, err := res.client.CoreV1().Services(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
|||||||
case KubernetesDeployment:
|
case KubernetesDeployment:
|
||||||
objs, err := res.client.AppsV1().Deployments(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
objs, err := res.client.AppsV1().Deployments(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
|||||||
case KubernetesPod:
|
case KubernetesPod:
|
||||||
objs, err := res.client.CoreV1().Pods(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
objs, err := res.client.CoreV1().Pods(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
|||||||
case KubernetesHPA:
|
case KubernetesHPA:
|
||||||
objs, err := res.client.AutoscalingV2beta1().HorizontalPodAutoscalers(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
objs, err := res.client.AutoscalingV2beta1().HorizontalPodAutoscalers(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
|||||||
case KubernetesDaemonSet:
|
case KubernetesDaemonSet:
|
||||||
objs, err := res.client.AppsV1().DaemonSets(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
objs, err := res.client.AppsV1().DaemonSets(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
|||||||
case KubernetesNode:
|
case KubernetesNode:
|
||||||
objs, err := res.client.CoreV1().Nodes().List(metav1.ListOptions{LabelSelector: res.selector})
|
objs, err := res.client.CoreV1().Nodes().List(metav1.ListOptions{LabelSelector: res.selector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Info(fmt.Sprintf("Unknown type: %v", res.objType))
|
consolemsg.Info(fmt.Sprintf("Unknown type: %v", res.objType))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) {
|
|||||||
Pods(metav1.NamespaceAll).
|
Pods(metav1.NamespaceAll).
|
||||||
List(metav1.ListOptions{LabelSelector: res.labelSelector})
|
List(metav1.ListOptions{LabelSelector: res.labelSelector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error getting controller list: %v", err))
|
consolemsg.Info(fmt.Sprintf("Error getting controller list: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) {
|
|||||||
|
|
||||||
stream, err := req.Stream()
|
stream, err := req.Stream()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error streaming logs for pod %v: %v", pod.Name, err))
|
consolemsg.Info(fmt.Sprintf("Error streaming logs for pod %v: %v", pod.Name, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,13 +232,13 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) {
|
|||||||
stream.Close()
|
stream.Close()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
log.Info(fmt.Sprintf("Error reading logs from buffer: %v", err))
|
consolemsg.Info(fmt.Sprintf("Error reading logs from buffer: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = buffer.WriteString(string(line) + "\n")
|
_, err = buffer.WriteString(string(line) + "\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error writing bytes to buffer: %v", err))
|
consolemsg.Info(fmt.Sprintf("Error writing bytes to buffer: %v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
"github.com/fission/fission/pkg/utils"
|
"github.com/fission/fission/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ func getPodFileName(dumpdir string, pod metav1.ObjectMeta, containerName string)
|
|||||||
func writeToFile(file string, obj interface{}) {
|
func writeToFile(file string, obj interface{}) {
|
||||||
bs, err := yaml.Marshal(obj)
|
bs, err := yaml.Marshal(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error encoding object: %v", err))
|
consolemsg.Info(fmt.Sprintf("Error encoding object: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +57,6 @@ func writeToFile(file string, obj interface{}) {
|
|||||||
|
|
||||||
err = ioutil.WriteFile(file, bs, 0644)
|
err = ioutil.WriteFile(file, bs, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(fmt.Sprintf("Error writing file %v: %v", file, err))
|
consolemsg.Info(fmt.Sprintf("Error writing file %v: %v", file, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateSubCommand struct {
|
type CreateSubCommand struct {
|
||||||
@@ -38,8 +38,12 @@ type CreateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Create(flags cli.Input) error {
|
func Create(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := CreateSubCommand{
|
opts := CreateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteSubCommand struct {
|
type DeleteSubCommand struct {
|
||||||
@@ -31,14 +31,18 @@ type DeleteSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Delete(flags cli.Input) error {
|
func Delete(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := DeleteSubCommand{
|
opts := DeleteSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "triggerns", flags)
|
m, err := util.GetMetadata("name", "triggerns", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,8 +32,12 @@ type ListSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func List(flags cli.Input) error {
|
func List(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ListSubCommand{
|
opts := ListSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ShowSubCommand struct {
|
type ShowSubCommand struct {
|
||||||
@@ -29,8 +29,12 @@ type ShowSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Show(flags cli.Input) error {
|
func Show(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := ShowSubCommand{
|
opts := ShowSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateSubCommand struct {
|
type UpdateSubCommand struct {
|
||||||
@@ -33,8 +33,12 @@ type UpdateSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Update(flags cli.Input) error {
|
func Update(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := UpdateSubCommand{
|
opts := UpdateSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -48,7 +52,7 @@ func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||||
m, err := cmd.GetMetadata("name", "triggerns", flags)
|
m, err := util.GetMetadata("name", "triggerns", flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,143 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 The Fission Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetServer(flags cli.Input) *client.Client {
|
|
||||||
return util.GetApiClient(flags.GlobalString(FISSION_SERVER))
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.ResourceRequirements, error) {
|
|
||||||
r := &v1.ResourceRequirements{}
|
|
||||||
|
|
||||||
if resReqs != nil {
|
|
||||||
r.Requests = resReqs.Requests
|
|
||||||
r.Limits = resReqs.Limits
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(r.Requests) == 0 {
|
|
||||||
r.Requests = make(map[v1.ResourceName]resource.Quantity)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(r.Limits) == 0 {
|
|
||||||
r.Limits = make(map[v1.ResourceName]resource.Quantity)
|
|
||||||
}
|
|
||||||
|
|
||||||
e := &multierror.Error{}
|
|
||||||
|
|
||||||
if flags.IsSet(RUNTIME_MINCPU) {
|
|
||||||
mincpu := flags.Int(RUNTIME_MINCPU)
|
|
||||||
cpuRequest, err := resource.ParseQuantity(strconv.Itoa(mincpu) + "m")
|
|
||||||
if err != nil {
|
|
||||||
e = multierror.Append(e, errors.Wrap(err, "Failed to parse mincpu"))
|
|
||||||
}
|
|
||||||
r.Requests[v1.ResourceCPU] = cpuRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
if flags.IsSet(RUNTIME_MINMEMORY) {
|
|
||||||
minmem := flags.Int(RUNTIME_MINMEMORY)
|
|
||||||
memRequest, err := resource.ParseQuantity(strconv.Itoa(minmem) + "Mi")
|
|
||||||
if err != nil {
|
|
||||||
e = multierror.Append(e, errors.Wrap(err, "Failed to parse minmemory"))
|
|
||||||
}
|
|
||||||
r.Requests[v1.ResourceMemory] = memRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
if flags.IsSet(RUNTIME_MAXCPU) {
|
|
||||||
maxcpu := flags.Int(RUNTIME_MAXCPU)
|
|
||||||
cpuLimit, err := resource.ParseQuantity(strconv.Itoa(maxcpu) + "m")
|
|
||||||
if err != nil {
|
|
||||||
e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxcpu"))
|
|
||||||
}
|
|
||||||
r.Limits[v1.ResourceCPU] = cpuLimit
|
|
||||||
}
|
|
||||||
|
|
||||||
if flags.IsSet(RUNTIME_MAXMEMORY) {
|
|
||||||
maxmem := flags.Int(RUNTIME_MAXMEMORY)
|
|
||||||
memLimit, err := resource.ParseQuantity(strconv.Itoa(maxmem) + "Mi")
|
|
||||||
if err != nil {
|
|
||||||
e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxmemory"))
|
|
||||||
}
|
|
||||||
r.Limits[v1.ResourceMemory] = memLimit
|
|
||||||
}
|
|
||||||
|
|
||||||
limitCPU := r.Limits[v1.ResourceCPU]
|
|
||||||
requestCPU := r.Requests[v1.ResourceCPU]
|
|
||||||
|
|
||||||
if limitCPU.IsZero() && !requestCPU.IsZero() {
|
|
||||||
r.Limits[v1.ResourceCPU] = requestCPU
|
|
||||||
} else if limitCPU.Cmp(requestCPU) < 0 {
|
|
||||||
e = multierror.Append(e, fmt.Errorf("MinCPU (%v) cannot be greater than MaxCPU (%v)", requestCPU.String(), limitCPU.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
limitMem := r.Limits[v1.ResourceMemory]
|
|
||||||
requestMem := r.Requests[v1.ResourceMemory]
|
|
||||||
|
|
||||||
if limitMem.IsZero() && !requestMem.IsZero() {
|
|
||||||
r.Limits[v1.ResourceMemory] = requestMem
|
|
||||||
} else if limitMem.Cmp(requestMem) < 0 {
|
|
||||||
e = multierror.Append(e, fmt.Errorf("MinMemory (%v) cannot be greater than MaxMemory (%v)", requestMem.String(), limitMem.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.ErrorOrNil() != nil {
|
|
||||||
return nil, e
|
|
||||||
}
|
|
||||||
|
|
||||||
return &v1.ResourceRequirements{
|
|
||||||
Requests: r.Requests,
|
|
||||||
Limits: r.Limits,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSpecDir(flags cli.Input) string {
|
|
||||||
specDir := flags.String(SPEC_SPECDIR)
|
|
||||||
if len(specDir) == 0 {
|
|
||||||
specDir = "specs"
|
|
||||||
}
|
|
||||||
return specDir
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMetadata returns a pointer to ObjectMeta that is populated with resource name and namespace given by the user.
|
|
||||||
func GetMetadata(nameFlagText string, namespaceFlagText string, flags cli.Input) (*metav1.ObjectMeta, error) {
|
|
||||||
name := flags.String(nameFlagText)
|
|
||||||
if len(name) == 0 {
|
|
||||||
return nil, errors.Errorf("need a resource name, use --%v", nameFlagText)
|
|
||||||
}
|
|
||||||
|
|
||||||
ns := flags.String(namespaceFlagText)
|
|
||||||
|
|
||||||
m := &metav1.ObjectMeta{
|
|
||||||
Name: name,
|
|
||||||
Namespace: ns,
|
|
||||||
}
|
|
||||||
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
@@ -20,11 +20,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,8 +32,12 @@ type VersionSubCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Version(flags cli.Input) error {
|
func Version(flags cli.Input) error {
|
||||||
|
c, err := util.GetServer(flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
opts := &VersionSubCommand{
|
opts := &VersionSubCommand{
|
||||||
client: cmd.GetServer(flags),
|
client: c,
|
||||||
}
|
}
|
||||||
return opts.do(flags)
|
return opts.do(flags)
|
||||||
}
|
}
|
||||||
@@ -43,7 +46,7 @@ func (opts *VersionSubCommand) do(flags cli.Input) error {
|
|||||||
ver := util.GetVersion(opts.client)
|
ver := util.GetVersion(opts.client)
|
||||||
bs, err := yaml.Marshal(ver)
|
bs, err := yaml.Marshal(ver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error formatting versions: " + err.Error())
|
return errors.Wrap(err, "error formatting versions")
|
||||||
}
|
}
|
||||||
fmt.Print(string(bs))
|
fmt.Print(string(bs))
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package log
|
package consolemsg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -27,8 +27,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Fatal(msg interface{}) {
|
func Fatal(msg interface{}) {
|
||||||
os.Stderr.WriteString(fmt.Sprintf("Fatal error: %v\n", msg))
|
//os.Stderr.WriteString(fmt.Sprintf("Fatal error: %v\n", msg))
|
||||||
os.Exit(1)
|
//os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Warn(msg interface{}) {
|
func Warn(msg interface{}) {
|
||||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cmd
|
package flag
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
@@ -30,7 +30,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
ferror "github.com/fission/fission/pkg/error"
|
ferror "github.com/fission/fission/pkg/error"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -84,7 +83,7 @@ func (influx InfluxDB) GetLogs(filter LogFilter) ([]LogEntry, error) {
|
|||||||
logEntries := []LogEntry{}
|
logEntries := []LogEntry{}
|
||||||
response, err := influx.query(query)
|
response, err := influx.query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return logEntries, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, r := range response.Results {
|
for _, r := range response.Results {
|
||||||
for _, series := range r.Series {
|
for _, series := range r.Series {
|
||||||
@@ -108,11 +107,11 @@ func (influx InfluxDB) GetLogs(filter LogFilter) ([]LogEntry, error) {
|
|||||||
for _, row := range series.Values {
|
for _, row := range series.Values {
|
||||||
t, err := time.Parse(time.RFC3339, row[0].(string))
|
t, err := time.Parse(time.RFC3339, row[0].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
seqNum, err := strconv.Atoi(row[seq].(string))
|
seqNum, err := strconv.Atoi(row[seq].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return logEntries, err
|
return nil, err
|
||||||
}
|
}
|
||||||
entry := LogEntry{
|
entry := LogEntry{
|
||||||
//The attributes of the LogEntry are selected as relative to their position in InfluxDB's line protocol response
|
//The attributes of the LogEntry are selected as relative to their position in InfluxDB's line protocol response
|
||||||
|
|||||||
@@ -25,12 +25,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/tools/portforward"
|
"k8s.io/client-go/tools/portforward"
|
||||||
"k8s.io/client-go/transport/spdy"
|
"k8s.io/client-go/transport/spdy"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
"github.com/fission/fission/pkg/utils"
|
"github.com/fission/fission/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,16 +40,16 @@ import (
|
|||||||
// is found by looking for a service in the same namespace and using
|
// is found by looking for a service in the same namespace and using
|
||||||
// its targetPort. Once the port forward is started, wait for it to
|
// its targetPort. Once the port forward is started, wait for it to
|
||||||
// start accepting connections before returning.
|
// start accepting connections before returning.
|
||||||
func SetupPortForward(namespace, labelSelector string) string {
|
func SetupPortForward(namespace, labelSelector string) (string, error) {
|
||||||
log.Verbose(2, "Setting up port forward to %s in namespace %s",
|
consolemsg.Verbose(2, "Setting up port forward to %s in namespace %s",
|
||||||
labelSelector, namespace)
|
labelSelector, namespace)
|
||||||
|
|
||||||
localPort, err := findFreePort()
|
localPort, err := findFreePort()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Error finding unused port :%v", err.Error()))
|
return "", errors.Wrap(err, "error finding unused port")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Verbose(2, "Waiting for local port %v", localPort)
|
consolemsg.Verbose(2, "Waiting for local port %v", localPort)
|
||||||
for {
|
for {
|
||||||
conn, _ := net.DialTimeout("tcp",
|
conn, _ := net.DialTimeout("tcp",
|
||||||
net.JoinHostPort("", localPort), time.Millisecond)
|
net.JoinHostPort("", localPort), time.Millisecond)
|
||||||
@@ -60,15 +61,16 @@ func SetupPortForward(namespace, labelSelector string) string {
|
|||||||
time.Sleep(time.Millisecond * 50)
|
time.Sleep(time.Millisecond * 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Verbose(2, "Starting port forward from local port %v", localPort)
|
consolemsg.Verbose(2, "Starting port forward from local port %v", localPort)
|
||||||
go func() {
|
go func() {
|
||||||
err := runPortForward(labelSelector, localPort, namespace)
|
err := runPortForward(labelSelector, localPort, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Error forwarding to port %v: %s", localPort, err.Error()))
|
fmt.Printf("Error forwarding to port %v: %s", localPort, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Verbose(2, "Waiting for port forward %v to start...", localPort)
|
consolemsg.Verbose(2, "Waiting for port forward %v to start...", localPort)
|
||||||
for {
|
for {
|
||||||
conn, _ := net.DialTimeout("tcp",
|
conn, _ := net.DialTimeout("tcp",
|
||||||
net.JoinHostPort("", localPort), time.Millisecond)
|
net.JoinHostPort("", localPort), time.Millisecond)
|
||||||
@@ -79,9 +81,9 @@ func SetupPortForward(namespace, labelSelector string) string {
|
|||||||
time.Sleep(time.Millisecond * 50)
|
time.Sleep(time.Millisecond * 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Verbose(2, "Port forward from local port %v started", localPort)
|
consolemsg.Verbose(2, "Port forward from local port %v started", localPort)
|
||||||
|
|
||||||
return localPort
|
return localPort, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findFreePort() (string, error) {
|
func findFreePort() (string, error) {
|
||||||
@@ -102,9 +104,12 @@ func findFreePort() (string, error) {
|
|||||||
|
|
||||||
// runPortForward creates a local port forward to the specified pod
|
// runPortForward creates a local port forward to the specified pod
|
||||||
func runPortForward(labelSelector string, localPort string, ns string) error {
|
func runPortForward(labelSelector string, localPort string, ns string) error {
|
||||||
config, clientset := GetKubernetesClient()
|
config, clientset, err := GetKubernetesClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
log.Verbose(2, "Connected to Kubernetes API")
|
consolemsg.Verbose(2, "Connected to Kubernetes API")
|
||||||
|
|
||||||
// if namespace is unset, try to find a pod in any namespace
|
// if namespace is unset, try to find a pod in any namespace
|
||||||
if len(ns) == 0 {
|
if len(ns) == 0 {
|
||||||
@@ -114,8 +119,10 @@ func runPortForward(labelSelector string, localPort string, ns string) error {
|
|||||||
// get the pod; if there is more than one, ask the user to disambiguate
|
// get the pod; if there is more than one, ask the user to disambiguate
|
||||||
podList, err := clientset.CoreV1().Pods(ns).
|
podList, err := clientset.CoreV1().Pods(ns).
|
||||||
List(meta_v1.ListOptions{LabelSelector: labelSelector})
|
List(meta_v1.ListOptions{LabelSelector: labelSelector})
|
||||||
if err != nil || len(podList.Items) == 0 {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Error getting pod for port-forwarding with label selector %v: %v", labelSelector, err))
|
return errors.Wrapf(err, "error getting pod for port-forwarding with label selector %v", labelSelector)
|
||||||
|
} else if len(podList.Items) == 0 {
|
||||||
|
return errors.Errorf("no available pod for port-forwarding with label selector %v", labelSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsList := make([]string, 0)
|
nsList := make([]string, 0)
|
||||||
@@ -131,8 +138,8 @@ func runPortForward(labelSelector string, localPort string, ns string) error {
|
|||||||
namespaces[p.Namespace] = append(namespaces[p.Namespace], &p)
|
namespaces[p.Namespace] = append(namespaces[p.Namespace], &p)
|
||||||
}
|
}
|
||||||
if len(nsList) > 1 {
|
if len(nsList) > 1 {
|
||||||
log.Fatal(fmt.Sprintf("Found %v fission installs, set FISSION_NAMESPACE to one of: %v",
|
return errors.Errorf("Found %v fission installs, set FISSION_NAMESPACE to one of: %v",
|
||||||
len(namespaces), strings.Join(nsList, " ")))
|
len(namespaces), strings.Join(nsList, " "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +148,7 @@ func runPortForward(labelSelector string, localPort string, ns string) error {
|
|||||||
ns = nsList[0]
|
ns = nsList[0]
|
||||||
pods, ok := namespaces[ns]
|
pods, ok := namespaces[ns]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal(fmt.Sprintf("Error finding fission install within the given namespace %v, please check FISSION_NAMESPACE is set properly", ns))
|
return errors.Errorf("Error finding fission install within the given namespace %v, please check FISSION_NAMESPACE is set properly", ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
var podName, podNameSpace string
|
var podName, podNameSpace string
|
||||||
@@ -159,10 +166,10 @@ func runPortForward(labelSelector string, localPort string, ns string) error {
|
|||||||
svcs, err := clientset.CoreV1().Services(podNameSpace).
|
svcs, err := clientset.CoreV1().Services(podNameSpace).
|
||||||
List(meta_v1.ListOptions{LabelSelector: labelSelector})
|
List(meta_v1.ListOptions{LabelSelector: labelSelector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Error getting %v service :%v", labelSelector, err.Error()))
|
return errors.Wrapf(err, "Error getting %v service", labelSelector)
|
||||||
}
|
}
|
||||||
if len(svcs.Items) == 0 {
|
if len(svcs.Items) == 0 {
|
||||||
log.Fatal(fmt.Sprintf("Service %v not found", labelSelector))
|
return errors.Errorf("Service %v not found", labelSelector)
|
||||||
}
|
}
|
||||||
service := &svcs.Items[0]
|
service := &svcs.Items[0]
|
||||||
|
|
||||||
@@ -170,7 +177,7 @@ func runPortForward(labelSelector string, localPort string, ns string) error {
|
|||||||
for _, servicePort := range service.Spec.Ports {
|
for _, servicePort := range service.Spec.Ports {
|
||||||
targetPort = servicePort.TargetPort.String()
|
targetPort = servicePort.TargetPort.String()
|
||||||
}
|
}
|
||||||
log.Verbose(2, "Connecting to port %v on pod %v/%v", targetPort, podNameSpace, podNameSpace)
|
consolemsg.Verbose(2, "Connecting to port %v on pod %v/%v", targetPort, podNameSpace, podNameSpace)
|
||||||
|
|
||||||
stopChannel := make(chan struct{}, 1)
|
stopChannel := make(chan struct{}, 1)
|
||||||
readyChannel := make(chan struct{})
|
readyChannel := make(chan struct{})
|
||||||
@@ -187,21 +194,19 @@ func runPortForward(labelSelector string, localPort string, ns string) error {
|
|||||||
// actually start the port-forwarding process here
|
// actually start the port-forwarding process here
|
||||||
transport, upgrader, err := spdy.RoundTripperFor(config)
|
transport, upgrader, err := spdy.RoundTripperFor(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("Failed to connect to Fission service on Kubernetes: %v", err.Error())
|
return errors.Errorf("Failed to connect to Fission service on Kubernetes")
|
||||||
log.Fatal(msg)
|
|
||||||
}
|
}
|
||||||
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", url)
|
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", url)
|
||||||
|
|
||||||
outStream := os.Stdout
|
outStream := os.Stdout
|
||||||
if log.Verbosity < 2 {
|
if consolemsg.Verbosity < 2 {
|
||||||
outStream = nil
|
outStream = nil
|
||||||
}
|
}
|
||||||
fw, err := portforward.New(dialer, ports, stopChannel, readyChannel, outStream, os.Stderr)
|
fw, err := portforward.New(dialer, ports, stopChannel, readyChannel, outStream, os.Stderr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("portforward.new errored out :%v", err.Error())
|
return errors.Wrap(err, "error creating port forwarder")
|
||||||
log.Fatal(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Verbose(2, "Starting port forwarder")
|
consolemsg.Verbose(2, "Starting port forwarder")
|
||||||
return fw.ForwardPorts()
|
return fw.ForwardPorts()
|
||||||
}
|
}
|
||||||
|
|||||||
+153
-45
@@ -22,62 +22,46 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||||
"github.com/fission/fission/pkg/info"
|
"github.com/fission/fission/pkg/info"
|
||||||
"github.com/fission/fission/pkg/plugin"
|
"github.com/fission/fission/pkg/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetApiClient(serverUrl string) *client.Client {
|
|
||||||
if len(serverUrl) == 0 {
|
|
||||||
// starts local portforwarder etc.
|
|
||||||
serverUrl = GetServerUrl()
|
|
||||||
}
|
|
||||||
|
|
||||||
isHTTPS := strings.Index(serverUrl, "https://") == 0
|
|
||||||
isHTTP := strings.Index(serverUrl, "http://") == 0
|
|
||||||
|
|
||||||
if !(isHTTP || isHTTPS) {
|
|
||||||
serverUrl = "http://" + serverUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
return client.MakeClient(serverUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetFissionNamespace() string {
|
func GetFissionNamespace() string {
|
||||||
fissionNamespace := os.Getenv("FISSION_NAMESPACE")
|
fissionNamespace := os.Getenv("FISSION_NAMESPACE")
|
||||||
return fissionNamespace
|
return fissionNamespace
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetServerUrl() string {
|
func GetApplicationUrl(selector string) (string, error) {
|
||||||
return GetApplicationUrl("application=fission-api")
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetApplicationUrl(selector string) string {
|
|
||||||
var serverUrl string
|
var serverUrl string
|
||||||
// Use FISSION_URL env variable if set; otherwise, port-forward to controller.
|
// Use FISSION_URL env variable if set; otherwise, port-forward to controller.
|
||||||
fissionUrl := os.Getenv("FISSION_URL")
|
fissionUrl := os.Getenv("FISSION_URL")
|
||||||
if len(fissionUrl) == 0 {
|
if len(fissionUrl) == 0 {
|
||||||
fissionNamespace := GetFissionNamespace()
|
fissionNamespace := GetFissionNamespace()
|
||||||
localPort := SetupPortForward(fissionNamespace, "application=fission-api")
|
localPort, err := SetupPortForward(fissionNamespace, selector)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
serverUrl = "http://127.0.0.1:" + localPort
|
serverUrl = "http://127.0.0.1:" + localPort
|
||||||
} else {
|
} else {
|
||||||
serverUrl = fissionUrl
|
serverUrl = fissionUrl
|
||||||
}
|
}
|
||||||
return serverUrl
|
return serverUrl, nil
|
||||||
}
|
|
||||||
|
|
||||||
func CheckErr(err error, msg string) {
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(fmt.Sprintf("Failed to %v: %v", msg, err))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// KubifyName make a kubernetes compliant name out of an arbitrary string
|
// KubifyName make a kubernetes compliant name out of an arbitrary string
|
||||||
@@ -88,18 +72,15 @@ func KubifyName(old string) string {
|
|||||||
newName := strings.ToLower(old)
|
newName := strings.ToLower(old)
|
||||||
|
|
||||||
// replace disallowed chars with '-'
|
// replace disallowed chars with '-'
|
||||||
inv, err := regexp.Compile("[^-a-z0-9]")
|
inv, _ := regexp.Compile("[^-a-z0-9]")
|
||||||
CheckErr(err, "compile regexp")
|
|
||||||
newName = string(inv.ReplaceAll([]byte(newName), []byte("-")))
|
newName = string(inv.ReplaceAll([]byte(newName), []byte("-")))
|
||||||
|
|
||||||
// trim leading non-alphabetic
|
// trim leading non-alphabetic
|
||||||
leadingnonalpha, err := regexp.Compile("^[^a-z]+")
|
leadingnonalpha, _ := regexp.Compile("^[^a-z]+")
|
||||||
CheckErr(err, "compile regexp")
|
|
||||||
newName = string(leadingnonalpha.ReplaceAll([]byte(newName), []byte{}))
|
newName = string(leadingnonalpha.ReplaceAll([]byte(newName), []byte{}))
|
||||||
|
|
||||||
// trim trailing
|
// trim trailing
|
||||||
trailing, err := regexp.Compile("[^a-z0-9]+$")
|
trailing, _ := regexp.Compile("[^a-z0-9]+$")
|
||||||
CheckErr(err, "compile regexp")
|
|
||||||
newName = string(trailing.ReplaceAll([]byte(newName), []byte{}))
|
newName = string(trailing.ReplaceAll([]byte(newName), []byte{}))
|
||||||
|
|
||||||
// truncate to length
|
// truncate to length
|
||||||
@@ -119,7 +100,7 @@ func KubifyName(old string) string {
|
|||||||
// GetKubernetesClient builds a new kubernetes client. If the KUBECONFIG
|
// GetKubernetesClient builds a new kubernetes client. If the KUBECONFIG
|
||||||
// environment variable is empty or doesn't exist, ~/.kube/config is used for
|
// environment variable is empty or doesn't exist, ~/.kube/config is used for
|
||||||
// the kube config path
|
// the kube config path
|
||||||
func GetKubernetesClient() (*restclient.Config, *kubernetes.Clientset) {
|
func GetKubernetesClient() (*restclient.Config, *kubernetes.Clientset, error) {
|
||||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||||
|
|
||||||
kubeConfigPath := os.Getenv("KUBECONFIG")
|
kubeConfigPath := os.Getenv("KUBECONFIG")
|
||||||
@@ -130,7 +111,7 @@ func GetKubernetesClient() (*restclient.Config, *kubernetes.Clientset) {
|
|||||||
// In case that user.Current() may be unable to work under some circumstances and return errors like
|
// In case that user.Current() may be unable to work under some circumstances and return errors like
|
||||||
// "user: Current not implemented on darwin/amd64" due to cross-compilation problem. (https://github.com/golang/go/issues/6376).
|
// "user: Current not implemented on darwin/amd64" due to cross-compilation problem. (https://github.com/golang/go/issues/6376).
|
||||||
// Instead of doing fatal here, we fallback to get home directory from the environment $HOME.
|
// Instead of doing fatal here, we fallback to get home directory from the environment $HOME.
|
||||||
log.Warn(fmt.Sprintf("Could not get the current user's directory (%s), fallback to get it from env $HOME", err))
|
consolemsg.Warn(fmt.Sprintf("Could not get the current user's directory (%s), fallback to get it from env $HOME", err))
|
||||||
homeDir = os.Getenv("HOME")
|
homeDir = os.Getenv("HOME")
|
||||||
} else {
|
} else {
|
||||||
homeDir = usr.HomeDir
|
homeDir = usr.HomeDir
|
||||||
@@ -138,27 +119,27 @@ func GetKubernetesClient() (*restclient.Config, *kubernetes.Clientset) {
|
|||||||
kubeConfigPath = filepath.Join(homeDir, ".kube", "config")
|
kubeConfigPath = filepath.Join(homeDir, ".kube", "config")
|
||||||
|
|
||||||
if _, err := os.Stat(kubeConfigPath); os.IsNotExist(err) {
|
if _, err := os.Stat(kubeConfigPath); os.IsNotExist(err) {
|
||||||
log.Fatal("Couldn't find kubeconfig file. " +
|
return nil, nil, errors.New("Couldn't find kubeconfig file. " +
|
||||||
"Set the KUBECONFIG environment variable to your kubeconfig's path.")
|
"Set the KUBECONFIG environment variable to your kubeconfig's path.")
|
||||||
}
|
}
|
||||||
loadingRules.ExplicitPath = kubeConfigPath
|
loadingRules.ExplicitPath = kubeConfigPath
|
||||||
log.Verbose(2, "Using kubeconfig from %q", kubeConfigPath)
|
consolemsg.Verbose(2, "Using kubeconfig from %q", kubeConfigPath)
|
||||||
} else {
|
} else {
|
||||||
log.Verbose(2, "Using kubeconfig from environment %q", kubeConfigPath)
|
consolemsg.Verbose(2, "Using kubeconfig from environment %q", kubeConfigPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||||
loadingRules, &clientcmd.ConfigOverrides{}).ClientConfig()
|
loadingRules, &clientcmd.ConfigOverrides{}).ClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Failed to build Kubernetes config: %s", err))
|
return nil, nil, errors.Wrap(err, "Failed to build Kubernetes config")
|
||||||
}
|
}
|
||||||
|
|
||||||
clientset, err := kubernetes.NewForConfig(config)
|
clientset, err := kubernetes.NewForConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Failed to connect to Kubernetes: %s", err))
|
return nil, nil, errors.Wrap(err, "Failed to connect to Kubernetes")
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, clientset
|
return config, clientset, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// given a list of functions, this checks if the functions actually exist on the cluster
|
// given a list of functions, this checks if the functions actually exist on the cluster
|
||||||
@@ -199,7 +180,7 @@ func GetVersion(client *client.Client) info.Versions {
|
|||||||
|
|
||||||
serverInfo, err := client.ServerInfo()
|
serverInfo, err := client.ServerInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(fmt.Sprintf("Error getting Fission API version: %v", err))
|
consolemsg.Warn(fmt.Sprintf("Error getting Fission API version: %v", err))
|
||||||
serverInfo = &info.ServerInfo{}
|
serverInfo = &info.ServerInfo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,3 +193,130 @@ func GetVersion(client *client.Client) info.Versions {
|
|||||||
|
|
||||||
return versions
|
return versions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetServer(flags cli.Input) (c *client.Client, err error) {
|
||||||
|
serverUrl := flags.GlobalString(flag.FISSION_SERVER)
|
||||||
|
if len(serverUrl) == 0 {
|
||||||
|
// starts local portforwarder etc.
|
||||||
|
serverUrl, err = GetApplicationUrl("application=fission-api")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isHTTPS := strings.Index(serverUrl, "https://") == 0
|
||||||
|
isHTTP := strings.Index(serverUrl, "http://") == 0
|
||||||
|
|
||||||
|
if !(isHTTP || isHTTPS) {
|
||||||
|
serverUrl = "http://" + serverUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.MakeClient(serverUrl), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.ResourceRequirements, error) {
|
||||||
|
r := &v1.ResourceRequirements{}
|
||||||
|
|
||||||
|
if resReqs != nil {
|
||||||
|
r.Requests = resReqs.Requests
|
||||||
|
r.Limits = resReqs.Limits
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.Requests) == 0 {
|
||||||
|
r.Requests = make(map[v1.ResourceName]resource.Quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.Limits) == 0 {
|
||||||
|
r.Limits = make(map[v1.ResourceName]resource.Quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
e := &multierror.Error{}
|
||||||
|
|
||||||
|
if flags.IsSet(flag.RUNTIME_MINCPU) {
|
||||||
|
mincpu := flags.Int(flag.RUNTIME_MINCPU)
|
||||||
|
cpuRequest, err := resource.ParseQuantity(strconv.Itoa(mincpu) + "m")
|
||||||
|
if err != nil {
|
||||||
|
e = multierror.Append(e, errors.Wrap(err, "Failed to parse mincpu"))
|
||||||
|
}
|
||||||
|
r.Requests[v1.ResourceCPU] = cpuRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.IsSet(flag.RUNTIME_MINMEMORY) {
|
||||||
|
minmem := flags.Int(flag.RUNTIME_MINMEMORY)
|
||||||
|
memRequest, err := resource.ParseQuantity(strconv.Itoa(minmem) + "Mi")
|
||||||
|
if err != nil {
|
||||||
|
e = multierror.Append(e, errors.Wrap(err, "Failed to parse minmemory"))
|
||||||
|
}
|
||||||
|
r.Requests[v1.ResourceMemory] = memRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.IsSet(flag.RUNTIME_MAXCPU) {
|
||||||
|
maxcpu := flags.Int(flag.RUNTIME_MAXCPU)
|
||||||
|
cpuLimit, err := resource.ParseQuantity(strconv.Itoa(maxcpu) + "m")
|
||||||
|
if err != nil {
|
||||||
|
e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxcpu"))
|
||||||
|
}
|
||||||
|
r.Limits[v1.ResourceCPU] = cpuLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.IsSet(flag.RUNTIME_MAXMEMORY) {
|
||||||
|
maxmem := flags.Int(flag.RUNTIME_MAXMEMORY)
|
||||||
|
memLimit, err := resource.ParseQuantity(strconv.Itoa(maxmem) + "Mi")
|
||||||
|
if err != nil {
|
||||||
|
e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxmemory"))
|
||||||
|
}
|
||||||
|
r.Limits[v1.ResourceMemory] = memLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
limitCPU := r.Limits[v1.ResourceCPU]
|
||||||
|
requestCPU := r.Requests[v1.ResourceCPU]
|
||||||
|
|
||||||
|
if limitCPU.IsZero() && !requestCPU.IsZero() {
|
||||||
|
r.Limits[v1.ResourceCPU] = requestCPU
|
||||||
|
} else if limitCPU.Cmp(requestCPU) < 0 {
|
||||||
|
e = multierror.Append(e, fmt.Errorf("MinCPU (%v) cannot be greater than MaxCPU (%v)", requestCPU.String(), limitCPU.String()))
|
||||||
|
}
|
||||||
|
|
||||||
|
limitMem := r.Limits[v1.ResourceMemory]
|
||||||
|
requestMem := r.Requests[v1.ResourceMemory]
|
||||||
|
|
||||||
|
if limitMem.IsZero() && !requestMem.IsZero() {
|
||||||
|
r.Limits[v1.ResourceMemory] = requestMem
|
||||||
|
} else if limitMem.Cmp(requestMem) < 0 {
|
||||||
|
e = multierror.Append(e, fmt.Errorf("MinMemory (%v) cannot be greater than MaxMemory (%v)", requestMem.String(), limitMem.String()))
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.ErrorOrNil() != nil {
|
||||||
|
return nil, e
|
||||||
|
}
|
||||||
|
|
||||||
|
return &v1.ResourceRequirements{
|
||||||
|
Requests: r.Requests,
|
||||||
|
Limits: r.Limits,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSpecDir(flags cli.Input) string {
|
||||||
|
specDir := flags.String(flag.SPEC_SPECDIR)
|
||||||
|
if len(specDir) == 0 {
|
||||||
|
specDir = "specs"
|
||||||
|
}
|
||||||
|
return specDir
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMetadata returns a pointer to ObjectMeta that is populated with resource name and namespace given by the user.
|
||||||
|
func GetMetadata(nameFlagText string, namespaceFlagText string, flags cli.Input) (*metav1.ObjectMeta, error) {
|
||||||
|
name := flags.String(nameFlagText)
|
||||||
|
if len(name) == 0 {
|
||||||
|
return nil, errors.Errorf("need a resource name, use --%v", nameFlagText)
|
||||||
|
}
|
||||||
|
|
||||||
|
ns := flags.String(namespaceFlagText)
|
||||||
|
|
||||||
|
m := &metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns,
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user