Migrate from urfave/cli to cobra (#1385)
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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 canaryconfig
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a canary config",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.CanaryNameFlag, flag.CanaryTriggerNameFlag, flag.CanaryNewFuncFlag, flag.CanaryOldFuncFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag, flag.CanaryWeightIncrementFlag, flag.CanaryIncrementIntervalFlag, flag.CanaryFailureThresholdFlag},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Aliases: []string{},
|
||||
Short: "View parameters in a canary config",
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.CanaryNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceCanaryFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Aliases: []string{},
|
||||
Short: "Update parameters of a canary config",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.CanaryNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceCanaryFlag, flag.CanaryWeightIncrementFlag, flag.CanaryIncrementIntervalFlag, flag.CanaryFailureThresholdFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{},
|
||||
Short: "Delete a canary config",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.CanaryNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceCanaryFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{},
|
||||
Short: "List canary configs",
|
||||
Long: "List all canary configs in a namespace if specified, else, list canary configs across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceCanaryFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "canary",
|
||||
Aliases: []string{"canary-config"},
|
||||
Short: "Create, Update and manage canary configs",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getCmd, updateCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -21,10 +21,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
@@ -56,13 +58,14 @@ func (opts *CreateSubCommand) do(flags cli.Input) error {
|
||||
func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
// canary configs can be created for functions in the same namespace
|
||||
|
||||
trigger := flags.String("httptrigger")
|
||||
newFunc := flags.String("newfunction")
|
||||
oldFunc := flags.String("oldfunction")
|
||||
ns := flags.String("fnNamespace")
|
||||
incrementStep := flags.Int("increment-step")
|
||||
failureThreshold := flags.Int("failure-threshold")
|
||||
incrementInterval := flags.String("increment-interval")
|
||||
name := flags.String(flagkey.CanaryName)
|
||||
ht := flags.String(flagkey.CanaryHTTPTriggerName)
|
||||
newFunc := flags.String(flagkey.CanaryNewFunc)
|
||||
oldFunc := flags.String(flagkey.CanaryOldFunc)
|
||||
fnNs := flags.String(flagkey.NamespaceFunction)
|
||||
incrementStep := flags.Int(flagkey.CanaryWeightIncrement)
|
||||
failureThreshold := flags.Int(flagkey.CanaryFailureThreshold)
|
||||
incrementInterval := flags.String(flagkey.CanaryIncrementInterval)
|
||||
|
||||
// check for time parsing
|
||||
_, err := time.ParseDuration(incrementInterval)
|
||||
@@ -71,14 +74,12 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
}
|
||||
|
||||
// check that the trigger exists in the same namespace.
|
||||
m, err := util.GetMetadata("httptrigger", "fnNamespace", flags)
|
||||
htTrigger, err := opts.client.HTTPTriggerGet(&metav1.ObjectMeta{
|
||||
Name: ht,
|
||||
Namespace: fnNs,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error finding http trigger in given namespace")
|
||||
}
|
||||
|
||||
htTrigger, err := opts.client.HTTPTriggerGet(m)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error finding trigger referenced in the canary config")
|
||||
return errors.Wrap(err, "error finding http trigger referenced in the canary config")
|
||||
}
|
||||
|
||||
// check that the trigger has function reference type function weights
|
||||
@@ -99,21 +100,19 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
// check that the functions exist in the same namespace
|
||||
fnList := []string{newFunc, oldFunc}
|
||||
err = util.CheckFunctionExistence(opts.client, fnList, ns)
|
||||
err = util.CheckFunctionExistence(opts.client, fnList, fnNs)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error checking functions existence")
|
||||
}
|
||||
|
||||
canaryMetadata, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// finally create canaryCfg in the same namespace as the functions referenced
|
||||
opts.canary = &fv1.CanaryConfig{
|
||||
Metadata: *canaryMetadata,
|
||||
Metadata: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: fnNs,
|
||||
},
|
||||
Spec: fv1.CanaryConfigSpec{
|
||||
Trigger: trigger,
|
||||
Trigger: ht,
|
||||
NewFunction: newFunc,
|
||||
OldFunction: oldFunc,
|
||||
WeightIncrement: incrementStep,
|
||||
|
||||
@@ -20,9 +20,11 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -30,27 +32,28 @@ type DeleteSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Delete(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Delete(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := DeleteSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(flags cli.Input) error {
|
||||
metadata, err := util.GetMetadata("name", "canaryNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) error {
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.CanaryName),
|
||||
Namespace: input.String(flagkey.NamespaceCanary),
|
||||
}
|
||||
err = opts.client.CanaryConfigDelete(metadata)
|
||||
|
||||
err := opts.client.CanaryConfigDelete(m)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting canary config")
|
||||
}
|
||||
|
||||
fmt.Printf("canaryconfig '%v.%v' deleted\n", metadata.Name, metadata.Namespace)
|
||||
fmt.Printf("canaryconfig '%v.%v' deleted\n", m.Name, m.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -22,9 +22,11 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -32,24 +34,22 @@ type GetSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Get(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Get(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) run(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "canaryNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
canaryCfg, err := opts.client.CanaryConfigGet(m)
|
||||
func (opts *GetSubCommand) run(input cli.Input) error {
|
||||
canaryCfg, err := opts.client.CanaryConfigGet(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.CanaryName),
|
||||
Namespace: input.String(flagkey.NamespaceCanary),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting canary config")
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -33,27 +34,27 @@ type ListSubCommand struct {
|
||||
namespace string
|
||||
}
|
||||
|
||||
func List(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func List(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) complete(flags cli.Input) error {
|
||||
opts.namespace = flags.String("canaryNamespace")
|
||||
opts.namespace = flags.String(flagkey.NamespaceCanary)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -33,43 +35,43 @@ type UpdateSubCommand struct {
|
||||
canary *fv1.CanaryConfig
|
||||
}
|
||||
|
||||
func Update(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Update(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := UpdateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
// get the current config
|
||||
m, err := util.GetMetadata("name", "canaryNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
incrementStep := flags.Int("increment-step")
|
||||
failureThreshold := flags.Int("failure-threshold")
|
||||
incrementInterval := flags.String("increment-interval")
|
||||
name := input.String(flagkey.CanaryName)
|
||||
ns := input.String(flagkey.NamespaceCanary)
|
||||
incrementStep := input.Int(flagkey.CanaryWeightIncrement)
|
||||
failureThreshold := input.Int(flagkey.CanaryFailureThreshold)
|
||||
incrementInterval := input.String(flagkey.CanaryIncrementInterval)
|
||||
|
||||
// check for time parsing
|
||||
_, err = time.ParseDuration(incrementInterval)
|
||||
_, err := time.ParseDuration(incrementInterval)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error parsing time duration")
|
||||
}
|
||||
|
||||
canaryCfg, err := opts.client.CanaryConfigGet(m)
|
||||
canaryCfg, err := opts.client.CanaryConfigGet(&metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: ns,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting canary config")
|
||||
}
|
||||
@@ -97,7 +99,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.client.CanaryConfigUpdate(opts.canary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating canary config")
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
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 environment
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create an environment",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.EnvNameFlag, flag.EnvImageFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceEnvironmentFlag, flag.EnvPoolsizeFlag,
|
||||
flag.EnvBuilderImageFlag, flag.EnvBuildCmdFlag, flag.EnvKeepArchiveFlag,
|
||||
flag.RunTimeMinCPUFlag, flag.RunTimeMaxCPUFlag, flag.RunTimeMinMemoryFlag, flag.RunTimeMaxMemoryFlag,
|
||||
flag.EnvVersionFlag, flag.EnvExternalNetworkFlag, flag.EnvTerminationGracePeriodFlag, flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "Get environment details",
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.EnvNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceEnvironmentFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update an environment",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.EnvNameFlag},
|
||||
Optional: []flag.Flag{flag.EnvImageFlag, flag.NamespaceEnvironmentFlag, flag.EnvPoolsizeFlag,
|
||||
flag.EnvBuilderImageFlag, flag.EnvBuildCmdFlag, flag.EnvKeepArchiveFlag,
|
||||
flag.EnvExternalNetworkFlag, flag.EnvTerminationGracePeriodFlag, flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete an environment",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.EnvNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceEnvironmentFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List environments",
|
||||
Long: "List all environments in a namespace if specified, else, list environments across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceEnvironmentFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "environment",
|
||||
Aliases: []string{"env"},
|
||||
Short: "Create, update and manage environments",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getCmd, updateCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -27,9 +27,10 @@ import (
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
type CreateSubCommand struct {
|
||||
@@ -37,28 +38,28 @@ type CreateSubCommand struct {
|
||||
env *fv1.Environment
|
||||
}
|
||||
|
||||
func Create(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Create(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := CreateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
// complete creates a environment objects and populates it with default value and CLI inputs.
|
||||
func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
env, err := createEnvironmentFromCmd(flags)
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
env, err := createEnvironmentFromCmd(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -68,23 +69,21 @@ 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.
|
||||
// It also prints warning/error if necessary.
|
||||
func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
m := opts.env.Metadata
|
||||
|
||||
envList, err := opts.client.EnvironmentList(m.Namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if len(envList) > 0 {
|
||||
consolemsg.Verbose(2, "%d environment(s) are present in the %s namespace. "+
|
||||
console.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.",
|
||||
len(envList), m.Namespace)
|
||||
}
|
||||
|
||||
// if we're writing a spec, don't call the API
|
||||
// save to spec file
|
||||
if flags.Bool(flag.SPEC_SPEC) {
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specFile := fmt.Sprintf("env-%v.yaml", m.Name)
|
||||
err = spec.SpecSave(*opts.env, specFile)
|
||||
if err != nil {
|
||||
@@ -103,39 +102,33 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||
}
|
||||
|
||||
// createEnvironmentFromCmd creates environment initialized with CLI input.
|
||||
func createEnvironmentFromCmd(flags cli.Input) (*fv1.Environment, error) {
|
||||
e := &multierror.Error{}
|
||||
func createEnvironmentFromCmd(input cli.Input) (*fv1.Environment, error) {
|
||||
e := utils.MultiErrorWithFormat()
|
||||
|
||||
envNamespace := flags.String(flag.ENVIRONMENT_NAMESPACE)
|
||||
envBuildCmd := flags.String(flag.ENVIRONMENT_BUILDCOMMAND)
|
||||
envExternalNetwork := flags.Bool(flag.ENVIRONMENT_EXTERNAL_NETWORK)
|
||||
keepArchive := flags.Bool(flag.ENVIRONMENT_KEEPARCHIVE)
|
||||
envName := input.String(flagkey.EnvName)
|
||||
envImg := input.String(flagkey.EnvImage)
|
||||
envNamespace := input.String(flagkey.NamespaceEnvironment)
|
||||
envBuildCmd := input.String(flagkey.EnvBuildcommand)
|
||||
envExternalNetwork := input.Bool(flagkey.EnvExternalNetwork)
|
||||
keepArchive := input.Bool(flagkey.EnvKeeparchive)
|
||||
envGracePeriod := input.Int64(flagkey.EnvGracePeriod)
|
||||
|
||||
envName := flags.String(flag.RESOURCE_NAME)
|
||||
if len(envName) == 0 {
|
||||
e = multierror.Append(e, errors.New("Need a name, use --name."))
|
||||
}
|
||||
|
||||
envImg := flags.String(flag.ENVIRONMENT_IMAGE)
|
||||
if len(envImg) == 0 {
|
||||
e = multierror.Append(e, errors.New("Need an image, use --image."))
|
||||
}
|
||||
|
||||
envGracePeriod := flags.Int64(flag.ENVIRONMENT_GRACE_PERIOD)
|
||||
if envGracePeriod <= 0 {
|
||||
envGracePeriod = 360
|
||||
}
|
||||
|
||||
envVersion := flags.Int(flag.ENVIRONMENT_VERSION)
|
||||
envVersion := input.Int(flagkey.EnvVersion)
|
||||
// Environment API interface version is not specified and
|
||||
// builder image is empty, set default interface version
|
||||
if envVersion == 0 {
|
||||
envVersion = 1
|
||||
}
|
||||
|
||||
envBuilderImg := flags.String(flag.ENVIRONMENT_BUILDER)
|
||||
poolsize := input.Int(flagkey.EnvPoolsize)
|
||||
if input.IsSet(flagkey.EnvPoolsize) {
|
||||
// TODO: remove silently version 3 assignment, we need to warn user to set it explicitly.
|
||||
envVersion = 3
|
||||
}
|
||||
|
||||
envBuilderImg := input.String(flagkey.EnvBuilderImage)
|
||||
if len(envBuilderImg) > 0 {
|
||||
if !flags.IsSet(flag.ENVIRONMENT_VERSION) {
|
||||
if !input.IsSet(flagkey.EnvVersion) {
|
||||
// TODO: remove set env version to 2 silently, we need to warn user to set it explicitly.
|
||||
envVersion = 2
|
||||
}
|
||||
@@ -144,14 +137,7 @@ func createEnvironmentFromCmd(flags cli.Input) (*fv1.Environment, error) {
|
||||
}
|
||||
}
|
||||
|
||||
poolsize := 3
|
||||
if flags.IsSet(flag.ENVIRONMENT_POOLSIZE) {
|
||||
poolsize = flags.Int(flag.ENVIRONMENT_POOLSIZE)
|
||||
// TODO: remove silently version 3 assignment, we need to warn user to set it explicitly.
|
||||
envVersion = 3
|
||||
}
|
||||
|
||||
resourceReq, err := util.GetResourceReqs(flags, nil)
|
||||
resourceReq, err := util.GetResourceReqs(input, nil)
|
||||
if err != nil {
|
||||
e = multierror.Append(e, err)
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
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/flag"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -31,24 +32,24 @@ type DeleteSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Delete(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Delete(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := DeleteSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
||||
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||
if err != nil {
|
||||
return err
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.EnvName),
|
||||
Namespace: input.String(flagkey.NamespaceEnvironment),
|
||||
}
|
||||
|
||||
err = opts.client.EnvironmentDelete(m)
|
||||
err := opts.client.EnvironmentDelete(m)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting environment")
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
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/flag"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -33,21 +34,21 @@ type GetSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Get(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Get(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) do(flags cli.Input) error {
|
||||
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||
if err != nil {
|
||||
return err
|
||||
func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.EnvName),
|
||||
Namespace: input.String(flagkey.NamespaceEnvironment),
|
||||
}
|
||||
|
||||
env, err := opts.client.EnvironmentGet(m)
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -33,21 +33,19 @@ type ListSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func List(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func List(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(flags cli.Input) error {
|
||||
envNamespace := flags.String(flag.ENVIRONMENT_NAMESPACE)
|
||||
|
||||
envs, err := opts.client.EnvironmentList(envNamespace)
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
envs, err := opts.client.EnvironmentList(input.String(flagkey.NamespaceEnvironment))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing environments")
|
||||
}
|
||||
|
||||
@@ -21,12 +21,14 @@ import (
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
type UpdateSubCommand struct {
|
||||
@@ -34,37 +36,35 @@ type UpdateSubCommand struct {
|
||||
env *fv1.Environment
|
||||
}
|
||||
|
||||
func Update(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Update(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := UpdateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
m, err := util.GetMetadata(flag.RESOURCE_NAME, flag.ENVIRONMENT_NAMESPACE, flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
env, err := opts.client.EnvironmentGet(m)
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
env, err := opts.client.EnvironmentGet(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.EnvName),
|
||||
Namespace: input.String(flagkey.NamespaceEnvironment),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error finding environment")
|
||||
}
|
||||
|
||||
env, err = updateExistingEnvironmentWithCmd(env, flags)
|
||||
env, err = updateExistingEnvironmentWithCmd(env, input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.client.EnvironmentUpdate(opts.env)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating environment")
|
||||
@@ -84,13 +84,13 @@ func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
||||
}
|
||||
|
||||
// updateExistingEnvironmentWithCmd updates a existing environment's value based on CLI input.
|
||||
func updateExistingEnvironmentWithCmd(env *fv1.Environment, flags cli.Input) (*fv1.Environment, error) {
|
||||
e := &multierror.Error{}
|
||||
func updateExistingEnvironmentWithCmd(env *fv1.Environment, input cli.Input) (*fv1.Environment, error) {
|
||||
e := utils.MultiErrorWithFormat()
|
||||
|
||||
envImg := flags.String(flag.ENVIRONMENT_IMAGE)
|
||||
envBuilderImg := flags.String(flag.ENVIRONMENT_BUILDER)
|
||||
envBuildCmd := flags.String(flag.ENVIRONMENT_BUILDCOMMAND)
|
||||
envExternalNetwork := flags.Bool(flag.ENVIRONMENT_EXTERNAL_NETWORK)
|
||||
envImg := input.String(flagkey.EnvImage)
|
||||
envBuilderImg := input.String(flagkey.EnvBuilderImage)
|
||||
envBuildCmd := input.String(flagkey.EnvBuildcommand)
|
||||
envExternalNetwork := input.Bool(flagkey.EnvExternalNetwork)
|
||||
|
||||
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"))
|
||||
@@ -111,25 +111,26 @@ func updateExistingEnvironmentWithCmd(env *fv1.Environment, flags cli.Input) (*f
|
||||
env.Spec.Builder.Command = envBuildCmd
|
||||
}
|
||||
|
||||
if flags.IsSet(flag.ENVIRONMENT_POOLSIZE) {
|
||||
env.Spec.Poolsize = flags.Int(flag.ENVIRONMENT_POOLSIZE)
|
||||
if input.IsSet(flagkey.EnvPoolsize) {
|
||||
env.Spec.Poolsize = input.Int(flagkey.EnvPoolsize)
|
||||
}
|
||||
|
||||
if flags.IsSet(flag.ENVIRONMENT_GRACE_PERIOD) {
|
||||
env.Spec.TerminationGracePeriod = flags.Int64(flag.ENVIRONMENT_GRACE_PERIOD)
|
||||
if input.IsSet(flagkey.EnvGracePeriod) {
|
||||
env.Spec.TerminationGracePeriod = input.Int64(flagkey.EnvGracePeriod)
|
||||
}
|
||||
|
||||
if flags.IsSet(flag.ENVIRONMENT_KEEPARCHIVE) {
|
||||
env.Spec.KeepArchive = flags.Bool(flag.ENVIRONMENT_KEEPARCHIVE)
|
||||
if input.IsSet(flagkey.EnvKeeparchive) {
|
||||
env.Spec.KeepArchive = input.Bool(flagkey.EnvKeeparchive)
|
||||
}
|
||||
|
||||
env.Spec.AllowAccessToExternalNetwork = envExternalNetwork
|
||||
|
||||
if flags.IsSet(flag.RUNTIME_MINCPU) || flags.IsSet(flag.RUNTIME_MAXCPU) ||
|
||||
flags.IsSet(flag.RUNTIME_MINMEMORY) || flags.IsSet(flag.RUNTIME_MAXMEMORY) ||
|
||||
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"))
|
||||
}
|
||||
// TODO: allow to update resource.
|
||||
//if input.IsSet(flagkey.RuntimeMincpu) || input.IsSet(flagkey.RuntimeMaxcpu) ||
|
||||
// input.IsSet(flagkey.RuntimeMinmemory) || input.IsSet(flagkey.RuntimeMaxmemory) ||
|
||||
// input.IsSet(flagkey.ReplicasMinscale) || input.IsSet(flagkey.ReplicasMaxscale) {
|
||||
// e = multierror.Append(e, errors.New("updating resource limits/requests for existing environments is currently unsupported; re-create the environment instead"))
|
||||
//}
|
||||
|
||||
if e.ErrorOrNil() != nil {
|
||||
return nil, e.ErrorOrNil()
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
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 function
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a function (and optionally, an HTTP route to it)",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.FnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag, flag.NamespaceEnvironmentFlag, flag.SpecSaveFlag,
|
||||
flag.FnEnvNameFlag, flag.FnCodeFlag, flag.PkgSrcArchiveFlag, flag.PkgDeployArchiveFlag, flag.FnKeepURLFlag,
|
||||
flag.FnEntryPointFlag, flag.FnBuildCmdFlag, flag.FnPkgNameFlag, flag.HtUrlFlag, flag.HtMethodFlag,
|
||||
flag.RunTimeMinCPUFlag, flag.RunTimeMaxCPUFlag, flag.RunTimeMinMemoryFlag, flag.RunTimeMaxMemoryFlag,
|
||||
flag.ReplicasMinFlag, flag.ReplicasMaxFlag, flag.FnExecutorTypeFlag, flag.RunTimeTargetCPUFlag,
|
||||
flag.FnCfgMapFlag, flag.FnSecretFlag, flag.FnSpecializationTimeoutFlag, flag.FnExecutionTimeoutFlag},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Aliases: []string{},
|
||||
Short: "Get function source code",
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.FnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
|
||||
})
|
||||
|
||||
getmetaCmd := &cobra.Command{
|
||||
Use: "getmeta",
|
||||
Aliases: []string{},
|
||||
Short: "Get function metadata",
|
||||
RunE: wrapper.Wrapper(GetMeta),
|
||||
}
|
||||
wrapper.SetFlags(getmetaCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.FnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Aliases: []string{},
|
||||
Short: "Update a function",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.FnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag, flag.NamespaceEnvironmentFlag, flag.SpecSaveFlag,
|
||||
flag.FnCodeFlag, flag.PkgSrcArchiveFlag, flag.PkgDeployArchiveFlag,
|
||||
flag.FnKeepURLFlag, flag.FnEntryPointFlag, flag.FnBuildCmdFlag, flag.FnPkgNameFlag, flag.HtUrlFlag,
|
||||
flag.HtMethodFlag, flag.RunTimeMinCPUFlag, flag.RunTimeMaxCPUFlag, flag.RunTimeMinMemoryFlag,
|
||||
flag.RunTimeMaxMemoryFlag, flag.ReplicasMinFlag, flag.ReplicasMaxFlag, flag.FnExecutorTypeFlag,
|
||||
flag.RunTimeTargetCPUFlag, flag.FnCfgMapFlag, flag.FnSecretFlag, flag.FnSpecializationTimeoutFlag,
|
||||
flag.FnExecutionTimeoutFlag, flag.PkgForceFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{},
|
||||
Short: "Delete a function",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.FnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{},
|
||||
Short: "List all functions in a namespace if specified, else, list functions across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
|
||||
})
|
||||
|
||||
logsCmd := &cobra.Command{
|
||||
Use: "log",
|
||||
Aliases: []string{"logs"},
|
||||
Short: "Display function logs",
|
||||
RunE: wrapper.Wrapper(Log),
|
||||
}
|
||||
wrapper.SetFlags(logsCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.FnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag, flag.FnLogPodFlag, flag.FnLogFollowFlag,
|
||||
flag.FnLogDetailFlag, flag.FnLogDBTypeFlag, flag.FnLogReverseQueryFlag, flag.FnLogCountFlag},
|
||||
})
|
||||
|
||||
testCmd := &cobra.Command{
|
||||
Use: "test",
|
||||
Aliases: []string{},
|
||||
Short: "Test a function",
|
||||
RunE: wrapper.Wrapper(Test),
|
||||
}
|
||||
wrapper.SetFlags(testCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.FnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag, flag.HtMethodFlag, flag.FnTestBodyFlag,
|
||||
flag.FnTestHeaderFlag, flag.FnTestQueryFlag, flag.FnTestTimeoutFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "function",
|
||||
Aliases: []string{"fn"},
|
||||
Short: "Create, update and manage functions",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getCmd, getmetaCmd, updateCmd, deleteCmd, listCmd, logsCmd, testCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -33,7 +33,8 @@ import (
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
||||
_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/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
@@ -49,44 +50,40 @@ type CreateSubCommand struct {
|
||||
specFile string
|
||||
}
|
||||
|
||||
func Create(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Create(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := CreateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
fnNamespace := flags.String("fnNamespace")
|
||||
envNamespace := flags.String("envNamespace")
|
||||
|
||||
fnName := flags.String("name")
|
||||
if len(fnName) == 0 {
|
||||
return errors.New("need --name argument")
|
||||
}
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
fnName := input.String(flagkey.FnName)
|
||||
fnNamespace := input.String(flagkey.NamespaceFunction)
|
||||
envNamespace := input.String(flagkey.NamespaceEnvironment)
|
||||
|
||||
// user wants a spec, create a yaml file with package and function
|
||||
toSpec := false
|
||||
if flags.Bool("spec") {
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
toSpec = true
|
||||
opts.specFile = fmt.Sprintf("function-%v.yaml", fnName)
|
||||
}
|
||||
specDir := util.GetSpecDir(flags)
|
||||
specDir := util.GetSpecDir(input)
|
||||
|
||||
// check for unique function names within a namespace
|
||||
metadata, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
metadata, err := util.GetMetadata(flagkey.FnName, flagkey.NamespaceFunction, input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -98,23 +95,23 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
return errors.New("a function with the same name already exists")
|
||||
}
|
||||
|
||||
entrypoint := flags.String("entrypoint")
|
||||
entrypoint := input.String(flagkey.FnEntrypoint)
|
||||
|
||||
fnTimeout := flags.Int("fntimeout")
|
||||
fnTimeout := input.Int(flagkey.FnExecutionTimeout)
|
||||
if fnTimeout <= 0 {
|
||||
return errors.New("fntimeout must be greater than 0")
|
||||
}
|
||||
|
||||
pkgName := flags.String("pkg")
|
||||
pkgName := input.String(flagkey.FnPackageName)
|
||||
|
||||
secretNames := flags.StringSlice("secret")
|
||||
cfgMapNames := flags.StringSlice("configmap")
|
||||
secretNames := input.StringSlice(flagkey.FnSecret)
|
||||
cfgMapNames := input.StringSlice(flagkey.FnCfgMap)
|
||||
|
||||
invokeStrategy, err := getInvokeStrategy(flags, nil)
|
||||
invokeStrategy, err := getInvokeStrategy(input, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resourceReq, err := util.GetResourceReqs(flags, &apiv1.ResourceRequirements{})
|
||||
resourceReq, err := util.GetResourceReqs(input, &apiv1.ResourceRequirements{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -132,13 +129,13 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
}
|
||||
pkgMetadata = &pkg.Metadata
|
||||
envName = pkg.Spec.Environment.Name
|
||||
if envName != flags.String("env") {
|
||||
consolemsg.Warn("Function's environment is different than package's environment, package's environment will be used for creating function")
|
||||
if envName != input.String(flagkey.FnEnvironmentName) {
|
||||
console.Warn("Function's environment is different than package's environment, package's environment will be used for creating function")
|
||||
}
|
||||
envNamespace = pkg.Spec.Environment.Namespace
|
||||
} else {
|
||||
// need to specify environment for creating new package
|
||||
envName = flags.String("env")
|
||||
envName = input.String(flagkey.FnEnvironmentName)
|
||||
if len(envName) == 0 {
|
||||
return errors.New("need --env argument")
|
||||
}
|
||||
@@ -151,21 +148,21 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
})
|
||||
if err != nil {
|
||||
if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNotFound {
|
||||
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))
|
||||
console.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 {
|
||||
return errors.Wrap(err, "error retrieving environment information")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
srcArchiveFiles := flags.StringSlice("src")
|
||||
srcArchiveFiles := input.StringSlice(flagkey.PkgSrcArchive)
|
||||
var deployArchiveFiles []string
|
||||
noZip := false
|
||||
code := flags.String("code")
|
||||
code := input.String(flagkey.FnCode)
|
||||
if len(code) == 0 {
|
||||
deployArchiveFiles = flags.StringSlice("deploy")
|
||||
deployArchiveFiles = input.StringSlice(flagkey.PkgDeployArchive)
|
||||
} else {
|
||||
deployArchiveFiles = append(deployArchiveFiles, flags.String("code"))
|
||||
deployArchiveFiles = append(deployArchiveFiles, input.String(flagkey.FnCode))
|
||||
noZip = true
|
||||
}
|
||||
// return error when both src & deploy archive are empty
|
||||
@@ -173,11 +170,11 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
return errors.New("need --code or --deploy or --src argument")
|
||||
}
|
||||
|
||||
buildcmd := flags.String("buildcmd")
|
||||
keepURL := flags.Bool("keepurl")
|
||||
buildcmd := input.String(flagkey.PkgBuildCmd)
|
||||
keepURL := input.Bool(flagkey.PkgKeepURL)
|
||||
|
||||
// create new package in the same namespace as the function.
|
||||
pkgMetadata, err = _package.CreatePackage(flags, opts.client, fnNamespace, envName, envNamespace,
|
||||
pkgMetadata, err = _package.CreatePackage(input, opts.client, fnNamespace, envName, envNamespace,
|
||||
srcArchiveFiles, deployArchiveFiles, buildcmd, specDir, opts.specFile, noZip, keepURL)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating package")
|
||||
@@ -196,7 +193,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
})
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
consolemsg.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
console.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
} else {
|
||||
return errors.Wrap(err, "error checking secret")
|
||||
}
|
||||
@@ -220,7 +217,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
})
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
consolemsg.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
||||
console.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
||||
} else {
|
||||
return errors.Wrap(err, "error checking configmap")
|
||||
}
|
||||
@@ -268,7 +265,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
// It also prints warning/error if necessary.
|
||||
func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||
// if we're writing a spec, don't create the function
|
||||
if flags.Bool("spec") {
|
||||
if flags.Bool(flagkey.SpecSave) {
|
||||
err := spec.SpecSave(*opts.function, opts.specFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating function spec")
|
||||
@@ -284,7 +281,7 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||
fmt.Printf("function '%v' created\n", opts.function.Metadata.Name)
|
||||
|
||||
// Allow the user to specify an HTTP trigger while creating a function.
|
||||
triggerUrl := flags.String("url")
|
||||
triggerUrl := flags.String(flagkey.HtUrl)
|
||||
if len(triggerUrl) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -292,7 +289,7 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||
triggerUrl = fmt.Sprintf("/%s", triggerUrl)
|
||||
}
|
||||
|
||||
method, err := httptrigger.GetMethod(flags.String("method"))
|
||||
method, err := httptrigger.GetMethod(flags.String(flagkey.HtMethod))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting HTTP trigger method")
|
||||
}
|
||||
@@ -325,7 +322,7 @@ func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrate
|
||||
|
||||
var fnExecutor, newFnExecutor fv1.ExecutorType
|
||||
|
||||
switch flags.String("executortype") {
|
||||
switch flags.String(flagkey.FnExecutorType) {
|
||||
case "":
|
||||
fallthrough
|
||||
case types.ExecutorTypePoolmgr:
|
||||
@@ -340,24 +337,24 @@ func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrate
|
||||
fnExecutor = existingInvokeStrategy.ExecutionStrategy.ExecutorType
|
||||
|
||||
// override the executor type if user specified a new executor type
|
||||
if flags.IsSet("executortype") {
|
||||
if flags.IsSet(flagkey.FnExecutorType) {
|
||||
fnExecutor = newFnExecutor
|
||||
}
|
||||
} else {
|
||||
fnExecutor = newFnExecutor
|
||||
}
|
||||
|
||||
if flags.IsSet("specializationtimeout") && fnExecutor != types.ExecutorTypeNewdeploy {
|
||||
return nil, errors.New("specializationtimeout flag is only applicable for newdeploy type of executor")
|
||||
if flags.IsSet(flagkey.FnSpecializationTimeout) && fnExecutor != types.ExecutorTypeNewdeploy {
|
||||
return nil, errors.Errorf("%v flag is only applicable for newdeploy type of executor", flagkey.FnSpecializationTimeout)
|
||||
}
|
||||
|
||||
if fnExecutor == types.ExecutorTypePoolmgr {
|
||||
if flags.IsSet("targetcpu") || flags.IsSet("minscale") || flags.IsSet("maxscale") {
|
||||
if flags.IsSet(flagkey.RuntimeTargetcpu) || flags.IsSet(flagkey.ReplicasMinscale) || flags.IsSet(flagkey.ReplicasMaxscale) {
|
||||
return nil, errors.New("to set target CPU or min/max scale for function, please specify \"--executortype newdeploy\"")
|
||||
}
|
||||
|
||||
if flags.IsSet("mincpu") || flags.IsSet("maxcpu") || flags.IsSet("minmemory") || flags.IsSet("maxmemory") {
|
||||
consolemsg.Warn("To limit CPU/Memory for function with executor type \"poolmgr\", please specify resources limits when creating environment")
|
||||
if flags.IsSet(flagkey.RuntimeMincpu) || flags.IsSet(flagkey.RuntimeMaxcpu) || flags.IsSet(flagkey.RuntimeMinmemory) || flags.IsSet(flagkey.RuntimeMaxmemory) {
|
||||
console.Warn("To limit CPU/Memory for function with executor type \"poolmgr\", please specify resources limits when creating environment")
|
||||
}
|
||||
strategy = &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
@@ -379,33 +376,33 @@ func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrate
|
||||
specializationTimeout = existingInvokeStrategy.ExecutionStrategy.SpecializationTimeout
|
||||
}
|
||||
|
||||
if flags.IsSet("targetcpu") {
|
||||
if flags.IsSet(flagkey.RuntimeTargetcpu) {
|
||||
targetCPU, err = getTargetCPU(flags)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if flags.IsSet("minscale") {
|
||||
minScale = flags.Int("minscale")
|
||||
if flags.IsSet(flagkey.ReplicasMinscale) {
|
||||
minScale = flags.Int(flagkey.ReplicasMinscale)
|
||||
}
|
||||
|
||||
if flags.IsSet("maxscale") {
|
||||
maxScale = flags.Int("maxscale")
|
||||
if flags.IsSet(flagkey.ReplicasMaxscale) {
|
||||
maxScale = flags.Int(flagkey.ReplicasMaxscale)
|
||||
if maxScale <= 0 {
|
||||
return nil, errors.New("maxscale must be greater than 0")
|
||||
return nil, errors.Errorf("%v must be greater than 0", flagkey.ReplicasMaxscale)
|
||||
}
|
||||
}
|
||||
|
||||
if flags.IsSet("specializationtimeout") {
|
||||
specializationTimeout = flags.Int("specializationtimeout")
|
||||
if flags.IsSet(flagkey.FnSpecializationTimeout) {
|
||||
specializationTimeout = flags.Int(flagkey.FnSpecializationTimeout)
|
||||
if specializationTimeout < fv1.DefaultSpecializationTimeOut {
|
||||
return nil, errors.New("specializationtimeout must be greater than or equal to 120 seconds")
|
||||
return nil, errors.Errorf("%v must be greater than or equal to 120 seconds", flagkey.FnSpecializationTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
if minScale > maxScale {
|
||||
return nil, fmt.Errorf("minscale provided: %v can not be greater than maxscale value %v", minScale, maxScale)
|
||||
return nil, fmt.Errorf("minscale (%v) can not be greater than maxscale (%v)", minScale, maxScale)
|
||||
}
|
||||
|
||||
// Right now a simple single case strategy implementation
|
||||
@@ -426,14 +423,9 @@ func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrate
|
||||
}
|
||||
|
||||
func getTargetCPU(flags cli.Input) (int, error) {
|
||||
var targetCPU int
|
||||
if flags.IsSet("targetcpu") {
|
||||
targetCPU = flags.Int("targetcpu")
|
||||
if targetCPU <= 0 || targetCPU > 100 {
|
||||
return 0, errors.New("TargetCPU must be a value between 1 - 100")
|
||||
}
|
||||
} else {
|
||||
targetCPU = DEFAULT_TARGET_CPU_PERCENTAGE
|
||||
targetCPU := flags.Int(flagkey.RuntimeTargetcpu)
|
||||
if targetCPU <= 0 || targetCPU > 100 {
|
||||
return 0, errors.Errorf("%v must be a value between 1 - 100", flagkey.RuntimeTargetcpu)
|
||||
}
|
||||
return targetCPU, nil
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -30,24 +32,24 @@ type DeleteSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Delete(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Delete(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := DeleteSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: input.String(flagkey.NamespaceFunction),
|
||||
}
|
||||
|
||||
err = opts.client.FunctionDelete(m)
|
||||
err := opts.client.FunctionDelete(m)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("delete function '%v'", m.Name))
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package function
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -47,7 +48,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// case: executor type set to poolmgr
|
||||
testArgs: map[string]interface{}{"executortype": fv1.ExecutorTypePoolmgr},
|
||||
testArgs: map[string]interface{}{flagkey.FnExecutorType: fv1.ExecutorTypePoolmgr},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
@@ -59,7 +60,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// case: executor type set to newdeploy
|
||||
testArgs: map[string]interface{}{"executortype": fv1.ExecutorTypeNewdeploy},
|
||||
testArgs: map[string]interface{}{flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
@@ -75,7 +76,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// case: executor type change from poolmgr to newdeploy
|
||||
testArgs: map[string]interface{}{"executortype": fv1.ExecutorTypeNewdeploy},
|
||||
testArgs: map[string]interface{}{flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy},
|
||||
existingInvokeStrategy: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
ExecutionStrategy: fv1.ExecutionStrategy{
|
||||
@@ -96,7 +97,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// case: executor type change from newdeploy to poolmgr
|
||||
testArgs: map[string]interface{}{"executortype": fv1.ExecutorTypePoolmgr},
|
||||
testArgs: map[string]interface{}{flagkey.FnExecutorType: fv1.ExecutorTypePoolmgr},
|
||||
existingInvokeStrategy: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
ExecutionStrategy: fv1.ExecutionStrategy{
|
||||
@@ -118,9 +119,9 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: minscale < maxscale
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"minscale": 2,
|
||||
"maxscale": 3,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.ReplicasMinscale: 2,
|
||||
flagkey.ReplicasMaxscale: 3,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: &fv1.InvokeStrategy{
|
||||
@@ -138,9 +139,9 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: minscale > maxscale
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"minscale": 5,
|
||||
"maxscale": 3,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.ReplicasMinscale: 5,
|
||||
flagkey.ReplicasMaxscale: 3,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: nil,
|
||||
@@ -149,8 +150,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: maxscale not specified
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"minscale": 5,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.ReplicasMinscale: 5,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: nil,
|
||||
@@ -159,8 +160,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: minscale not specified
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"maxscale": 3,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.ReplicasMaxscale: 3,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: &fv1.InvokeStrategy{
|
||||
@@ -178,8 +179,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: maxscale set to 0
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"maxscale": 0,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.ReplicasMaxscale: 0,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: nil,
|
||||
@@ -188,8 +189,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: maxscale set to 9 when existing is 5
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"maxscale": 9,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.ReplicasMaxscale: 9,
|
||||
},
|
||||
existingInvokeStrategy: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
@@ -216,7 +217,7 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: change nothing for existing strategy
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
},
|
||||
existingInvokeStrategy: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
@@ -243,8 +244,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: set target cpu percentage
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"targetcpu": 50,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.RuntimeTargetcpu: 50,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: &fv1.InvokeStrategy{
|
||||
@@ -262,8 +263,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: change target cpu percentage
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"targetcpu": 20,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.RuntimeTargetcpu: 20,
|
||||
},
|
||||
existingInvokeStrategy: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
@@ -290,8 +291,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: change specializationtimeout
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"specializationtimeout": 200,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.FnSpecializationTimeout: 200,
|
||||
},
|
||||
existingInvokeStrategy: &fv1.InvokeStrategy{
|
||||
StrategyType: fv1.StrategyTypeExecution,
|
||||
@@ -317,8 +318,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: specializationtimeout should not work for poolmgr
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypePoolmgr,
|
||||
"specializationtimeout": 10,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypePoolmgr,
|
||||
flagkey.FnSpecializationTimeout: 10,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: nil,
|
||||
@@ -327,8 +328,8 @@ func TestGetInvokeStrategy(t *testing.T) {
|
||||
{
|
||||
// case: specializationtimeout should not be less than 120
|
||||
testArgs: map[string]interface{}{
|
||||
"executortype": fv1.ExecutorTypeNewdeploy,
|
||||
"specializationtimeout": 90,
|
||||
flagkey.FnExecutorType: fv1.ExecutorTypeNewdeploy,
|
||||
flagkey.FnSpecializationTimeout: 90,
|
||||
},
|
||||
existingInvokeStrategy: nil,
|
||||
expectedResult: nil,
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -31,24 +32,22 @@ type GetSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Get(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Get(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) do(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fn, err := opts.client.FunctionGet(m)
|
||||
func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
fn, err := opts.client.FunctionGet(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: input.String(flagkey.NamespaceFunction),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function")
|
||||
}
|
||||
|
||||
@@ -22,9 +22,11 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -32,24 +34,22 @@ type GetMetaSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func GetMeta(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func GetMeta(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetMetaSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *GetMetaSubCommand) do(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fn, err := opts.client.FunctionGet(m)
|
||||
func (opts *GetMetaSubCommand) do(input cli.Input) error {
|
||||
fn, err := opts.client.FunctionGet(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: input.String(flagkey.NamespaceFunction),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function")
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -33,19 +34,19 @@ type ListSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func List(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func List(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(flags cli.Input) error {
|
||||
ns := flags.String("fnNamespace")
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
ns := input.String(flagkey.NamespaceFunction)
|
||||
|
||||
fns, err := opts.client.FunctionList(ns)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,9 +22,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/logdb"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
@@ -33,38 +35,32 @@ type LogSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Log(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Log(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := LogSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *LogSubCommand) do(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (opts *LogSubCommand) do(input cli.Input) error {
|
||||
dbType := input.String(flagkey.FnLogDBType)
|
||||
fnPod := input.String(flagkey.FnLogPod)
|
||||
|
||||
dbType := flags.String("dbtype")
|
||||
if len(dbType) == 0 {
|
||||
dbType = logdb.INFLUXDB
|
||||
}
|
||||
logReverseQuery := !input.Bool(flagkey.FnLogFollow) && input.Bool(flagkey.FnLogReverseQuery)
|
||||
|
||||
fnPod := flags.String("pod")
|
||||
|
||||
logReverseQuery := !flags.Bool("f") && flags.Bool("r")
|
||||
|
||||
recordLimit := flags.Int("recordcount")
|
||||
recordLimit := input.Int(flagkey.FnLogCount)
|
||||
if recordLimit <= 0 {
|
||||
recordLimit = 1000
|
||||
}
|
||||
|
||||
f, err := opts.client.FunctionGet(m)
|
||||
f, err := opts.client.FunctionGet(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: input.String(flagkey.NamespaceFunction),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function")
|
||||
}
|
||||
@@ -104,7 +100,7 @@ func (opts *LogSubCommand) do(flags cli.Input) error {
|
||||
return
|
||||
}
|
||||
for _, logEntry := range logEntries {
|
||||
if flags.Bool("d") {
|
||||
if input.Bool(flagkey.FnLogDetail) {
|
||||
fmt.Printf("Timestamp: %s\nNamespace: %s\nFunction Name: %s\nFunction ID: %s\nPod: %s\nContainer: %s\nStream: %s\nLog: %s\n---\n",
|
||||
logEntry.Timestamp, logEntry.Namespace, logEntry.FuncName, logEntry.FuncUid, logEntry.Pod, logEntry.Container, logEntry.Stream, logEntry.Message)
|
||||
} else {
|
||||
@@ -124,7 +120,7 @@ func (opts *LogSubCommand) do(flags cli.Input) error {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
<-responseChan
|
||||
if !flags.Bool("f") {
|
||||
if !input.Bool(flagkey.FnLogFollow) {
|
||||
ctx.Done()
|
||||
break
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -38,21 +39,21 @@ type TestSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Test(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Test(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := TestSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *TestSubCommand) do(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
func (opts *TestSubCommand) do(input cli.Input) error {
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: input.String(flagkey.NamespaceFunction),
|
||||
}
|
||||
|
||||
routerURL := os.Getenv("FISSION_ROUTER")
|
||||
@@ -76,7 +77,7 @@ func (opts *TestSubCommand) do(flags cli.Input) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
queryParams := flags.StringSlice("query")
|
||||
queryParams := input.StringSlice(flagkey.FnTestQuery)
|
||||
if len(queryParams) > 0 {
|
||||
query := url.Values{}
|
||||
for _, q := range queryParams {
|
||||
@@ -97,15 +98,15 @@ func (opts *TestSubCommand) do(flags cli.Input) error {
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
if deadline := flags.Duration("timeout"); deadline > 0 {
|
||||
if deadline := input.Duration(flagkey.FnTestTimeout); deadline > 0 {
|
||||
var closeCtx func()
|
||||
ctx, closeCtx = context.WithTimeout(ctx, deadline)
|
||||
defer closeCtx()
|
||||
}
|
||||
|
||||
headers := flags.StringSlice("header")
|
||||
headers := input.StringSlice(flagkey.FnTestHeader)
|
||||
|
||||
resp, err := doHTTPRequest(ctx, flags.String("method"), functionUrl.String(), flags.String("body"), headers)
|
||||
resp, err := doHTTPRequest(ctx, input.String(flagkey.HtMethod), functionUrl.String(), input.String(flagkey.FnTestBody), headers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -123,9 +124,9 @@ func (opts *TestSubCommand) do(flags cli.Input) error {
|
||||
}
|
||||
|
||||
fmt.Printf("Error calling function %s: %d; Please try again or fix the error: %s", m.Name, resp.StatusCode, string(body))
|
||||
err = printPodLogs(flags)
|
||||
err = printPodLogs(input)
|
||||
if err != nil {
|
||||
return Log(flags)
|
||||
return Log(input)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -157,8 +158,8 @@ func doHTTPRequest(ctx context.Context, method, url, body string, headers []stri
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func printPodLogs(flags cli.Input) error {
|
||||
fnName := flags.String("name")
|
||||
func printPodLogs(input cli.Input) error {
|
||||
fnName := input.String(flagkey.FnName)
|
||||
if len(fnName) == 0 {
|
||||
return errors.New("need --name argument.")
|
||||
}
|
||||
@@ -174,7 +175,7 @@ func printPodLogs(flags cli.Input) error {
|
||||
}
|
||||
queryURL.Path = fmt.Sprintf("/proxy/logs/%s", fnName)
|
||||
|
||||
req, err := http.NewRequest("POST", queryURL.String(), nil)
|
||||
req, err := http.NewRequest(http.MethodPost, queryURL.String(), nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating logs request")
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package function
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -27,7 +28,7 @@ import (
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
_package "github.com/fission/fission/pkg/fission-cli/cmd/package"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
@@ -37,41 +38,30 @@ type UpdateSubCommand struct {
|
||||
function *fv1.Function
|
||||
}
|
||||
|
||||
func Update(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Update(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := UpdateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
if len(flags.String("package")) > 0 {
|
||||
return errors.New("--package is deprecated, please use --deploy instead")
|
||||
}
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
fnName := input.String(flagkey.FnName)
|
||||
fnNamespace := input.String(flagkey.NamespaceFunction)
|
||||
|
||||
if len(flags.String("srcpkg")) > 0 {
|
||||
return errors.New("--srcpkg is deprecated, please use --src instead.")
|
||||
}
|
||||
|
||||
fnName := flags.String("name")
|
||||
if len(fnName) == 0 {
|
||||
return errors.New("Need name of function, use --name")
|
||||
}
|
||||
fnNamespace := flags.String("fnNamespace")
|
||||
|
||||
m, err := util.GetMetadata("name", "fnNamespace", flags)
|
||||
m, err := util.GetMetadata("name", "fnNamespace", input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -81,8 +71,8 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
return errors.Wrap(err, fmt.Sprintf("read function '%v'", fnName))
|
||||
}
|
||||
|
||||
envName := flags.String("env")
|
||||
envNamespace := flags.String("envNamespace")
|
||||
envName := input.String("env")
|
||||
envNamespace := input.String("envNamespace")
|
||||
// if the new env specified is the same as the old one, no need to update package
|
||||
// same is true for all update parameters, but, for now, we dont check all of them - because, its ok to
|
||||
// re-write the object with same old values, we just end up getting a new resource version for the object.
|
||||
@@ -96,24 +86,24 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
var deployArchiveFiles []string
|
||||
codeFlag := false
|
||||
code := flags.String("code")
|
||||
code := input.String("code")
|
||||
if len(code) == 0 {
|
||||
deployArchiveFiles = flags.StringSlice("deploy")
|
||||
deployArchiveFiles = input.StringSlice("deploy")
|
||||
} else {
|
||||
deployArchiveFiles = append(deployArchiveFiles, flags.String("code"))
|
||||
deployArchiveFiles = append(deployArchiveFiles, input.String("code"))
|
||||
codeFlag = true
|
||||
}
|
||||
|
||||
srcArchiveFiles := flags.StringSlice("src")
|
||||
pkgName := flags.String("pkg")
|
||||
entrypoint := flags.String("entrypoint")
|
||||
buildcmd := flags.String("buildcmd")
|
||||
force := flags.Bool("force")
|
||||
srcArchiveFiles := input.StringSlice("src")
|
||||
pkgName := input.String("pkg")
|
||||
entrypoint := input.String("entrypoint")
|
||||
buildcmd := input.String("buildcmd")
|
||||
force := input.Bool("force")
|
||||
|
||||
secretNames := flags.StringSlice("secret")
|
||||
cfgMapNames := flags.StringSlice("configmap")
|
||||
secretNames := input.StringSlice("secret")
|
||||
cfgMapNames := input.StringSlice("configmap")
|
||||
|
||||
specializationTimeout := flags.Int("specializationtimeout")
|
||||
specializationTimeout := input.Int("specializationtimeout")
|
||||
|
||||
if len(srcArchiveFiles) > 0 && len(deployArchiveFiles) > 0 {
|
||||
return errors.New("Need either of --src or --deploy and not both arguments.")
|
||||
@@ -131,7 +121,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
Name: secretName,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
consolemsg.Warn(fmt.Sprintf("secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
console.Warn(fmt.Sprintf("secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +145,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
Name: cfgMapName,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
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))
|
||||
console.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as the function", cfgMapName, fnNamespace))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,8 +171,8 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
function.Spec.Package.FunctionName = entrypoint
|
||||
}
|
||||
|
||||
if flags.IsSet("fntimeout") {
|
||||
fnTimeout := flags.Int("fntimeout")
|
||||
if input.IsSet("fntimeout") {
|
||||
fnTimeout := input.Int("fntimeout")
|
||||
if fnTimeout <= 0 {
|
||||
return errors.New("fntimeout must be greater than 0")
|
||||
}
|
||||
@@ -193,13 +183,13 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
pkgName = function.Spec.Package.PackageRef.Name
|
||||
}
|
||||
|
||||
strategy, err := getInvokeStrategy(flags, &function.Spec.InvokeStrategy)
|
||||
strategy, err := getInvokeStrategy(input, &function.Spec.InvokeStrategy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
function.Spec.InvokeStrategy = *strategy
|
||||
|
||||
if flags.IsSet("specializationtimeout") {
|
||||
if input.IsSet("specializationtimeout") {
|
||||
if strategy.ExecutionStrategy.ExecutorType != types.ExecutorTypeNewdeploy {
|
||||
return errors.New("specializationtimeout flag is only applicable for newdeploy type of executor")
|
||||
}
|
||||
@@ -211,7 +201,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
}
|
||||
}
|
||||
|
||||
resReqs, err := util.GetResourceReqs(flags, &function.Spec.Resources)
|
||||
resReqs, err := util.GetResourceReqs(input, &function.Spec.Resources)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -238,7 +228,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
return errors.New("package is used by multiple functions, use --force to force update")
|
||||
}
|
||||
|
||||
keepURL := flags.Bool("keepurl")
|
||||
keepURL := input.Bool("keepurl")
|
||||
|
||||
pkgMetadata, err = _package.UpdatePackage(opts.client, pkg, envName, envNamespace, srcArchiveFiles, deployArchiveFiles, buildcmd, false, codeFlag, keepURL)
|
||||
if err != nil {
|
||||
@@ -271,7 +261,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
}
|
||||
|
||||
if function.Spec.Environment.Name != pkg.Spec.Environment.Name {
|
||||
consolemsg.Warn("Function's environment is different than package's environment, package's environment will be used for updating function")
|
||||
console.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.Namespace = pkg.Spec.Environment.Namespace
|
||||
}
|
||||
@@ -281,7 +271,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.client.FunctionUpdate(opts.function)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating function")
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
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 httptrigger
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create an HTTP trigger",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtUrlFlag, flag.HtFnNameFlag},
|
||||
Optional: []flag.Flag{flag.HtNameFlag, flag.HtMethodFlag, flag.HtIngressRuleFlag,
|
||||
flag.HtIngressAnnotationFlag, flag.HtIngressTLSFlag, flag.HtIngressFlag,
|
||||
flag.HtFnWeightFlag, flag.HtHostFlag, flag.NamespaceFunctionFlag, flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Aliases: []string{},
|
||||
Short: "Get HTTP trigger details",
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtNameFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Aliases: []string{},
|
||||
Short: "Update an HTTP trigger",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnNameFlag, flag.HtUrlFlag,
|
||||
flag.HtMethodFlag, flag.HtIngressRuleFlag, flag.HtIngressAnnotationFlag,
|
||||
flag.HtIngressTLSFlag, flag.HtIngressFlag, flag.HtFnWeightFlag, flag.HtHostFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{},
|
||||
Short: "Delete an HTTP trigger",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnFilterFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{},
|
||||
Short: "List all HTTP triggers in a namespace if specified, else, list HTTP triggers across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnFilterFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "httptrigger",
|
||||
Aliases: []string{"ht", "route"},
|
||||
Short: "Create, update and manage HTTP triggers",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getCmd, updateCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -104,7 +104,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
if !flags.Bool("spec") {
|
||||
err = util.CheckFunctionExistence(opts.client, functionList, fnNamespace)
|
||||
if err != nil {
|
||||
consolemsg.Warn(err.Error())
|
||||
console.Warn(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
host := flags.String("host")
|
||||
if flags.IsSet("host") {
|
||||
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
console.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
}
|
||||
|
||||
// just name triggers by uuid.
|
||||
|
||||
@@ -19,12 +19,14 @@ package httptrigger
|
||||
import (
|
||||
"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/pkg/errors"
|
||||
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"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
type DeleteSubCommand struct {
|
||||
@@ -84,7 +86,7 @@ func (opts *DeleteSubCommand) run(flags cli.Input) error {
|
||||
triggersToDelete = []string{opts.triggerName}
|
||||
}
|
||||
|
||||
errs := &multierror.Error{}
|
||||
errs := utils.MultiErrorWithFormat()
|
||||
|
||||
for _, name := range triggersToDelete {
|
||||
err := opts.client.HTTPTriggerDelete(&metav1.ObjectMeta{
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -73,7 +73,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
functionList := flags.StringSlice("function")
|
||||
err := util.CheckFunctionExistence(opts.client, functionList, triggerNamespace)
|
||||
if err != nil {
|
||||
consolemsg.Warn(err.Error())
|
||||
console.Warn(err.Error())
|
||||
}
|
||||
|
||||
var functionWeightsList []int
|
||||
@@ -96,7 +96,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
if flags.IsSet("host") {
|
||||
ht.Spec.Host = flags.String("host")
|
||||
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
console.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
}
|
||||
|
||||
if flags.IsSet("ingressrule") || flags.IsSet("ingressannotation") || flags.IsSet("ingresstls") {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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 kubewatch
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a kube watcher",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.KwFnNameFlag, flag.KwObjTypeFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceFunctionFlag, flag.KwLabelsFlag, flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{},
|
||||
Short: "Delete a kube watcher",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.KwFnNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{},
|
||||
Short: "List all kube watchers in a namespace if specified, else, list kube watchers across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "watch",
|
||||
Aliases: []string{"w"},
|
||||
Short: "Create, update and manage kube watcher",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
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 mqtrigger
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a message queue trigger",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.MqtFnNameFlag, flag.MqtTopicFlag},
|
||||
Optional: []flag.Flag{flag.MqtNameFlag, flag.NamespaceFunctionFlag, flag.MqtMQTypeFlag,
|
||||
flag.MqtRespTopicFlag, flag.MqtErrorTopicFlag, flag.MqtMaxRetriesFlag, flag.MqtMsgContentTypeFlag,
|
||||
flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Aliases: []string{},
|
||||
Short: "Update a message queue trigger",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.MqtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.MqtTopicFlag, flag.MqtRespTopicFlag,
|
||||
flag.MqtErrorTopicFlag, flag.MqtMaxRetriesFlag, flag.MqtFnNameFlag, flag.MqtMsgContentTypeFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{},
|
||||
Short: "Delete a message queue trigger",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.MqtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{},
|
||||
Short: "List all message queue triggers in a namespace if specified, else, list message queue triggers across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "mqtrigger",
|
||||
Aliases: []string{"mqt"},
|
||||
Short: "Create, update and manage message queue triggers",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, updateCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
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 _package
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a package",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.PkgEnvironmentFlag},
|
||||
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.NamespaceEnvironmentFlag,
|
||||
flag.PkgSrcArchiveFlag, flag.PkgDeployArchiveFlag, flag.PkgKeepURLFlag, flag.PkgBuildCmdFlag},
|
||||
})
|
||||
|
||||
getSrcCmd := &cobra.Command{
|
||||
Use: "getsrc",
|
||||
Short: "Get package details",
|
||||
RunE: wrapper.Wrapper(GetSrc),
|
||||
}
|
||||
wrapper.SetFlags(getSrcCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.PkgNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.PkgOutputFlag},
|
||||
})
|
||||
|
||||
getDeployCmd := &cobra.Command{
|
||||
Use: "getdeploy",
|
||||
Short: "Get package details",
|
||||
RunE: wrapper.Wrapper(GetDeploy),
|
||||
}
|
||||
wrapper.SetFlags(getDeployCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.PkgNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.PkgOutputFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update a package",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.PkgNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.PkgEnvironmentFlag, flag.NamespaceEnvironmentFlag,
|
||||
flag.PkgSrcArchiveFlag, flag.PkgDeployArchiveFlag, flag.PkgKeepURLFlag,
|
||||
flag.PkgBuildCmdFlag, flag.PkgForceFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete a package",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.PkgNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.PkgForceFlag, flag.PkgOrphanFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all packages in a namespace if specified, else, list packages across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.PkgOrphanFlag, flag.PkgStatusFlag, flag.NamespacePackageFlag},
|
||||
})
|
||||
|
||||
infoCmd := &cobra.Command{
|
||||
Use: "info",
|
||||
Short: "Show package information",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(infoCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.PkgNameFlag, flag.NamespacePackageFlag},
|
||||
})
|
||||
|
||||
rebuildCmd := &cobra.Command{
|
||||
Use: "rebuild",
|
||||
Short: "Rebuild a failed package",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(rebuildCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.PkgNameFlag, flag.NamespacePackageFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "package",
|
||||
Aliases: []string{"pkg"},
|
||||
Short: "Create, update and manage packages",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getSrcCmd, getDeployCmd, updateCmd, deleteCmd, listCmd, infoCmd, rebuildCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -41,8 +41,7 @@ import (
|
||||
// upload the archive using client. noZip avoids zipping the
|
||||
// includeFiles, but is ignored if there's more than one includeFile.
|
||||
func CreateArchive(client *client.Client, includeFiles []string, noZip bool, keepURL bool, specDir string, specFile string) (*fv1.Archive, error) {
|
||||
|
||||
errs := &multierror.Error{}
|
||||
errs := utils.MultiErrorWithFormat()
|
||||
fileURL := ""
|
||||
|
||||
// check files existence
|
||||
@@ -65,7 +64,7 @@ func CreateArchive(client *client.Client, includeFiles []string, noZip bool, kee
|
||||
}
|
||||
|
||||
if len(files) == 0 {
|
||||
errs = multierror.Append(errs, errors.New(fmt.Sprintf("Error finding any files with path \"%v\"", path)))
|
||||
errs = multierror.Append(errs, errors.Errorf("Error finding any files with path \"%v\"", path))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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 plugin
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List installed client plugins",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "plugin",
|
||||
Aliases: []string{"plugins"},
|
||||
Short: "Manage CLI plugins",
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
command.AddCommand(listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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 recorder
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a recorder",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.RecorderNameFlag, flag.RecorderFnFlag, flag.RecorderTriggersFlag, flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "Get recorder details",
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderNameFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update a recorder",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderNameFlag},
|
||||
Optional: []flag.Flag{flag.RecorderFnFlag, flag.RecorderTriggersFlag, flag.RecorderEnabledFlag, flag.RecorderDisabledFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete a recorder",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceRecorderFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all recorders in a namespace if specified, else, list recorders across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceRecorderFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "recorder",
|
||||
Short: "Create, update and manage recorders",
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getCmd, updateCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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 records
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
viewCmd := &cobra.Command{
|
||||
Use: "view",
|
||||
Short: "View existing records",
|
||||
RunE: wrapper.Wrapper(View),
|
||||
}
|
||||
wrapper.SetFlags(viewCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.RecordsFilterTimeToFlag, flag.RecordsFilterTimeFromFlag,
|
||||
flag.RecordsFilterFunctionFlag, flag.RecordsFilterTriggerFlag, flag.RecordsVerbosityFlag,
|
||||
flag.RecordsVvFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "records",
|
||||
Short: "View records with optional filters",
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
command.AddCommand(viewCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 replay
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
replayCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a recorder",
|
||||
RunE: wrapper.Wrapper(Replay),
|
||||
}
|
||||
wrapper.SetFlags(replayCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecordsReqIDFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "replay",
|
||||
Short: "Replay records",
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
command.AddCommand(replayCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -37,7 +37,7 @@ import (
|
||||
|
||||
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
||||
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
@@ -430,7 +430,7 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
|
||||
absGlob := rootDir + "/" + relativeGlob
|
||||
f, err := filepath.Glob(absGlob)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob))
|
||||
console.Info(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob))
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, f...)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
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 spec
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
initCmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Create an initial declarative application specification",
|
||||
RunE: wrapper.Wrapper(Init),
|
||||
}
|
||||
wrapper.SetFlags(initCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecNameFlag, flag.SpecDeployIDFlag},
|
||||
})
|
||||
|
||||
validateCmd := &cobra.Command{
|
||||
Use: "validate",
|
||||
Short: "Validate declarative application specification",
|
||||
RunE: wrapper.Wrapper(Validate),
|
||||
}
|
||||
wrapper.SetFlags(validateCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag},
|
||||
})
|
||||
|
||||
applyCmd := &cobra.Command{
|
||||
Use: "apply",
|
||||
Short: "Create, update, or delete resources from application specification",
|
||||
RunE: wrapper.Wrapper(Apply),
|
||||
}
|
||||
wrapper.SetFlags(applyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecDeployIDFlag, flag.SpecWaitFlag},
|
||||
})
|
||||
|
||||
destroyCmd := &cobra.Command{
|
||||
Use: "destroy",
|
||||
Short: "Delete an environment",
|
||||
RunE: wrapper.Wrapper(Destroy),
|
||||
}
|
||||
wrapper.SetFlags(destroyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "spec",
|
||||
Aliases: []string{"specs"},
|
||||
Short: "Manage a declarative application specification",
|
||||
}
|
||||
|
||||
command.AddCommand(initCmd, validateCmd, applyCmd, destroyCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -32,10 +32,11 @@ import (
|
||||
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/cmd/spec/types"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/generator/encoder"
|
||||
v1generator "github.com/fission/fission/pkg/generator/v1"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
var specDefaultEncoder = encoder.DefaultYAMLEncoder()
|
||||
@@ -246,7 +247,7 @@ func (fr *FissionResources) validateFunctionReference(functions map[string]bool,
|
||||
}
|
||||
|
||||
func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
result := &multierror.Error{}
|
||||
result := utils.MultiErrorWithFormat()
|
||||
|
||||
// check references: both dangling refs + garbage
|
||||
// packages -> archives
|
||||
@@ -357,7 +358,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
Namespace: cm.Namespace,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
consolemsg.Warn(fmt.Sprintf("Configmap %s is referred in the spec but not present in the cluster", cm.Name))
|
||||
console.Warn(fmt.Sprintf("Configmap %s is referred in the spec but not present in the cluster", cm.Name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +368,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
Namespace: s.Namespace,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
consolemsg.Warn(fmt.Sprintf("Secret %s is referred in the spec but not present in the cluster", s.Name))
|
||||
console.Warn(fmt.Sprintf("Secret %s is referred in the spec but not present in the cluster", s.Name))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -395,7 +396,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
}
|
||||
|
||||
if len(t.Spec.Host) > 0 {
|
||||
consolemsg.Warn(fmt.Sprintf("Host in HTTPTrigger spec.Host is now marked as deprecated, see 'help' for details"))
|
||||
console.Warn(fmt.Sprintf("Host in HTTPTrigger spec.Host is now marked as deprecated, see 'help' for details"))
|
||||
}
|
||||
|
||||
result = multierror.Append(result, t.Validate())
|
||||
@@ -430,25 +431,25 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
for _, e := range fr.Environments {
|
||||
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)) {
|
||||
consolemsg.Warn("You have provided both - container spec and pod spec and while merging the pod spec will take precedence.")
|
||||
console.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,
|
||||
// we have to warn the user to modify spec file when this takes place.
|
||||
if e.Spec.Version < 3 && e.Spec.Poolsize != 0 {
|
||||
consolemsg.Warn("Poolsize can only be configured when environment version equals to 3, default poolsize 3 will be used for creating environment pool.")
|
||||
console.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 {
|
||||
if _, ok := environments[fmt.Sprintf("%s:%s", f.Spec.Environment.Name, f.Spec.Environment.Namespace)]; !ok {
|
||||
consolemsg.Warn(fmt.Sprintf("Environment %s is referenced in function %s but not declared in specs", f.Spec.Environment.Name, f.Metadata.Name))
|
||||
console.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
|
||||
if strategy.ExecutorType == fv1.ExecutorTypeNewdeploy && strategy.SpecializationTimeout < fv1.DefaultSpecializationTimeOut {
|
||||
consolemsg.Warn(fmt.Sprintf("SpecializationTimeout in function spec.InvokeStrategy.ExecutionStrategy should be a value equal to or greater than %v", fv1.DefaultSpecializationTimeOut))
|
||||
console.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 {
|
||||
consolemsg.Warn(fmt.Sprintf("FunctionTimeout in function spec should be a field which should have a value greater than 0"))
|
||||
console.Warn(fmt.Sprintf("FunctionTimeout in function spec should be a field which should have a value greater than 0"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,7 +578,7 @@ func (fr *FissionResources) ParseYaml(b []byte, loc *Location) error {
|
||||
default:
|
||||
// no need to error out just because there's some extra files around;
|
||||
// also good for compatibility.
|
||||
consolemsg.Warn(fmt.Sprintf("Ignoring unknown type %v in %v", tm.Kind, loc))
|
||||
console.Warn(fmt.Sprintf("Ignoring unknown type %v in %v", tm.Kind, loc))
|
||||
}
|
||||
|
||||
// add to source map, check for duplicates
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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 support
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
dumpCmd := &cobra.Command{
|
||||
Use: "dump",
|
||||
Short: "Collect & dump all necessary information for troubleshooting",
|
||||
RunE: wrapper.Wrapper(Dump),
|
||||
}
|
||||
wrapper.SetFlags(dumpCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SupportNoZipFlag, flag.SupportOutputFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "support",
|
||||
Short: "Collect diagnostic information for support",
|
||||
}
|
||||
|
||||
command.AddCommand(dumpCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdEnvironment:
|
||||
items, err := res.client.EnvironmentList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdFunction:
|
||||
items, err := res.client.FunctionList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdPackage:
|
||||
items, err := res.client.PackageList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdHttpTrigger:
|
||||
items, err := res.client.HTTPTriggerList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdKubeWatcher:
|
||||
items, err := res.client.WatchList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
for _, mqType := range []string{types.MessageQueueTypeNats, types.MessageQueueTypeASQ} {
|
||||
l, err := res.client.MessageQueueTriggerList(mqType, metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
break
|
||||
}
|
||||
triggers = append(triggers, l...)
|
||||
@@ -131,7 +131,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdTimeTrigger:
|
||||
items, err := res.client.TimeTriggerList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
}
|
||||
|
||||
default:
|
||||
consolemsg.Info(fmt.Sprintf("Unknown type: %v", res.crdType))
|
||||
console.Info(fmt.Sprintf("Unknown type: %v", res.crdType))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -52,7 +52,7 @@ func NewKubernetesVersion(clientset *kubernetes.Clientset) Resource {
|
||||
func (res KubernetesVersion) Dump(dumpDir string) {
|
||||
serverVer, err := res.client.ServerVersion()
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error setting up kubernetes client: %v", err))
|
||||
console.Info(fmt.Sprintf("Error setting up kubernetes client: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
||||
case KubernetesService:
|
||||
objs, err := res.client.CoreV1().Services(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
||||
case KubernetesDeployment:
|
||||
objs, err := res.client.AppsV1().Deployments(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
||||
case KubernetesPod:
|
||||
objs, err := res.client.CoreV1().Pods(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
||||
case KubernetesHPA:
|
||||
objs, err := res.client.AutoscalingV2beta1().HorizontalPodAutoscalers(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
||||
case KubernetesDaemonSet:
|
||||
objs, err := res.client.AppsV1().DaemonSets(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: res.selector})
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
||||
case KubernetesNode:
|
||||
objs, err := res.client.CoreV1().Nodes().List(metav1.ListOptions{LabelSelector: res.selector})
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
console.Info(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (res KubernetesObjectDumper) Dump(dumpDir string) {
|
||||
}
|
||||
|
||||
default:
|
||||
consolemsg.Info(fmt.Sprintf("Unknown type: %v", res.objType))
|
||||
console.Info(fmt.Sprintf("Unknown type: %v", res.objType))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) {
|
||||
Pods(metav1.NamespaceAll).
|
||||
List(metav1.ListOptions{LabelSelector: res.labelSelector})
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error getting controller list: %v", err))
|
||||
console.Info(fmt.Sprintf("Error getting controller list: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) {
|
||||
|
||||
stream, err := req.Stream()
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error streaming logs for pod %v: %v", pod.Name, err))
|
||||
console.Info(fmt.Sprintf("Error streaming logs for pod %v: %v", pod.Name, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -232,13 +232,13 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) {
|
||||
stream.Close()
|
||||
break
|
||||
}
|
||||
consolemsg.Info(fmt.Sprintf("Error reading logs from buffer: %v", err))
|
||||
console.Info(fmt.Sprintf("Error reading logs from buffer: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
_, err = buffer.WriteString(string(line) + "\n")
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error writing bytes to buffer: %v", err))
|
||||
console.Info(fmt.Sprintf("Error writing bytes to buffer: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/ghodss/yaml"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"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{}) {
|
||||
bs, err := yaml.Marshal(obj)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error encoding object: %v", err))
|
||||
console.Info(fmt.Sprintf("Error encoding object: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -57,6 +57,6 @@ func writeToFile(file string, obj interface{}) {
|
||||
|
||||
err = ioutil.WriteFile(file, bs, 0644)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Error writing file %v: %v", file, err))
|
||||
console.Info(fmt.Sprintf("Error writing file %v: %v", file, err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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 timetrigger
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a time trigger",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.TtNameFlag, flag.TtFnNameFlag, flag.NamespaceFunctionFlag, flag.TtCronFlag, flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Aliases: []string{},
|
||||
Short: "Update a time trigger",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.TtNameFlag},
|
||||
Optional: []flag.Flag{flag.TtFnNameFlag, flag.NamespaceFunctionFlag, flag.TtCronFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{},
|
||||
Short: "Delete a time trigger",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.TtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{},
|
||||
Short: "List all time triggers in a namespace if specified, else, list time triggers across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
})
|
||||
|
||||
showCmd := &cobra.Command{
|
||||
Use: "showschedule",
|
||||
Aliases: []string{"show"},
|
||||
Short: "Show schedule for cron spec",
|
||||
RunE: wrapper.Wrapper(Show),
|
||||
}
|
||||
wrapper.SetFlags(showCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.TtCronFlag, flag.TtRoundFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "timetrigger",
|
||||
Aliases: []string{"tt", "timer"},
|
||||
Short: "Create, update and manage time triggers",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, updateCmd, deleteCmd, listCmd, showCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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 version
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Version information",
|
||||
RunE: wrapper.Wrapper(Version),
|
||||
}
|
||||
return command
|
||||
}
|
||||
Reference in New Issue
Block a user