Replace flag text with const (#1391)

This commit is contained in:
Ta-Ching Chen
2019-11-09 22:13:35 +08:00
committed by GitHub
parent 6f5f6900b6
commit d3d8ff6c1b
73 changed files with 867 additions and 926 deletions
+9 -9
View File
@@ -30,8 +30,8 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.CanaryName, flag.CanaryTriggerName, flag.CanaryNewFunc, flag.CanaryOldFunc},
Optional: []flag.Flag{flag.NamespaceFunction, flag.CanaryWeightIncrement, flag.CanaryIncrementInterval, flag.CanaryFailureThreshold},
})
getCmd := &cobra.Command{
@@ -41,8 +41,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Get),
}
wrapper.SetFlags(getCmd, flag.FlagSet{
Required: []flag.Flag{flag.CanaryNameFlag},
Optional: []flag.Flag{flag.NamespaceCanaryFlag},
Required: []flag.Flag{flag.CanaryName},
Optional: []flag.Flag{flag.NamespaceCanary},
})
updateCmd := &cobra.Command{
@@ -52,8 +52,8 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.CanaryName},
Optional: []flag.Flag{flag.NamespaceCanary, flag.CanaryWeightIncrement, flag.CanaryIncrementInterval, flag.CanaryFailureThreshold},
})
deleteCmd := &cobra.Command{
@@ -63,8 +63,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.CanaryNameFlag},
Optional: []flag.Flag{flag.NamespaceCanaryFlag},
Required: []flag.Flag{flag.CanaryName},
Optional: []flag.Flag{flag.NamespaceCanary},
})
listCmd := &cobra.Command{
@@ -75,7 +75,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceCanaryFlag},
Optional: []flag.Flag{flag.NamespaceCanary},
})
command := &cobra.Command{
+16 -16
View File
@@ -36,36 +36,36 @@ type CreateSubCommand struct {
canary *fv1.CanaryConfig
}
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 {
func (opts *CreateSubCommand) complete(input cli.Input) error {
// canary configs can be created for functions in the same namespace
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)
name := input.String(flagkey.CanaryName)
ht := input.String(flagkey.CanaryHTTPTriggerName)
newFunc := input.String(flagkey.CanaryNewFunc)
oldFunc := input.String(flagkey.CanaryOldFunc)
fnNs := input.String(flagkey.NamespaceFunction)
incrementStep := input.Int(flagkey.CanaryWeightIncrement)
failureThreshold := input.Int(flagkey.CanaryFailureThreshold)
incrementInterval := input.String(flagkey.CanaryIncrementInterval)
// check for time parsing
_, err := time.ParseDuration(incrementInterval)
@@ -128,7 +128,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *CreateSubCommand) run(flags cli.Input) error {
func (opts *CreateSubCommand) run(input cli.Input) error {
_, err := opts.client.CanaryConfigCreate(opts.canary)
if err != nil {
return errors.Wrap(err, "error creating canary config")
+3 -3
View File
@@ -53,12 +53,12 @@ func (opts *ListSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ListSubCommand) complete(flags cli.Input) error {
opts.namespace = flags.String(flagkey.NamespaceCanary)
func (opts *ListSubCommand) complete(input cli.Input) error {
opts.namespace = input.String(flagkey.NamespaceCanary)
return nil
}
func (opts *ListSubCommand) run(flags cli.Input) error {
func (opts *ListSubCommand) run(input cli.Input) error {
canaryCfgs, err := opts.client.CanaryConfigList(opts.namespace)
if err != nil {
return errors.Wrap(err, "error listing canary config")
+1 -1
View File
@@ -21,5 +21,5 @@ import (
)
type (
CommandAction func(flags cli.Input) error
CommandAction func(input cli.Input) error
)
+14 -14
View File
@@ -30,11 +30,11 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.EnvName, flag.EnvImage},
Optional: []flag.Flag{flag.NamespaceEnvironment, flag.EnvPoolsize,
flag.EnvBuilderImage, flag.EnvBuildCmd, flag.EnvKeepArchive,
flag.RunTimeMinCPU, flag.RunTimeMaxCPU, flag.RunTimeMinMemory, flag.RunTimeMaxMemory,
flag.EnvVersion, flag.EnvExternalNetwork, flag.EnvTerminationGracePeriod, flag.SpecSave},
})
getCmd := &cobra.Command{
@@ -43,8 +43,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Get),
}
wrapper.SetFlags(getCmd, flag.FlagSet{
Required: []flag.Flag{flag.EnvNameFlag},
Optional: []flag.Flag{flag.NamespaceEnvironmentFlag},
Required: []flag.Flag{flag.EnvName},
Optional: []flag.Flag{flag.NamespaceEnvironment},
})
updateCmd := &cobra.Command{
@@ -53,10 +53,10 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.EnvName},
Optional: []flag.Flag{flag.EnvImage, flag.NamespaceEnvironment, flag.EnvPoolsize,
flag.EnvBuilderImage, flag.EnvBuildCmd, flag.EnvKeepArchive,
flag.EnvExternalNetwork, flag.EnvTerminationGracePeriod, flag.SpecSave},
})
deleteCmd := &cobra.Command{
@@ -65,8 +65,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.EnvNameFlag},
Optional: []flag.Flag{flag.NamespaceEnvironmentFlag},
Required: []flag.Flag{flag.EnvName},
Optional: []flag.Flag{flag.NamespaceEnvironment},
})
listCmd := &cobra.Command{
@@ -76,7 +76,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceEnvironmentFlag},
Optional: []flag.Flag{flag.NamespaceEnvironment},
})
command := &cobra.Command{
+28 -28
View File
@@ -30,13 +30,13 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction, flag.NamespaceEnvironment, flag.SpecSave,
flag.FnEnvName, flag.FnCode, flag.PkgSrcArchive, flag.PkgDeployArchive, flag.FnKeepURL,
flag.FnEntryPoint, flag.FnBuildCmd, flag.FnPkgName, flag.HtUrl, flag.HtMethod,
flag.RunTimeMinCPU, flag.RunTimeMaxCPU, flag.RunTimeMinMemory, flag.RunTimeMaxMemory,
flag.ReplicasMin, flag.ReplicasMax, flag.FnExecutorType, flag.RunTimeTargetCPU,
flag.FnCfgMap, flag.FnSecret, flag.FnSpecializationTimeout, flag.FnExecutionTimeout},
})
getCmd := &cobra.Command{
@@ -46,8 +46,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Get),
}
wrapper.SetFlags(getCmd, flag.FlagSet{
Required: []flag.Flag{flag.FnNameFlag},
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction},
})
getmetaCmd := &cobra.Command{
@@ -57,8 +57,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(GetMeta),
}
wrapper.SetFlags(getmetaCmd, flag.FlagSet{
Required: []flag.Flag{flag.FnNameFlag},
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction},
})
updateCmd := &cobra.Command{
@@ -68,14 +68,14 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction, flag.NamespaceEnvironment, flag.SpecSave,
flag.FnCode, flag.PkgSrcArchive, flag.PkgDeployArchive,
flag.FnKeepURL, flag.FnEntryPoint, flag.FnBuildCmd, flag.FnPkgName, flag.HtUrl,
flag.HtMethod, flag.RunTimeMinCPU, flag.RunTimeMaxCPU, flag.RunTimeMinMemory,
flag.RunTimeMaxMemory, flag.ReplicasMin, flag.ReplicasMax, flag.FnExecutorType,
flag.RunTimeTargetCPU, flag.FnCfgMap, flag.FnSecret, flag.FnSpecializationTimeout,
flag.FnExecutionTimeout, flag.PkgForce},
})
deleteCmd := &cobra.Command{
@@ -85,8 +85,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.FnNameFlag},
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction},
})
listCmd := &cobra.Command{
@@ -96,7 +96,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceFunctionFlag},
Optional: []flag.Flag{flag.NamespaceFunction},
})
logsCmd := &cobra.Command{
@@ -106,9 +106,9 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction, flag.FnLogPod, flag.FnLogFollow,
flag.FnLogDetail, flag.FnLogDBType, flag.FnLogReverseQuery, flag.FnLogCount},
})
testCmd := &cobra.Command{
@@ -118,9 +118,9 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction, flag.HtMethod, flag.FnTestBody,
flag.FnTestHeader, flag.FnTestQuery, flag.FnTestTimeout},
})
command := &cobra.Command{
+25 -27
View File
@@ -83,12 +83,10 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
specDir := util.GetSpecDir(input)
// check for unique function names within a namespace
metadata, err := util.GetMetadata(flagkey.FnName, flagkey.NamespaceFunction, input)
if err != nil {
return err
}
fn, err := opts.client.FunctionGet(metadata)
fn, err := opts.client.FunctionGet(&metav1.ObjectMeta{
Name: input.String(flagkey.FnName),
Namespace: input.String(flagkey.NamespaceFunction),
})
if err != nil && !ferror.IsNotFound(err) {
return err
} else if fn != nil {
@@ -174,7 +172,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
keepURL := input.Bool(flagkey.PkgKeepURL)
// create new package in the same namespace as the function.
pkgMetadata, err = _package.CreatePackage(input, opts.client, fnNamespace, envName, envNamespace,
pkgMetadata, err = _package.CreatePackage(input, opts.client, fnName, fnNamespace, envName, envNamespace,
srcArchiveFiles, deployArchiveFiles, buildcmd, specDir, opts.specFile, noZip, keepURL)
if err != nil {
return errors.Wrap(err, "error creating package")
@@ -263,9 +261,9 @@ func (opts *CreateSubCommand) complete(input 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 {
func (opts *CreateSubCommand) run(input cli.Input) error {
// if we're writing a spec, don't create the function
if flags.Bool(flagkey.SpecSave) {
if input.Bool(flagkey.SpecSave) {
err := spec.SpecSave(*opts.function, opts.specFile)
if err != nil {
return errors.Wrap(err, "error creating function spec")
@@ -281,7 +279,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(flagkey.HtUrl)
triggerUrl := input.String(flagkey.HtUrl)
if len(triggerUrl) == 0 {
return nil
}
@@ -289,7 +287,7 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
triggerUrl = fmt.Sprintf("/%s", triggerUrl)
}
method, err := httptrigger.GetMethod(flags.String(flagkey.HtMethod))
method, err := httptrigger.GetMethod(input.String(flagkey.HtMethod))
if err != nil {
return errors.Wrap(err, "error getting HTTP trigger method")
}
@@ -318,11 +316,11 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
return nil
}
func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrategy) (strategy *fv1.InvokeStrategy, err error) {
func getInvokeStrategy(input cli.Input, existingInvokeStrategy *fv1.InvokeStrategy) (strategy *fv1.InvokeStrategy, err error) {
var fnExecutor, newFnExecutor fv1.ExecutorType
switch flags.String(flagkey.FnExecutorType) {
switch input.String(flagkey.FnExecutorType) {
case "":
fallthrough
case types.ExecutorTypePoolmgr:
@@ -337,23 +335,23 @@ 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(flagkey.FnExecutorType) {
if input.IsSet(flagkey.FnExecutorType) {
fnExecutor = newFnExecutor
}
} else {
fnExecutor = newFnExecutor
}
if flags.IsSet(flagkey.FnSpecializationTimeout) && fnExecutor != types.ExecutorTypeNewdeploy {
if input.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(flagkey.RuntimeTargetcpu) || flags.IsSet(flagkey.ReplicasMinscale) || flags.IsSet(flagkey.ReplicasMaxscale) {
if input.IsSet(flagkey.RuntimeTargetcpu) || input.IsSet(flagkey.ReplicasMinscale) || input.IsSet(flagkey.ReplicasMaxscale) {
return nil, errors.New("to set target CPU or min/max scale for function, please specify \"--executortype newdeploy\"")
}
if flags.IsSet(flagkey.RuntimeMincpu) || flags.IsSet(flagkey.RuntimeMaxcpu) || flags.IsSet(flagkey.RuntimeMinmemory) || flags.IsSet(flagkey.RuntimeMaxmemory) {
if input.IsSet(flagkey.RuntimeMincpu) || input.IsSet(flagkey.RuntimeMaxcpu) || input.IsSet(flagkey.RuntimeMinmemory) || input.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{
@@ -376,26 +374,26 @@ func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrate
specializationTimeout = existingInvokeStrategy.ExecutionStrategy.SpecializationTimeout
}
if flags.IsSet(flagkey.RuntimeTargetcpu) {
targetCPU, err = getTargetCPU(flags)
if input.IsSet(flagkey.RuntimeTargetcpu) {
targetCPU, err = getTargetCPU(input)
if err != nil {
return nil, err
}
}
if flags.IsSet(flagkey.ReplicasMinscale) {
minScale = flags.Int(flagkey.ReplicasMinscale)
if input.IsSet(flagkey.ReplicasMinscale) {
minScale = input.Int(flagkey.ReplicasMinscale)
}
if flags.IsSet(flagkey.ReplicasMaxscale) {
maxScale = flags.Int(flagkey.ReplicasMaxscale)
if input.IsSet(flagkey.ReplicasMaxscale) {
maxScale = input.Int(flagkey.ReplicasMaxscale)
if maxScale <= 0 {
return nil, errors.Errorf("%v must be greater than 0", flagkey.ReplicasMaxscale)
}
}
if flags.IsSet(flagkey.FnSpecializationTimeout) {
specializationTimeout = flags.Int(flagkey.FnSpecializationTimeout)
if input.IsSet(flagkey.FnSpecializationTimeout) {
specializationTimeout = input.Int(flagkey.FnSpecializationTimeout)
if specializationTimeout < fv1.DefaultSpecializationTimeOut {
return nil, errors.Errorf("%v must be greater than or equal to 120 seconds", flagkey.FnSpecializationTimeout)
}
@@ -422,8 +420,8 @@ func getInvokeStrategy(flags cli.Input, existingInvokeStrategy *fv1.InvokeStrate
return strategy, nil
}
func getTargetCPU(flags cli.Input) (int, error) {
targetCPU := flags.Int(flagkey.RuntimeTargetcpu)
func getTargetCPU(input cli.Input) (int, error) {
targetCPU := input.Int(flagkey.RuntimeTargetcpu)
if targetCPU <= 0 || targetCPU > 100 {
return 0, errors.Errorf("%v must be a value between 1 - 100", flagkey.RuntimeTargetcpu)
}
@@ -18,13 +18,13 @@ package function
import (
"fmt"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"testing"
"github.com/stretchr/testify/assert"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/dummy"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
)
func TestGetInvokeStrategy(t *testing.T) {
-3
View File
@@ -160,9 +160,6 @@ func doHTTPRequest(ctx context.Context, method, url, body string, headers []stri
func printPodLogs(input cli.Input) error {
fnName := input.String(flagkey.FnName)
if len(fnName) == 0 {
return errors.New("need --name argument.")
}
u, err := util.GetApplicationUrl("application=fission-api")
if err != nil {
+25 -27
View File
@@ -18,7 +18,6 @@ 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"
@@ -29,6 +28,7 @@ import (
"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/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"
)
@@ -61,18 +61,16 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
fnName := input.String(flagkey.FnName)
fnNamespace := input.String(flagkey.NamespaceFunction)
m, err := util.GetMetadata("name", "fnNamespace", input)
if err != nil {
return err
}
function, err := opts.client.FunctionGet(m)
function, err := opts.client.FunctionGet(&metav1.ObjectMeta{
Name: input.String(flagkey.FnName),
Namespace: input.String(flagkey.NamespaceFunction),
})
if err != nil {
return errors.Wrap(err, fmt.Sprintf("read function '%v'", fnName))
}
envName := input.String("env")
envNamespace := input.String("envNamespace")
envName := input.String(flagkey.FnEnvironmentName)
envNamespace := input.String(flagkey.NamespaceEnvironment)
// 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.
@@ -86,27 +84,27 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
var deployArchiveFiles []string
codeFlag := false
code := input.String("code")
code := input.String(flagkey.FnCode)
if len(code) == 0 {
deployArchiveFiles = input.StringSlice("deploy")
deployArchiveFiles = input.StringSlice(flagkey.PkgDeployArchive)
} else {
deployArchiveFiles = append(deployArchiveFiles, input.String("code"))
deployArchiveFiles = append(deployArchiveFiles, input.String(flagkey.FnCode))
codeFlag = true
}
srcArchiveFiles := input.StringSlice("src")
pkgName := input.String("pkg")
entrypoint := input.String("entrypoint")
buildcmd := input.String("buildcmd")
force := input.Bool("force")
srcArchiveFiles := input.StringSlice(flagkey.PkgSrcArchive)
pkgName := input.String(flagkey.FnPackageName)
entrypoint := input.String(flagkey.FnEntrypoint)
buildcmd := input.String(flagkey.PkgBuildCmd)
force := input.Bool(flagkey.PkgForce)
secretNames := input.StringSlice("secret")
cfgMapNames := input.StringSlice("configmap")
secretNames := input.StringSlice(flagkey.FnSecret)
cfgMapNames := input.StringSlice(flagkey.FnCfgMap)
specializationTimeout := input.Int("specializationtimeout")
specializationTimeout := input.Int(flagkey.FnSpecializationTimeout)
if len(srcArchiveFiles) > 0 && len(deployArchiveFiles) > 0 {
return errors.New("Need either of --src or --deploy and not both arguments.")
return errors.Errorf("need either of --%v or --%v and not both arguments", flagkey.PkgSrcArchive, flagkey.PkgDeployArchive)
}
var secrets []fv1.SecretReference
@@ -171,10 +169,10 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
function.Spec.Package.FunctionName = entrypoint
}
if input.IsSet("fntimeout") {
fnTimeout := input.Int("fntimeout")
if input.IsSet(flagkey.FnExecutionTimeout) {
fnTimeout := input.Int(flagkey.FnExecutionTimeout)
if fnTimeout <= 0 {
return errors.New("fntimeout must be greater than 0")
return errors.Errorf("--%v must be greater than 0", flagkey.FnExecutionTimeout)
}
function.Spec.FunctionTimeout = fnTimeout
}
@@ -189,13 +187,13 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
}
function.Spec.InvokeStrategy = *strategy
if input.IsSet("specializationtimeout") {
if input.IsSet(flagkey.FnSpecializationTimeout) {
if strategy.ExecutionStrategy.ExecutorType != types.ExecutorTypeNewdeploy {
return errors.New("specializationtimeout flag is only applicable for newdeploy type of executor")
return errors.Errorf("--%v flag is only applicable for newdeploy type of executor", flagkey.FnSpecializationTimeout)
}
if specializationTimeout < fv1.DefaultSpecializationTimeOut {
return errors.New("specializationtimeout must be greater than or equal to 120 seconds")
return errors.Errorf("--%v must be greater than or equal to 120 seconds", flagkey.FnSpecializationTimeout)
} else {
function.Spec.InvokeStrategy.ExecutionStrategy.SpecializationTimeout = specializationTimeout
}
+11 -12
View File
@@ -30,10 +30,10 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.HtUrl, flag.HtFnName},
Optional: []flag.Flag{flag.HtName, flag.HtMethod, flag.HtIngressRule,
flag.HtIngressAnnotation, flag.HtIngressTLS, flag.HtIngress,
flag.HtFnWeight, flag.HtHost, flag.NamespaceFunction, flag.SpecSave},
})
getCmd := &cobra.Command{
@@ -43,7 +43,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Get),
}
wrapper.SetFlags(getCmd, flag.FlagSet{
Required: []flag.Flag{flag.HtNameFlag},
Required: []flag.Flag{flag.HtName},
})
updateCmd := &cobra.Command{
@@ -53,10 +53,10 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.HtName},
Optional: []flag.Flag{flag.NamespaceTrigger, flag.HtFnName, flag.HtUrl,
flag.HtMethod, flag.HtIngressRule, flag.HtIngressAnnotation,
flag.HtIngressTLS, flag.HtIngress, flag.HtFnWeight, flag.HtHost},
})
deleteCmd := &cobra.Command{
@@ -66,8 +66,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.HtNameFlag},
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnFilterFlag},
Optional: []flag.Flag{flag.HtName, flag.HtFnFilter, flag.NamespaceTrigger},
})
listCmd := &cobra.Command{
@@ -77,7 +76,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnFilterFlag},
Optional: []flag.Flag{flag.NamespaceTrigger, flag.HtFnFilter},
})
command := &cobra.Command{
+38 -41
View File
@@ -31,6 +31,7 @@ import (
"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/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -39,28 +40,28 @@ type CreateSubCommand struct {
trigger *fv1.HTTPTrigger
}
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 {
functionList := flags.StringSlice("function")
functionWeightsList := flags.IntSlice("weight")
func (opts *CreateSubCommand) complete(input cli.Input) error {
functionList := input.StringSlice(flagkey.HtFnName)
functionWeightsList := input.IntSlice(flagkey.HtFnWeight)
if len(functionList) == 0 {
return errors.New("need a function name to create a trigger, use --function")
@@ -71,8 +72,13 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return err
}
triggerName := flags.String("name")
fnNamespace := flags.String("fnNamespace")
triggerName := input.String(flagkey.HtName)
// just name triggers by uuid.
if triggerName == "" {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.HtName))
triggerName = uuid.NewV4().String()
}
fnNamespace := input.String(flagkey.NamespaceFunction)
m := &metav1.ObjectMeta{
Name: triggerName,
@@ -87,44 +93,35 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return errors.New("duplicate trigger exists, choose a different name or leave it empty for fission to auto-generate it")
}
triggerUrl := flags.String("url")
if len(triggerUrl) == 0 {
return errors.New("need a trigger URL, use --url")
}
if !strings.HasPrefix(triggerUrl, "/") {
triggerUrl := input.String(flagkey.HtUrl)
if triggerUrl == "/" {
return errors.New("url with only root path is not allowed")
} else if !strings.HasPrefix(triggerUrl, "/") {
triggerUrl = fmt.Sprintf("/%s", triggerUrl)
}
method, err := GetMethod(flags.String("method"))
method, err := GetMethod(input.String(flagkey.HtMethod))
if err != nil {
return err
}
// For Specs, the spec validate checks for function reference
if !flags.Bool("spec") {
if !input.Bool(flagkey.SpecSave) {
err = util.CheckFunctionExistence(opts.client, functionList, fnNamespace)
if err != nil {
console.Warn(err.Error())
}
}
createIngress := flags.Bool("createingress")
createIngress := input.Bool(flagkey.HtIngress)
ingressConfig, err := GetIngressConfig(
flags.StringSlice("ingressannotation"), flags.String("ingressrule"),
flags.String("ingresstls"), triggerUrl, nil)
input.StringSlice(flagkey.HtIngressAnnotation), input.String(flagkey.HtIngressRule),
input.String(flagkey.HtIngressTLS), triggerUrl, nil)
if err != nil {
return errors.Wrap(err, "error parsing ingress configuration")
}
host := flags.String("host")
if flags.IsSet("host") {
console.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
}
// just name triggers by uuid.
if triggerName == "" {
triggerName = uuid.NewV4().String()
}
host := input.String(flagkey.HtHost)
opts.trigger = &fv1.HTTPTrigger{
Metadata: metav1.ObjectMeta{
@@ -144,9 +141,9 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *CreateSubCommand) run(flags cli.Input) error {
func (opts *CreateSubCommand) run(input cli.Input) error {
// if we're writing a spec, don't call the API
if flags.Bool("spec") {
if input.Bool(flagkey.SpecSave) {
specFile := fmt.Sprintf("route-%v.yaml", opts.trigger.Metadata.Name)
err := spec.SpecSave(*opts.trigger, specFile)
if err != nil {
@@ -168,23 +165,23 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
// GetMethod returns one of HTTP method
func GetMethod(method string) (string, error) {
switch strings.ToUpper(method) {
case "GET":
case http.MethodGet:
return http.MethodGet, nil
case "HEAD":
case http.MethodHead:
return http.MethodHead, nil
case "POST":
case http.MethodPost:
return http.MethodPost, nil
case "PUT":
case http.MethodPut:
return http.MethodPut, nil
case "PATCH":
case http.MethodPatch:
return http.MethodPatch, nil
case "DELETE":
case http.MethodDelete:
return http.MethodDelete, nil
case "CONNECT":
case http.MethodConnect:
return http.MethodConnect, nil
case "OPTIONS":
case http.MethodOptions:
return http.MethodOptions, nil
case "TRACE":
case http.MethodTrace:
return http.MethodTrace, nil
default:
return "", fmt.Errorf("invalid or unsupported HTTP Method %v", method)
+14 -13
View File
@@ -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"
"github.com/fission/fission/pkg/utils"
)
@@ -36,38 +37,38 @@ type DeleteSubCommand struct {
namespace string
}
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 {
err := opts.complete(flags)
func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
opts.triggerName = flags.String("name")
opts.functionName = flags.String("function")
func (opts *DeleteSubCommand) complete(input cli.Input) error {
opts.triggerName = input.String(flagkey.HtName)
opts.functionName = input.String(flagkey.HtFnName)
if len(opts.triggerName) == 0 && len(opts.functionName) == 0 {
return errors.New("need --name or --function")
return errors.Errorf("need --%v or --%v", flagkey.HtName, flagkey.HtFnName)
} else if len(opts.triggerName) > 0 && len(opts.functionName) > 0 {
return errors.New("need either of --name or --function and not both arguments")
return errors.Errorf("need either of --%v or --%v and not both arguments", flagkey.HtName, flagkey.HtFnName)
}
opts.namespace = flags.String("triggerNamespace")
opts.namespace = input.String(flagkey.NamespaceTrigger)
return nil
}
func (opts *DeleteSubCommand) run(flags cli.Input) error {
func (opts *DeleteSubCommand) run(input cli.Input) error {
triggers, err := opts.client.HTTPTriggerList(opts.namespace)
if err != nil {
return errors.Wrap(err, "error getting HTTP trigger list")
+10 -25
View File
@@ -28,48 +28,33 @@ 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"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
type GetSubCommand struct {
client *client.Client
trigger string
namespace string
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 {
err := opts.complete(flags)
if err != nil {
return err
}
return opts.run(flags)
func (opts *GetSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *GetSubCommand) complete(flags cli.Input) error {
opts.trigger = flags.String("name")
opts.namespace = flags.String("fnNamespace")
if len(opts.trigger) <= 0 {
return errors.New("need a trigger name, use --name")
}
return nil
}
func (opts *GetSubCommand) run(flags cli.Input) error {
func (opts *GetSubCommand) run(input cli.Input) error {
m := &metav1.ObjectMeta{
Name: opts.trigger,
Namespace: opts.namespace,
Name: input.String(flagkey.HtName),
Namespace: input.String(flagkey.NamespaceFunction),
}
ht, err := opts.client.HTTPTriggerGet(m)
if err != nil {
+13 -22
View File
@@ -22,51 +22,42 @@ 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"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
type ListSubCommand struct {
client *client.Client
triggerNamespace string
filterFunctionName string
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 {
err := opts.complete(flags)
if err != nil {
return err
}
return opts.run(flags)
func (opts *ListSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ListSubCommand) complete(flags cli.Input) error {
opts.triggerNamespace = flags.String("triggerNamespace")
opts.filterFunctionName = flags.String("function")
return nil
}
func (opts *ListSubCommand) run(flags cli.Input) error {
hts, err := opts.client.HTTPTriggerList(opts.triggerNamespace)
func (opts *ListSubCommand) run(input cli.Input) error {
hts, err := opts.client.HTTPTriggerList(input.String(flagkey.NamespaceTrigger))
if err != nil {
return errors.Wrap(err, "error listing HTTP triggers")
}
filterFunctionName := input.String(flagkey.HtFnName)
var triggers []fv1.HTTPTrigger
for _, ht := range hts {
// TODO: list canary http triggers as well.
if len(opts.filterFunctionName) == 0 ||
(len(opts.filterFunctionName) > 0 && opts.filterFunctionName == ht.Spec.FunctionReference.Name) {
if len(filterFunctionName) == 0 ||
(len(filterFunctionName) > 0 && filterFunctionName == ht.Spec.FunctionReference.Name) {
triggers = append(triggers, ht)
}
+2 -1
View File
@@ -24,7 +24,8 @@ import (
)
// GetIngressConfig returns an IngressConfig based on user inputs; return error if any.
func GetIngressConfig(annotations []string, rule string, tls string, fallbackRelativeURL string, oldIngressConfig *fv1.IngressConfig) (*fv1.IngressConfig, error) {
func GetIngressConfig(annotations []string, rule string, tls string,
fallbackRelativeURL string, oldIngressConfig *fv1.IngressConfig) (*fv1.IngressConfig, error) {
removeAnns, anns, err := getIngressAnnotations(annotations)
if err != nil {
+23 -26
View File
@@ -26,6 +26,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/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -34,31 +35,28 @@ type UpdateSubCommand struct {
trigger *fv1.HTTPTrigger
}
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 {
htName := flags.String("name")
if len(htName) == 0 {
return errors.New("need name of trigger, use --name")
}
triggerNamespace := flags.String("triggerNamespace")
func (opts *UpdateSubCommand) complete(input cli.Input) error {
htName := input.String(flagkey.HtName)
triggerNamespace := input.String(flagkey.NamespaceTrigger)
ht, err := opts.client.HTTPTriggerGet(&metav1.ObjectMeta{
Name: htName,
@@ -68,17 +66,17 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
return errors.Wrap(err, "error getting HTTP trigger")
}
if flags.IsSet("function") {
if input.IsSet(flagkey.HtFnName) {
// get the functions and their weights if specified
functionList := flags.StringSlice("function")
functionList := input.StringSlice(flagkey.HtFnName)
err := util.CheckFunctionExistence(opts.client, functionList, triggerNamespace)
if err != nil {
console.Warn(err.Error())
}
var functionWeightsList []int
if flags.IsSet("weight") {
functionWeightsList = flags.IntSlice("weight")
if input.IsSet(flagkey.HtFnWeight) {
functionWeightsList = input.IntSlice(flagkey.HtFnWeight)
}
// set function reference
@@ -90,21 +88,20 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
ht.Spec.FunctionReference = *functionRef
}
if flags.IsSet("createingress") {
ht.Spec.CreateIngress = flags.Bool("createingress")
if input.IsSet(flagkey.HtIngress) {
ht.Spec.CreateIngress = input.Bool(flagkey.HtIngress)
}
if flags.IsSet("host") {
ht.Spec.Host = flags.String("host")
console.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
if input.IsSet(flagkey.HtHost) {
ht.Spec.Host = input.String(flagkey.HtHost)
}
if flags.IsSet("ingressrule") || flags.IsSet("ingressannotation") || flags.IsSet("ingresstls") {
if input.IsSet(flagkey.HtIngressRule) || input.IsSet(flagkey.HtIngressAnnotation) || input.IsSet(flagkey.HtIngressTLS) {
ingress, err := GetIngressConfig(
flags.StringSlice("ingressannotation"), flags.String("ingressrule"),
flags.String("ingresstls"), ht.Spec.RelativeURL, &ht.Spec.IngressConfig)
input.StringSlice(flagkey.HtIngressAnnotation), input.String(flagkey.HtIngressRule),
input.String(flagkey.HtIngressTLS), ht.Spec.RelativeURL, &ht.Spec.IngressConfig)
if err != nil {
return errors.Wrap(err, "parse ingress configuration")
return errors.Wrap(err, "error parsing ingress configuration")
}
ht.Spec.IngressConfig = *ingress
}
@@ -114,7 +111,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.HTTPTriggerUpdate(opts.trigger)
if err != nil {
return errors.Wrap(err, "error updating the HTTP trigger")
+7 -5
View File
@@ -30,8 +30,10 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.KwFnName},
Optional: []flag.Flag{flag.KwName, flag.KwObjType, flag.NamespaceFunction, flag.SpecSave},
// TODO: add label selector flag
// flag.KwLabelsFlag
})
deleteCmd := &cobra.Command{
@@ -41,8 +43,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.KwFnNameFlag},
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Required: []flag.Flag{flag.KwFnName},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
listCmd := &cobra.Command{
@@ -52,7 +54,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
command := &cobra.Command{
+20 -38
View File
@@ -27,6 +27,8 @@ 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/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -35,55 +37,35 @@ type CreateSubCommand struct {
watcher *fv1.KubernetesWatchTrigger
}
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 {
fnName := flags.String("function")
if len(fnName) == 0 {
return errors.New("Need a function name to create a watch, use --function")
func (opts *CreateSubCommand) complete(input cli.Input) error {
watchName := input.String(flagkey.KwName)
if len(watchName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
watchName = uuid.NewV4().String()
}
fnNamespace := flags.String("fnNamespace")
namespace := flags.String("ns")
if len(namespace) == 0 {
fmt.Println("Watch 'default' namespace. Use --ns <namespace> to override.")
namespace = "default"
}
objType := flags.String("type")
if len(objType) == 0 {
fmt.Println("Object type unspecified, will watch pods. Use --type <type> to override.")
objType = "pod"
}
labels := flags.String("labels")
// empty 'labels' selects everything
if len(labels) == 0 {
fmt.Printf("Watching all objects of type '%v', use --labels to refine selection.\n", objType)
} else {
// TODO
fmt.Printf("Label selector not implemented, watching all objects")
}
// automatically name watches
watchName := uuid.NewV4().String()
fnName := input.String(flagkey.KwFnName)
fnNamespace := input.String(flagkey.NamespaceFunction)
namespace := input.String(flagkey.KwNamespace)
objType := input.String(flagkey.KwObjType)
opts.watcher = &fv1.KubernetesWatchTrigger{
Metadata: metav1.ObjectMeta{
@@ -104,9 +86,9 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *CreateSubCommand) run(flags cli.Input) error {
func (opts *CreateSubCommand) run(input cli.Input) error {
// if we're writing a spec, don't call the API
if flags.Bool("spec") {
if input.Bool(flagkey.SpecSave) {
specFile := fmt.Sprintf("kubewatch-%v.yaml", opts.watcher.Metadata.Name)
err := spec.SpecSave(*opts.watcher, specFile)
if err != nil {
@@ -120,6 +102,6 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
return errors.Wrap(err, "error creating kubewatch")
}
fmt.Printf("kubewatch '%v' created\n", opts.watcher.Metadata.Name)
fmt.Printf("trigger '%v' created\n", opts.watcher.Metadata.Name)
return nil
}
+12 -14
View File
@@ -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"
)
@@ -33,35 +34,32 @@ type DeleteSubCommand struct {
namespace string
}
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 {
err := opts.complete(flags)
func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
opts.name = flags.String("name")
if len(opts.name) == 0 {
return errors.New("need name of watch to delete, use --name")
}
opts.namespace = flags.String("triggerns")
func (opts *DeleteSubCommand) complete(input cli.Input) error {
opts.name = input.String(flagkey.KwName)
opts.namespace = input.String(flagkey.NamespaceTrigger)
return nil
}
func (opts *DeleteSubCommand) run(flags cli.Input) error {
func (opts *DeleteSubCommand) run(input cli.Input) error {
err := opts.client.WatchDelete(&metav1.ObjectMeta{
Name: opts.name,
Namespace: opts.namespace,
@@ -70,6 +68,6 @@ func (opts *DeleteSubCommand) run(flags cli.Input) error {
return errors.Wrap(err, "error deleting kubewatch")
}
fmt.Printf("watch '%v' deleted\n", opts.name)
fmt.Printf("trigger '%v' deleted\n", opts.name)
return nil
}
+10 -9
View File
@@ -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,31 +34,31 @@ 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("triggerns")
func (opts *ListSubCommand) complete(input cli.Input) error {
opts.namespace = input.String(flagkey.NamespaceTrigger)
return nil
}
func (opts *ListSubCommand) run(flags cli.Input) error {
func (opts *ListSubCommand) run(input cli.Input) error {
ws, err := opts.client.WatchList(opts.namespace)
if err != nil {
return errors.Wrap(err, "error listing kubewatches")
+10 -10
View File
@@ -30,10 +30,10 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.MqtFnName, flag.MqtTopic},
Optional: []flag.Flag{flag.MqtName, flag.NamespaceFunction, flag.MqtMQType,
flag.MqtRespTopic, flag.MqtErrorTopic, flag.MqtMaxRetries, flag.MqtMsgContentType,
flag.SpecSave},
})
updateCmd := &cobra.Command{
@@ -43,9 +43,9 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.MqtName},
Optional: []flag.Flag{flag.NamespaceTrigger, flag.MqtTopic, flag.MqtRespTopic,
flag.MqtErrorTopic, flag.MqtMaxRetries, flag.MqtFnName, flag.MqtMsgContentType},
})
deleteCmd := &cobra.Command{
@@ -55,8 +55,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.MqtNameFlag},
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Required: []flag.Flag{flag.MqtName},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
listCmd := &cobra.Command{
@@ -66,7 +66,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
command := &cobra.Command{
+26 -28
View File
@@ -27,6 +27,8 @@ 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/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"
)
@@ -36,38 +38,36 @@ type CreateSubCommand struct {
trigger *fv1.MessageQueueTrigger
}
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 {
mqtName := flags.String("name")
func (opts *CreateSubCommand) complete(input cli.Input) error {
mqtName := input.String(flagkey.MqtName)
if len(mqtName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
mqtName = uuid.NewV4().String()
}
fnName := flags.String("function")
if len(fnName) == 0 {
return errors.New("Need a function name to create a trigger, use --function")
}
fnNamespace := flags.String("fnNamespace")
fnName := input.String(flagkey.MqtFnName)
fnNamespace := input.String(flagkey.NamespaceFunction)
var mqType fv1.MessageQueueType
switch flags.String("mqtype") {
switch input.String(flagkey.MqtMQType) {
case "":
mqType = types.MessageQueueTypeNats
case types.MessageQueueTypeNats:
@@ -80,28 +80,26 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return errors.New("Unknown message queue type, currently only \"nats-streaming, azure-storage-queue, kafka \" is supported")
}
// TODO: check topic availability
topic := flags.String("topic")
topic := input.String(flagkey.MqtTopic)
if len(topic) == 0 {
return errors.New("Topic cannot be empty")
return errors.New("topic cannot be empty")
}
respTopic := flags.String("resptopic")
respTopic := input.String(flagkey.MqtRespTopic)
if topic == respTopic {
// TODO maybe this should just be a warning, perhaps
// allow it behind a --force flag
return errors.New("Listen topic should not equal to response topic")
return errors.New("listen topic should not equal to response topic")
}
errorTopic := flags.String("errortopic")
maxRetries := flags.Int("maxretries")
errorTopic := input.String(flagkey.MqtErrorTopic)
maxRetries := input.Int(flagkey.MqtMaxRetries)
if maxRetries < 0 {
return errors.New("Maximum number of retries must be a natural number, default is 0")
return errors.New("Maximum number of retries must be greater than or equal to 0")
}
contentType := flags.String("contenttype")
contentType := input.String(flagkey.MqtMsgContentType)
if len(contentType) == 0 {
contentType = "application/json"
}
@@ -133,9 +131,9 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *CreateSubCommand) run(flags cli.Input) error {
func (opts *CreateSubCommand) run(input cli.Input) error {
// if we're writing a spec, don't call the API
if flags.Bool("spec") {
if input.Bool(flagkey.SpecSave) {
specFile := fmt.Sprintf("mqtrigger-%v.yaml", opts.trigger.Metadata.Name)
err := spec.SpecSave(*opts.trigger, specFile)
if err != nil {
@@ -149,14 +147,14 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
return errors.Wrap(err, "create message queue trigger")
}
fmt.Printf("message queue trigger '%s' created\n", opts.trigger.Metadata.Name)
fmt.Printf("trigger '%s' created\n", opts.trigger.Metadata.Name)
return nil
}
func checkMQTopicAvailability(mqType fv1.MessageQueueType, topics ...string) error {
for _, t := range topics {
if len(t) > 0 && !fv1.IsTopicValid(mqType, t) {
return errors.Errorf("Invalid topic for %s: %s", mqType, t)
return errors.Errorf("invalid topic for %s: %s", mqType, t)
}
}
return nil
+14 -14
View File
@@ -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"
)
@@ -32,40 +33,39 @@ type DeleteSubCommand struct {
metadata *metav1.ObjectMeta
}
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 {
err := opts.complete(flags)
func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
m, err := util.GetMetadata("name", "triggerns", flags)
if err != nil {
return err
func (opts *DeleteSubCommand) complete(input cli.Input) error {
opts.metadata = &metav1.ObjectMeta{
Name: input.String(flagkey.MqtName),
Namespace: input.String(flagkey.NamespaceTrigger),
}
opts.metadata = m
return nil
}
func (opts *DeleteSubCommand) run(flags cli.Input) error {
err := opts.client.WatchDelete(opts.metadata)
func (opts *DeleteSubCommand) run(input cli.Input) error {
err := opts.client.MessageQueueTriggerDelete(opts.metadata)
if err != nil {
return errors.Wrap(err, "error deleting message queue trigger")
}
fmt.Printf("message queue trigger '%v' deleted\n", opts.metadata.Name)
fmt.Printf("trigger '%v' deleted\n", opts.metadata.Name)
return nil
}
+11 -10
View File
@@ -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,32 +34,32 @@ 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("triggerns")
func (opts *ListSubCommand) complete(input cli.Input) error {
opts.namespace = input.String(flagkey.NamespaceTrigger)
return nil
}
func (opts *ListSubCommand) run(flags cli.Input) error {
mqts, err := opts.client.MessageQueueTriggerList(flags.String("mqtype"), opts.namespace)
func (opts *ListSubCommand) run(input cli.Input) error {
mqts, err := opts.client.MessageQueueTriggerList(input.String(flagkey.MqtMQType), opts.namespace)
if err != nil {
return errors.Wrap(err, "error listing message queue triggers")
}
+21 -21
View File
@@ -20,10 +20,12 @@ import (
"fmt"
"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"
)
@@ -32,42 +34,40 @@ type UpdateSubCommand struct {
trigger *fv1.MessageQueueTrigger
}
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("name", "triggerns", flags)
if err != nil {
return err
}
mqt, err := opts.client.MessageQueueTriggerGet(m)
func (opts *UpdateSubCommand) complete(input cli.Input) error {
mqt, err := opts.client.MessageQueueTriggerGet(&metav1.ObjectMeta{
Name: input.String(flagkey.MqtName),
Namespace: input.String(flagkey.NamespaceTrigger),
})
if err != nil {
return errors.Wrap(err, "error getting message queue trigger")
}
topic := flags.String("topic")
respTopic := flags.String("resptopic")
errorTopic := flags.String("errortopic")
maxRetries := flags.Int("maxretries")
fnName := flags.String("function")
contentType := flags.String("contenttype")
topic := input.String(flagkey.MqtTopic)
respTopic := input.String(flagkey.MqtRespTopic)
errorTopic := input.String(flagkey.MqtErrorTopic)
maxRetries := input.Int(flagkey.MqtMaxRetries)
fnName := input.String(flagkey.MqtFnName)
contentType := input.String(flagkey.MqtMsgContentType)
// TODO : Find out if we can make a call to checkIfFunctionExists, in the same ns more importantly.
@@ -103,14 +103,14 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
}
if !updated {
return errors.New("Nothing to update. Use --topic, --resptopic, --errortopic, --maxretries or --function.")
return errors.New("Nothing changed, see 'help' for more details")
}
opts.trigger = mqt
return nil
}
func (opts *UpdateSubCommand) run(flags cli.Input) error {
func (opts *UpdateSubCommand) run(input cli.Input) error {
_, err := opts.client.MessageQueueTriggerUpdate(opts.trigger)
if err != nil {
return errors.Wrap(err, "error updating message queue trigger")
+17 -16
View File
@@ -30,9 +30,9 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.PkgEnvironment},
Optional: []flag.Flag{flag.PkgName, flag.NamespacePackage, flag.NamespaceEnvironment,
flag.PkgSrcArchive, flag.PkgDeployArchive, flag.PkgKeepURL, flag.PkgBuildCmd},
})
getSrcCmd := &cobra.Command{
@@ -41,8 +41,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(GetSrc),
}
wrapper.SetFlags(getSrcCmd, flag.FlagSet{
Required: []flag.Flag{flag.PkgNameFlag},
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.PkgOutputFlag},
Required: []flag.Flag{flag.PkgName},
Optional: []flag.Flag{flag.NamespacePackage, flag.PkgOutput},
})
getDeployCmd := &cobra.Command{
@@ -51,8 +51,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(GetDeploy),
}
wrapper.SetFlags(getDeployCmd, flag.FlagSet{
Required: []flag.Flag{flag.PkgNameFlag},
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.PkgOutputFlag},
Required: []flag.Flag{flag.PkgName},
Optional: []flag.Flag{flag.NamespacePackage, flag.PkgOutput},
})
updateCmd := &cobra.Command{
@@ -61,10 +61,10 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.PkgName},
Optional: []flag.Flag{flag.NamespacePackage, flag.PkgEnvironment, flag.NamespaceEnvironment,
flag.PkgSrcArchive, flag.PkgDeployArchive, flag.PkgKeepURL,
flag.PkgBuildCmd, flag.PkgForce},
})
deleteCmd := &cobra.Command{
@@ -73,8 +73,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.PkgNameFlag},
Optional: []flag.Flag{flag.NamespacePackageFlag, flag.PkgForceFlag, flag.PkgOrphanFlag},
Optional: []flag.Flag{flag.PkgName, flag.NamespacePackage, flag.PkgForce, flag.PkgOrphan},
})
listCmd := &cobra.Command{
@@ -83,7 +82,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.PkgOrphanFlag, flag.PkgStatusFlag, flag.NamespacePackageFlag},
Optional: []flag.Flag{flag.PkgOrphan, flag.PkgStatus, flag.NamespacePackage},
})
infoCmd := &cobra.Command{
@@ -92,7 +91,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(infoCmd, flag.FlagSet{
Optional: []flag.Flag{flag.PkgNameFlag, flag.NamespacePackageFlag},
Required: []flag.Flag{flag.PkgName},
Optional: []flag.Flag{flag.NamespacePackage},
})
rebuildCmd := &cobra.Command{
@@ -101,7 +101,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(rebuildCmd, flag.FlagSet{
Optional: []flag.Flag{flag.PkgNameFlag, flag.NamespacePackageFlag},
Required: []flag.Flag{flag.PkgName},
Optional: []flag.Flag{flag.NamespacePackage},
})
command := &cobra.Command{
+28 -23
View File
@@ -31,6 +31,8 @@ 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/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -38,49 +40,49 @@ type CreateSubCommand struct {
client *client.Client
}
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.run(input)
if err != nil {
return err
}
//return opts.run(flags)
return nil
}
func (opts *CreateSubCommand) complete(flags cli.Input) error {
pkgNamespace := flags.String("pkgNamespace")
envName := flags.String("env")
if len(envName) == 0 {
return errors.New("Need --env argument.")
func (opts *CreateSubCommand) run(input cli.Input) error {
pkgName := input.String(flagkey.PkgName)
if len(pkgName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.HtName))
}
envNamespace := flags.String("envNamespace")
srcArchiveFiles := flags.StringSlice("src")
deployArchiveFiles := flags.StringSlice("deploy")
buildcmd := flags.String("buildcmd")
keepURL := flags.Bool("keepurl")
pkgNamespace := input.String(flagkey.NamespacePackage)
envName := input.String(flagkey.PkgEnvironment)
envNamespace := input.String(flagkey.NamespaceEnvironment)
srcArchiveFiles := input.StringSlice(flagkey.PkgSrcArchive)
deployArchiveFiles := input.StringSlice(flagkey.PkgDeployArchive)
buildcmd := input.String(flagkey.PkgBuildCmd)
keepURL := input.Bool(flagkey.PkgKeepURL)
if len(srcArchiveFiles) == 0 && len(deployArchiveFiles) == 0 {
return errors.New("Need --src to specify source archive, or use --deploy to specify deployment archive.")
return errors.Errorf("need --%v or --%v flag", flagkey.PkgSrcArchive, flagkey.PkgDeployArchive)
}
_, err := CreatePackage(flags, opts.client, pkgNamespace, envName, envNamespace,
_, err := CreatePackage(input, opts.client, pkgName, pkgNamespace, envName, envNamespace,
srcArchiveFiles, deployArchiveFiles, buildcmd, "", "", false, keepURL)
return err
}
func CreatePackage(flags cli.Input, client *client.Client, pkgNamespace string, envName string, envNamespace string,
func CreatePackage(input cli.Input, client *client.Client, pkgName string, pkgNamespace string, envName string, envNamespace string,
srcArchiveFiles []string, deployArchiveFiles []string, buildcmd string, specDir string, specFile string, noZip bool, keepURL bool) (*metav1.ObjectMeta, error) {
pkgSpec := fv1.PackageSpec{
@@ -91,7 +93,6 @@ func CreatePackage(flags cli.Input, client *client.Client, pkgNamespace string,
}
var pkgStatus fv1.BuildStatus = fv1.BuildStatusSucceeded
var pkgName string
if len(deployArchiveFiles) > 0 {
if len(specFile) > 0 { // we should do this in all cases, i think
pkgStatus = fv1.BuildStatusNone
@@ -101,7 +102,9 @@ func CreatePackage(flags cli.Input, client *client.Client, pkgNamespace string,
return nil, err
}
pkgSpec.Deployment = *deployment
pkgName = util.KubifyName(fmt.Sprintf("%v-%v", path.Base(deployArchiveFiles[0]), uniuri.NewLen(4)))
if len(pkgName) == 0 {
pkgName = util.KubifyName(fmt.Sprintf("%v-%v", path.Base(deployArchiveFiles[0]), uniuri.NewLen(4)))
}
}
if len(srcArchiveFiles) > 0 {
source, err := CreateArchive(client, srcArchiveFiles, false, keepURL, specDir, specFile)
@@ -110,7 +113,9 @@ func CreatePackage(flags cli.Input, client *client.Client, pkgNamespace string,
}
pkgSpec.Source = *source
pkgStatus = fv1.BuildStatusPending // set package build status to pending
pkgName = util.KubifyName(fmt.Sprintf("%v-%v", path.Base(srcArchiveFiles[0]), uniuri.NewLen(4)))
if len(pkgName) == 0 {
pkgName = util.KubifyName(fmt.Sprintf("%v-%v", path.Base(srcArchiveFiles[0]), uniuri.NewLen(4)))
}
}
if len(buildcmd) > 0 {
@@ -134,7 +139,7 @@ func CreatePackage(flags cli.Input, client *client.Client, pkgNamespace string,
if len(specFile) > 0 {
// if a package sith the same spec exists, don't create a new spec file
fr, err := spec.ReadSpecs(util.GetSpecDir(flags))
fr, err := spec.ReadSpecs(util.GetSpecDir(input))
if err != nil {
return nil, errors.Wrap(err, "error reading specs")
}
+18 -17
View File
@@ -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"
)
@@ -35,42 +36,39 @@ type DeleteSubCommand struct {
force bool
}
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 {
err := opts.complete(flags)
func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
opts.name = flags.String("name")
opts.namespace = flags.String("pkgNamespace")
opts.deleteOrphans = flags.Bool("orphan")
opts.force = flags.Bool("f")
func (opts *DeleteSubCommand) complete(input cli.Input) error {
opts.name = input.String(flagkey.PkgName)
opts.namespace = input.String(flagkey.NamespacePackage)
opts.deleteOrphans = input.Bool(flagkey.PkgOrphan)
opts.force = input.Bool(flagkey.PkgForce)
if len(opts.name) == 0 && !opts.deleteOrphans {
return errors.New("need --name argument or --orphan flag")
}
if len(opts.name) != 0 && opts.deleteOrphans {
return errors.New("need either --name argument or --orphan flag")
return errors.Errorf("need --%v or --%v flag", flagkey.PkgName, flagkey.PkgOrphan)
}
return nil
}
func (opts *DeleteSubCommand) run(flags cli.Input) error {
func (opts *DeleteSubCommand) run(input cli.Input) error {
if len(opts.name) != 0 {
_, err := opts.client.PackageGet(&metav1.ObjectMeta{
Namespace: opts.namespace,
@@ -93,7 +91,10 @@ func (opts *DeleteSubCommand) run(flags cli.Input) error {
return err
}
fmt.Printf("Package '%v' deleted\n", opts.name)
} else {
}
// TODO improve list speed when --orphan
if opts.deleteOrphans {
err := deleteOrphanPkgs(opts.client, opts.namespace)
if err != nil {
return errors.Wrap(err, "deleting orphan packages")
+15 -18
View File
@@ -18,7 +18,6 @@ package _package
import (
"bytes"
"errors"
"io"
"os"
@@ -28,6 +27,7 @@ import (
"github.com/fission/fission/pkg/controller/client"
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -44,8 +44,8 @@ type GetSubCommand struct {
archiveType int
}
func GetSrc(flags cli.Input) error {
c, err := util.GetServer(flags)
func GetSrc(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
@@ -53,11 +53,11 @@ func GetSrc(flags cli.Input) error {
client: c,
archiveType: sourceArchive,
}
return opts.do(flags)
return opts.do(input)
}
func GetDeploy(flags cli.Input) error {
c, err := util.GetServer(flags)
func GetDeploy(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
@@ -65,28 +65,25 @@ func GetDeploy(flags cli.Input) error {
client: c,
archiveType: deployArchive,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *GetSubCommand) do(flags cli.Input) error {
err := opts.complete(flags)
func (opts *GetSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *GetSubCommand) complete(flags cli.Input) error {
opts.name = flags.String("name")
if len(opts.name) == 0 {
return errors.New("need name of package, use --name")
}
opts.namespace = flags.String("pkgNamespace")
opts.output = flags.String("output")
func (opts *GetSubCommand) complete(input cli.Input) error {
opts.name = input.String(flagkey.PkgName)
opts.namespace = input.String(flagkey.NamespacePackage)
opts.output = input.String(flagkey.PkgOutput)
return nil
}
func (opts *GetSubCommand) run(flags cli.Input) error {
func (opts *GetSubCommand) run(input cli.Input) error {
pkg, err := opts.client.PackageGet(&metav1.ObjectMeta{
Namespace: opts.namespace,
Name: opts.name,
+11 -13
View File
@@ -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"
)
@@ -35,35 +36,32 @@ type InfoSubCommand struct {
namespace string
}
func Info(flags cli.Input) error {
c, err := util.GetServer(flags)
func Info(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := InfoSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *InfoSubCommand) do(flags cli.Input) error {
err := opts.complete(flags)
func (opts *InfoSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *InfoSubCommand) complete(flags cli.Input) error {
opts.name = flags.String("name")
if len(opts.name) == 0 {
return errors.New("Need name of package, use --name")
}
opts.namespace = flags.String("pkgNamespace")
func (opts *InfoSubCommand) complete(input cli.Input) error {
opts.name = input.String(flagkey.PkgName)
opts.namespace = input.String("pkgNamespace")
return nil
}
func (opts *InfoSubCommand) run(flags cli.Input) error {
func (opts *InfoSubCommand) run(input cli.Input) error {
pkg, err := opts.client.PackageGet(&metav1.ObjectMeta{
Namespace: opts.namespace,
Name: opts.name,
+13 -11
View File
@@ -27,6 +27,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"
)
@@ -37,34 +38,34 @@ type ListSubCommand struct {
pkgNamespace 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 {
func (opts *ListSubCommand) complete(input cli.Input) error {
// option for the user to list all orphan packages (not referenced by any function)
opts.listOrphans = flags.Bool("orphan")
opts.status = flags.String("status")
opts.pkgNamespace = flags.String("pkgNamespace")
opts.listOrphans = input.Bool(flagkey.PkgOrphan)
opts.status = input.String(flagkey.PkgStatus)
opts.pkgNamespace = input.String(flagkey.NamespacePackage)
return nil
}
func (opts *ListSubCommand) run(flags cli.Input) error {
func (opts *ListSubCommand) run(input cli.Input) error {
pkgList, err := opts.client.PackageList(opts.pkgNamespace)
if err != nil {
return err
@@ -80,6 +81,7 @@ func (opts *ListSubCommand) run(flags cli.Input) error {
for _, pkg := range pkgList {
show := true
// TODO improve list speed when --orphan
if opts.listOrphans {
fnList, err := GetFunctionsByPackage(opts.client, pkg.Metadata.Name, pkg.Metadata.Namespace)
if err != nil {
+11 -13
View File
@@ -25,6 +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"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -34,35 +35,32 @@ type RebuildSubCommand struct {
namespace string
}
func Rebuild(flags cli.Input) error {
c, err := util.GetServer(flags)
func Rebuild(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := RebuildSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *RebuildSubCommand) do(flags cli.Input) error {
err := opts.complete(flags)
func (opts *RebuildSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *RebuildSubCommand) complete(flags cli.Input) error {
opts.name = flags.String("name")
if len(opts.name) == 0 {
return errors.New("Need name of package, use --name")
}
opts.namespace = flags.String("pkgNamespace")
func (opts *RebuildSubCommand) complete(input cli.Input) error {
opts.name = input.String(flagkey.PkgName)
opts.namespace = input.String(flagkey.NamespacePackage)
return nil
}
func (opts *RebuildSubCommand) run(flags cli.Input) error {
func (opts *RebuildSubCommand) run(input cli.Input) error {
pkg, err := opts.client.PackageGet(&metav1.ObjectMeta{
Name: opts.name,
Namespace: opts.namespace,
+18 -29
View File
@@ -26,6 +26,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"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -42,51 +43,39 @@ type UpdateSubCommand struct {
keepURL bool
}
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 {
opts.pkgName = flags.String("name")
if len(opts.pkgName) == 0 {
return errors.New("Need --name argument.")
}
opts.pkgNamespace = flags.String("pkgNamespace")
opts.force = flags.Bool("f")
opts.envName = flags.String("env")
opts.envNamespace = flags.String("envNamespace")
opts.srcArchiveFiles = flags.StringSlice("src")
opts.deployArchiveFiles = flags.StringSlice("deploy")
opts.buildcmd = flags.String("buildcmd")
opts.keepURL = flags.Bool("keepurl")
if len(opts.srcArchiveFiles) > 0 && len(opts.deployArchiveFiles) > 0 {
return errors.New("Need either of --src or --deploy and not both arguments.")
}
if len(opts.srcArchiveFiles) == 0 && len(opts.deployArchiveFiles) == 0 &&
len(opts.envName) == 0 && len(opts.buildcmd) == 0 {
return errors.New("Need --env or --src or --deploy or --buildcmd argument.")
}
func (opts *UpdateSubCommand) complete(input cli.Input) error {
opts.pkgName = input.String(flagkey.PkgName)
opts.pkgNamespace = input.String(flagkey.NamespacePackage)
opts.force = input.Bool(flagkey.PkgForce)
opts.envName = input.String(flagkey.PkgEnvironment)
opts.envNamespace = input.String(flagkey.NamespaceEnvironment)
opts.srcArchiveFiles = input.StringSlice(flagkey.PkgSrcArchive)
opts.deployArchiveFiles = input.StringSlice(flagkey.PkgDeployArchive)
opts.buildcmd = input.String(flagkey.PkgBuildCmd)
opts.keepURL = input.Bool(flagkey.PkgKeepURL)
return nil
}
func (opts *UpdateSubCommand) run(flags cli.Input) error {
func (opts *UpdateSubCommand) run(input cli.Input) error {
pkg, err := opts.client.PackageGet(&metav1.ObjectMeta{
Namespace: opts.pkgNamespace,
Name: opts.pkgName,
+4 -4
View File
@@ -31,18 +31,18 @@ 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 {
func (opts *ListSubCommand) do(input cli.Input) error {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
fmt.Fprintln(w, "NAME\tVERSION\tPATH")
for _, p := range plugin.FindAll() {
+7 -7
View File
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Create),
}
wrapper.SetFlags(createCmd, flag.FlagSet{
Optional: []flag.Flag{flag.RecorderNameFlag, flag.RecorderFnFlag, flag.RecorderTriggersFlag, flag.SpecSaveFlag},
Optional: []flag.Flag{flag.RecorderName, flag.RecorderFn, flag.RecorderTriggers, flag.SpecSave},
})
getCmd := &cobra.Command{
@@ -39,7 +39,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Get),
}
wrapper.SetFlags(getCmd, flag.FlagSet{
Required: []flag.Flag{flag.RecorderNameFlag},
Required: []flag.Flag{flag.RecorderName},
})
updateCmd := &cobra.Command{
@@ -48,8 +48,8 @@ func Commands() *cobra.Command {
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},
Required: []flag.Flag{flag.RecorderName},
Optional: []flag.Flag{flag.RecorderFn, flag.RecorderTriggers, flag.RecorderEnabled, flag.RecorderDisabled},
})
deleteCmd := &cobra.Command{
@@ -58,8 +58,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.RecorderNameFlag},
Optional: []flag.Flag{flag.NamespaceRecorderFlag},
Required: []flag.Flag{flag.RecorderName},
Optional: []flag.Flag{flag.NamespaceRecorder},
})
listCmd := &cobra.Command{
@@ -68,7 +68,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceRecorderFlag},
Optional: []flag.Flag{flag.NamespaceRecorder},
})
command := &cobra.Command{
+12 -12
View File
@@ -36,32 +36,32 @@ type CreateSubCommand struct {
recorder *fv1.Recorder
}
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 {
recName := flags.String("name")
func (opts *CreateSubCommand) complete(input cli.Input) error {
recName := input.String("name")
if len(recName) == 0 {
recName = uuid.NewV4().String()
}
fnName := flags.String("function")
triggersOriginal := flags.StringSlice("trigger")
fnName := input.String("function")
triggersOriginal := input.StringSlice("trigger")
// Function XOR triggers can be given
if len(fnName) == 0 && len(triggersOriginal) == 0 {
@@ -104,9 +104,9 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *CreateSubCommand) run(flags cli.Input) error {
func (opts *CreateSubCommand) run(input cli.Input) error {
// If we're writing a spec, don't call the API
if flags.Bool("spec") {
if input.Bool("spec") {
specFile := fmt.Sprintf("recorder-%v.yaml", opts.recorder.Metadata.Name)
err := spec.SpecSave(*opts.recorder, specFile)
if err != nil {
+11 -12
View File
@@ -32,35 +32,34 @@ type DeleteSubCommand struct {
metadata *metav1.ObjectMeta
}
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 {
err := opts.complete(flags)
func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
m, err := util.GetMetadata("name", "recorderns", flags)
if err != nil {
return err
func (opts *DeleteSubCommand) complete(input cli.Input) error {
opts.metadata = &metav1.ObjectMeta{
Name: input.String("name"),
Namespace: input.String("recorderns"),
}
opts.metadata = m
return nil
}
func (opts *DeleteSubCommand) run(flags cli.Input) error {
func (opts *DeleteSubCommand) run(input cli.Input) error {
err := opts.client.RecorderDelete(opts.metadata)
if err != nil {
return errors.Wrap(err, "error deleting recorder")
+9 -9
View File
@@ -34,27 +34,27 @@ type GetSubCommand struct {
name string
}
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 {
err := opts.complete(flags)
func (opts *GetSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *GetSubCommand) complete(flags cli.Input) error {
opts.name = flags.String("name")
func (opts *GetSubCommand) complete(input cli.Input) error {
opts.name = input.String("name")
if len(opts.name) <= 0 {
return errors.New("need a recorder name, use --name")
@@ -62,7 +62,7 @@ func (opts *GetSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *GetSubCommand) run(flags cli.Input) error {
func (opts *GetSubCommand) run(input cli.Input) error {
recorder, err := opts.client.RecorderGet(&metav1.ObjectMeta{
Name: opts.name,
Namespace: "default",
+6 -6
View File
@@ -32,22 +32,22 @@ 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 {
return opts.run(flags)
func (opts *ListSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ListSubCommand) run(flags cli.Input) error {
func (opts *ListSubCommand) run(input cli.Input) error {
recorders, err := opts.client.RecorderList("default")
if err != nil {
return errors.Wrap(err, "error listing recorders")
+13 -13
View File
@@ -34,33 +34,33 @@ type UpdateSubCommand struct {
recorder *fv1.Recorder
}
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 {
recName := flags.String("name")
enable := flags.Bool("enable")
disable := flags.Bool("disable")
func (opts *UpdateSubCommand) complete(input cli.Input) error {
recName := input.String("name")
enable := input.Bool("enable")
disable := input.Bool("disable")
//retPolicy := flags.String("retention")
//evictPolicy := flags.String("eviction")
triggers := flags.StringSlice("trigger")
function := flags.String("function")
triggers := input.StringSlice("trigger")
function := input.String("function")
if enable && disable {
return errors.New("Cannot enable and disable a recorder simultaneously.")
@@ -134,7 +134,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.RecorderUpdate(opts.recorder)
if err != nil {
return errors.Wrap(err, "error updating recorder")
+3 -3
View File
@@ -30,9 +30,9 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(View),
}
wrapper.SetFlags(viewCmd, flag.FlagSet{
Optional: []flag.Flag{flag.RecordsFilterTimeToFlag, flag.RecordsFilterTimeFromFlag,
flag.RecordsFilterFunctionFlag, flag.RecordsFilterTriggerFlag, flag.RecordsVerbosityFlag,
flag.RecordsVvFlag},
Optional: []flag.Flag{flag.RecordsFilterTimeTo, flag.RecordsFilterTimeFrom,
flag.RecordsFilterFunction, flag.RecordsFilterTrigger, flag.RecordsVerbosity,
flag.RecordsVv},
})
command := &cobra.Command{
+13 -13
View File
@@ -33,37 +33,37 @@ type ViewSubCommand struct {
client *client.Client
}
func View(flags cli.Input) error {
c, err := util.GetServer(flags)
func View(flaginput cli.Input) error {
c, err := util.GetServer(flaginput)
if err != nil {
return err
}
opts := ViewSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(flaginput)
}
func (opts *ViewSubCommand) do(flags cli.Input) error {
return opts.run(flags)
func (opts *ViewSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ViewSubCommand) run(flags cli.Input) error {
func (opts *ViewSubCommand) run(input cli.Input) error {
var verbosity int
if flags.Bool("v") && flags.Bool("vv") {
if input.Bool("v") && input.Bool("vv") {
return errors.New("conflicting verbosity levels, use either --v or --vv")
}
if flags.Bool("v") {
if input.Bool("v") {
verbosity = 1
}
if flags.Bool("vv") {
if input.Bool("vv") {
verbosity = 2
}
function := flags.String("function")
trigger := flags.String("trigger")
from := flags.String("from")
to := flags.String("to")
function := input.String("function")
trigger := input.String("trigger")
from := input.String("from")
to := input.String("to")
//Refuse multiple filters for now
if multipleFiltersSpecified(function, trigger, from+to) {
+1 -1
View File
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Replay),
}
wrapper.SetFlags(replayCmd, flag.FlagSet{
Required: []flag.Flag{flag.RecordsReqIDFlag},
Required: []flag.Flag{flag.RecordsReqID},
})
command := &cobra.Command{
+7 -7
View File
@@ -32,23 +32,23 @@ type ReplaySubCommand struct {
client *client.Client
}
func Replay(flags cli.Input) error {
c, err := util.GetServer(flags)
func Replay(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := ReplaySubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *ReplaySubCommand) do(flags cli.Input) error {
return opts.run(flags)
func (opts *ReplaySubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ReplaySubCommand) run(flags cli.Input) error {
reqUID := flags.String("reqUID")
func (opts *ReplaySubCommand) run(input cli.Input) error {
reqUID := input.String("reqUID")
if len(reqUID) == 0 {
return errors.New("Need a reqUID, use --reqUID flag to specify")
}
+12 -12
View File
@@ -34,10 +34,10 @@ 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"
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/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"
"github.com/fission/fission/pkg/utils"
@@ -56,27 +56,27 @@ type ApplySubCommand struct {
// Apply is *not* transactional -- if the user hits Ctrl-C, or their laptop dies
// etc, while doing an apply, they will get a partially applied deployment. However,
// they can retry their apply command once they're back online.
func Apply(flags cli.Input) error {
c, err := util.GetServer(flags)
func Apply(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := ApplySubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *ApplySubCommand) do(flags cli.Input) error {
return opts.run(flags)
func (opts *ApplySubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ApplySubCommand) run(flags cli.Input) error {
specDir := util.GetSpecDir(flags)
func (opts *ApplySubCommand) run(input cli.Input) error {
specDir := util.GetSpecDir(input)
deleteResources := flags.Bool("delete")
watchResources := flags.Bool("watch")
waitForBuild := flags.Bool("wait")
deleteResources := input.Bool(flagkey.SpecDelete)
watchResources := input.Bool(flagkey.SpecWatch)
waitForBuild := input.Bool(flagkey.SpecWait)
var watcher *fsnotify.Watcher
var pbw *packageBuildWatcher
@@ -123,7 +123,7 @@ func (opts *ApplySubCommand) run(flags cli.Input) error {
}
// validate
err = fr.Validate(flags)
err = fr.Validate(input)
if err != nil {
return errors.Wrap(err, "error validating specs")
}
+4 -4
View File
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Init),
}
wrapper.SetFlags(initCmd, flag.FlagSet{
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecNameFlag, flag.SpecDeployIDFlag},
Optional: []flag.Flag{flag.SpecDir, flag.SpecName, flag.SpecDeployID},
})
validateCmd := &cobra.Command{
@@ -39,7 +39,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Validate),
}
wrapper.SetFlags(validateCmd, flag.FlagSet{
Optional: []flag.Flag{flag.SpecDirFlag},
Optional: []flag.Flag{flag.SpecDir},
})
applyCmd := &cobra.Command{
@@ -48,7 +48,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Apply),
}
wrapper.SetFlags(applyCmd, flag.FlagSet{
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecDeployIDFlag, flag.SpecWaitFlag},
Optional: []flag.Flag{flag.SpecDir, flag.SpecDeployID, flag.SpecWait},
})
destroyCmd := &cobra.Command{
@@ -57,7 +57,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Destroy),
}
wrapper.SetFlags(destroyCmd, flag.FlagSet{
Optional: []flag.Flag{flag.SpecDirFlag},
Optional: []flag.Flag{flag.SpecDir},
})
command := &cobra.Command{
+7 -7
View File
@@ -29,24 +29,24 @@ type DestroySubCommand struct {
}
// Destroy destroys everything in the spec.
func Destroy(flags cli.Input) error {
c, err := util.GetServer(flags)
func Destroy(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := &DestroySubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *DestroySubCommand) do(flags cli.Input) error {
return opts.run(flags)
func (opts *DestroySubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *DestroySubCommand) run(flags cli.Input) error {
func (opts *DestroySubCommand) run(input cli.Input) error {
// get specdir
specDir := util.GetSpecDir(flags)
specDir := util.GetSpecDir(input)
// read everything
fr, err := ReadSpecs(specDir)
+13 -12
View File
@@ -29,6 +29,7 @@ import (
"github.com/fission/fission/pkg/controller/client"
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -37,30 +38,30 @@ type InitSubCommand struct {
deployConfig *spectypes.DeploymentConfig
}
func Init(flags cli.Input) error {
c, err := util.GetServer(flags)
func Init(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := InitSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *InitSubCommand) do(flags cli.Input) error {
err := opts.complete(flags)
func (opts *InitSubCommand) do(input cli.Input) error {
err := opts.complete(input)
if err != nil {
return err
}
return opts.run(flags)
return opts.run(input)
}
func (opts *InitSubCommand) complete(flags cli.Input) error {
func (opts *InitSubCommand) complete(input cli.Input) error {
// Figure out spec directory
specDir := util.GetSpecDir(flags)
specDir := util.GetSpecDir(input)
name := flags.String("name")
name := input.String(flagkey.SpecName)
if len(name) == 0 {
// come up with a name using the current dir
dir, err := filepath.Abs(".")
@@ -71,7 +72,7 @@ func (opts *InitSubCommand) complete(flags cli.Input) error {
name = util.KubifyName(basename)
}
deployID := flags.String("deployid")
deployID := input.String(flagkey.SpecDeployID)
if len(deployID) == 0 {
deployID = uuid.NewV4().String()
}
@@ -101,8 +102,8 @@ func (opts *InitSubCommand) complete(flags cli.Input) error {
// run just initializes an empty spec directory and adds some
// sample YAMLs in there that might be useful.
func (opts *InitSubCommand) run(flags cli.Input) error {
specDir := util.GetSpecDir(flags)
func (opts *InitSubCommand) run(input cli.Input) error {
specDir := util.GetSpecDir(input)
// Add a bit of documentation to the spec dir here
err := ioutil.WriteFile(filepath.Join(specDir, "README"), []byte(SPEC_README), 0644)
+2 -2
View File
@@ -246,7 +246,7 @@ func (fr *FissionResources) validateFunctionReference(functions map[string]bool,
return nil
}
func (fr *FissionResources) Validate(flags cli.Input) error {
func (fr *FissionResources) Validate(input cli.Input) error {
result := utils.MultiErrorWithFormat()
// check references: both dangling refs + garbage
@@ -348,7 +348,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
packages[MapKey(pkgMeta)] = true
}
client, err := util.GetServer(flags)
client, err := util.GetServer(input)
if err != nil {
return err
}
+8 -8
View File
@@ -38,32 +38,32 @@ type ValidateSubCommand struct {
// Validate parses a set of specs and checks for references to
// resources that don't exist.
func Validate(flags cli.Input) error {
c, err := util.GetServer(flags)
func Validate(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := &ValidateSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *ValidateSubCommand) do(flags cli.Input) error {
return opts.run(flags)
func (opts *ValidateSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ValidateSubCommand) run(flags cli.Input) error {
func (opts *ValidateSubCommand) run(input cli.Input) error {
// this will error on parse errors and on duplicates
specDir := util.GetSpecDir(flags)
specDir := util.GetSpecDir(input)
fr, err := ReadSpecs(specDir)
if err != nil {
return errors.Wrap(err, "error reading specs")
}
// this does the rest of the checks, like dangling refs
err = fr.Validate(flags)
err = fr.Validate(input)
if err != nil {
return errors.Wrap(err, "error validating specs")
}
+1 -1
View File
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Dump),
}
wrapper.SetFlags(dumpCmd, flag.FlagSet{
Optional: []flag.Flag{flag.SupportNoZipFlag, flag.SupportOutputFlag},
Optional: []flag.Flag{flag.SupportNoZip, flag.SupportOutput},
})
command := &cobra.Command{
+7 -6
View File
@@ -28,6 +28,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/support/resources"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/utils"
)
@@ -41,22 +42,22 @@ type DumpSubCommand struct {
client *client.Client
}
func Dump(flags cli.Input) error {
c, err := util.GetServer(flags)
func Dump(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := &DumpSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *DumpSubCommand) do(flags cli.Input) error {
func (opts *DumpSubCommand) do(input cli.Input) error {
fmt.Println("Start dumping process...")
nozip := flags.Bool("nozip")
outputDir := flags.String("output")
nozip := input.Bool(flagkey.SupportNoZip)
outputDir := input.String(flagkey.SupportOutput)
// check whether the dump directory exists.
_, err := os.Stat(outputDir)
+7 -7
View File
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Create),
}
wrapper.SetFlags(createCmd, flag.FlagSet{
Optional: []flag.Flag{flag.TtNameFlag, flag.TtFnNameFlag, flag.NamespaceFunctionFlag, flag.TtCronFlag, flag.SpecSaveFlag},
Optional: []flag.Flag{flag.TtName, flag.TtFnName, flag.NamespaceFunction, flag.TtCron, flag.SpecSave},
})
updateCmd := &cobra.Command{
@@ -40,8 +40,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Update),
}
wrapper.SetFlags(updateCmd, flag.FlagSet{
Required: []flag.Flag{flag.TtNameFlag},
Optional: []flag.Flag{flag.TtFnNameFlag, flag.NamespaceFunctionFlag, flag.TtCronFlag},
Required: []flag.Flag{flag.TtName},
Optional: []flag.Flag{flag.TtFnName, flag.NamespaceFunction, flag.TtCron},
})
deleteCmd := &cobra.Command{
@@ -51,8 +51,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.TtNameFlag},
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Required: []flag.Flag{flag.TtName},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
listCmd := &cobra.Command{
@@ -62,7 +62,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
showCmd := &cobra.Command{
@@ -72,7 +72,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Show),
}
wrapper.SetFlags(showCmd, flag.FlagSet{
Optional: []flag.Flag{flag.TtCronFlag, flag.TtRoundFlag},
Optional: []flag.Flag{flag.TtCron, flag.TtRound},
})
command := &cobra.Command{
+14 -13
View File
@@ -29,6 +29,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/spec"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -37,39 +38,39 @@ type CreateSubCommand struct {
trigger *fv1.TimeTrigger
}
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 {
name := flags.String("name")
func (opts *CreateSubCommand) complete(input cli.Input) error {
name := input.String(flagkey.TtName)
if len(name) == 0 {
name = uuid.NewV4().String()
}
fnName := flags.String("function")
fnName := input.String(flagkey.TtFnName)
if len(fnName) == 0 {
return errors.New("Need a function name to create a trigger, use --function")
}
fnNamespace := flags.String("fnNamespace")
fnNamespace := input.String(flagkey.NamespaceFunction)
cronSpec := flags.String("cron")
cronSpec := input.String(flagkey.TtCron)
if len(cronSpec) == 0 {
return errors.New("Need a cron spec like '0 30 * * * *', '@every 1h30m', or '@hourly'; use --cron")
}
@@ -91,9 +92,9 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *CreateSubCommand) run(flags cli.Input) error {
func (opts *CreateSubCommand) run(input cli.Input) error {
// if we're writing a spec, don't call the API
if flags.Bool("spec") {
if input.Bool(flagkey.SpecSave) {
specFile := fmt.Sprintf("timetrigger-%v.yaml", opts.trigger.Metadata.Name)
err := spec.SpecSave(*opts.trigger, specFile)
if err != nil {
+10 -8
View File
@@ -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", "triggerns", flags)
if err != nil {
return err
func (opts *DeleteSubCommand) do(input cli.Input) error {
m := &metav1.ObjectMeta{
Name: input.String(flagkey.TtName),
Namespace: input.String(flagkey.NamespaceTrigger),
}
err = opts.client.TimeTriggerDelete(m)
err := opts.client.TimeTriggerDelete(m)
if err != nil {
return errors.Wrap(err, "error deleting trigger")
}
+6 -5
View File
@@ -23,6 +23,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"
"github.com/pkg/errors"
)
@@ -31,19 +32,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 {
ttNs := flags.String("triggerns")
func (opts *ListSubCommand) do(input cli.Input) error {
ttNs := input.String(flagkey.NamespaceTrigger)
tts, err := opts.client.TimeTriggerList(ttNs)
if err != nil {
return errors.Wrap(err, "list Time triggers")
+9 -8
View File
@@ -21,6 +21,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"
)
@@ -28,24 +29,24 @@ type ShowSubCommand struct {
client *client.Client
}
func Show(flags cli.Input) error {
c, err := util.GetServer(flags)
func Show(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := ShowSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *ShowSubCommand) do(flags cli.Input) error {
return opts.run(flags)
func (opts *ShowSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ShowSubCommand) run(flags cli.Input) error {
round := flags.Int("round")
cronSpec := flags.String("cron")
func (opts *ShowSubCommand) run(flaginput cli.Input) error {
round := flaginput.Int(flagkey.TtName)
cronSpec := flaginput.String(flagkey.TtCron)
if len(cronSpec) == 0 {
return errors.New("need a cron spec like '0 30 * * * *', '@every 1h30m', or '@hourly'; use --cron")
}
+17 -17
View File
@@ -20,10 +20,12 @@ import (
"fmt"
"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"
)
@@ -32,38 +34,36 @@ type UpdateSubCommand struct {
trigger *fv1.TimeTrigger
}
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("name", "triggerns", flags)
if err != nil {
return err
}
tt, err := opts.client.TimeTriggerGet(m)
func (opts *UpdateSubCommand) complete(input cli.Input) error {
tt, err := opts.client.TimeTriggerGet(&metav1.ObjectMeta{
Name: input.String(flagkey.TtName),
Namespace: input.String(flagkey.NamespaceTrigger),
})
if err != nil {
return errors.Wrap(err, "error getting time trigger")
}
updated := false
newCron := flags.String("cron")
newCron := input.String("cron")
if len(newCron) != 0 {
tt.Spec.Cron = newCron
updated = true
@@ -72,7 +72,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
// TODO : During update, function has to be in the same ns as the trigger object
// but since we are not checking this for other triggers too, not sure if we need a check here.
fnName := flags.String("function")
fnName := input.String("function")
if len(fnName) > 0 {
tt.Spec.FunctionReference.Name = fnName
updated = true
@@ -87,13 +87,13 @@ 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.TimeTriggerUpdate(opts.trigger)
if err != nil {
return errors.Wrap(err, "error updating Time trigger")
}
fmt.Printf("Time trigger '%v' updated\n", opts.trigger.Metadata.Name)
fmt.Printf("trigger '%v' updated\n", opts.trigger.Metadata.Name)
t, err := getAPITimeInfo(opts.client)
if err != nil {
+4 -4
View File
@@ -31,18 +31,18 @@ type VersionSubCommand struct {
client *client.Client
}
func Version(flags cli.Input) error {
c, err := util.GetServer(flags)
func Version(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := &VersionSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *VersionSubCommand) do(flags cli.Input) error {
func (opts *VersionSubCommand) do(input cli.Input) error {
ver := util.GetVersion(opts.client)
bs, err := yaml.Marshal(ver)
if err != nil {