diff --git a/cmd/fission-cli/app/app.go b/cmd/fission-cli/app/app.go index 55592a40..557a1901 100644 --- a/cmd/fission-cli/app/app.go +++ b/cmd/fission-cli/app/app.go @@ -36,8 +36,8 @@ func App() *cobra.Command { Long: usage, //SilenceUsage: true, PreRunE: wrapper.Wrapper( - func(flags cli.Input) error { - console.Verbosity = flags.Int(flagkey.Verbosity) + func(input cli.Input) error { + console.Verbosity = input.Int(flagkey.Verbosity) return nil }, ), @@ -51,7 +51,7 @@ func App() *cobra.Command { }) wrapper.SetFlags(rootCmd, flag.FlagSet{ - Optional: []flag.Flag{flag.GlobalServerFlag, flag.GlobalVerbosityFlag}, + Optional: []flag.Flag{flag.GlobalServer, flag.GlobalVerbosity}, }) groups := helptemplate.CommandGroups{} diff --git a/pkg/apis/fission.io/v1/validation.go b/pkg/apis/fission.io/v1/validation.go index 781e670d..3d383656 100644 --- a/pkg/apis/fission.io/v1/validation.go +++ b/pkg/apis/fission.io/v1/validation.go @@ -339,7 +339,7 @@ func (es ExecutionStrategy) Validate() error { if es.ExecutorType == ExecutorTypeNewdeploy { if es.MinScale < 0 { - result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "ExecutionStrategy.MinScale", es.MinScale, "minimum scale must be greater or equal to 0")) + result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "ExecutionStrategy.MinScale", es.MinScale, "minimum scale must be greater than or equal to 0")) } if es.MaxScale <= 0 { @@ -347,7 +347,7 @@ func (es ExecutionStrategy) Validate() error { } if es.MaxScale < es.MinScale { - result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "ExecutionStrategy.MaxScale", es.MaxScale, "maximum scale must be greater or equal to minimum scale")) + result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "ExecutionStrategy.MaxScale", es.MaxScale, "maximum scale must be greater than or equal to minimum scale")) } if es.TargetCPUPercent <= 0 || es.TargetCPUPercent > 100 { @@ -421,11 +421,11 @@ func (spec EnvironmentSpec) Validate() error { } if spec.Poolsize < 0 { - result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "EnvironmentSpec.Poolsize", spec.Poolsize, "must be greater or equal to 0")) + result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "EnvironmentSpec.Poolsize", spec.Poolsize, "must be greater than or equal to 0")) } if spec.TerminationGracePeriod < 0 { - result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "EnvironmentSpec.TerminationGracePeriod", spec.TerminationGracePeriod, "must be greater or equal to 0")) + result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "EnvironmentSpec.TerminationGracePeriod", spec.TerminationGracePeriod, "must be greater than or equal to 0")) } return result.ErrorOrNil() diff --git a/pkg/fission-cli/cmd/canaryconfig/command.go b/pkg/fission-cli/cmd/canaryconfig/command.go index 0699b783..fbc65390 100644 --- a/pkg/fission-cli/cmd/canaryconfig/command.go +++ b/pkg/fission-cli/cmd/canaryconfig/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/canaryconfig/create.go b/pkg/fission-cli/cmd/canaryconfig/create.go index 31d75b17..635faa55 100644 --- a/pkg/fission-cli/cmd/canaryconfig/create.go +++ b/pkg/fission-cli/cmd/canaryconfig/create.go @@ -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") diff --git a/pkg/fission-cli/cmd/canaryconfig/list.go b/pkg/fission-cli/cmd/canaryconfig/list.go index 48dc351f..cd630768 100644 --- a/pkg/fission-cli/cmd/canaryconfig/list.go +++ b/pkg/fission-cli/cmd/canaryconfig/list.go @@ -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") diff --git a/pkg/fission-cli/cmd/cmd.go b/pkg/fission-cli/cmd/cmd.go index 067bc276..d25a8b8f 100644 --- a/pkg/fission-cli/cmd/cmd.go +++ b/pkg/fission-cli/cmd/cmd.go @@ -21,5 +21,5 @@ import ( ) type ( - CommandAction func(flags cli.Input) error + CommandAction func(input cli.Input) error ) diff --git a/pkg/fission-cli/cmd/environment/command.go b/pkg/fission-cli/cmd/environment/command.go index ee8393f7..1dde4d5e 100644 --- a/pkg/fission-cli/cmd/environment/command.go +++ b/pkg/fission-cli/cmd/environment/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/function/command.go b/pkg/fission-cli/cmd/function/command.go index 2de9544f..6aef5f1b 100644 --- a/pkg/fission-cli/cmd/function/command.go +++ b/pkg/fission-cli/cmd/function/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/function/create.go b/pkg/fission-cli/cmd/function/create.go index a4329ee2..db2808cc 100644 --- a/pkg/fission-cli/cmd/function/create.go +++ b/pkg/fission-cli/cmd/function/create.go @@ -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) } diff --git a/pkg/fission-cli/cmd/function/function_test.go b/pkg/fission-cli/cmd/function/function_test.go index 06b336e6..5ab8c248 100644 --- a/pkg/fission-cli/cmd/function/function_test.go +++ b/pkg/fission-cli/cmd/function/function_test.go @@ -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) { diff --git a/pkg/fission-cli/cmd/function/test.go b/pkg/fission-cli/cmd/function/test.go index 7f79b494..2ae4cd7a 100644 --- a/pkg/fission-cli/cmd/function/test.go +++ b/pkg/fission-cli/cmd/function/test.go @@ -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 { diff --git a/pkg/fission-cli/cmd/function/update.go b/pkg/fission-cli/cmd/function/update.go index efdc4df3..8b498085 100644 --- a/pkg/fission-cli/cmd/function/update.go +++ b/pkg/fission-cli/cmd/function/update.go @@ -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 } diff --git a/pkg/fission-cli/cmd/httptrigger/command.go b/pkg/fission-cli/cmd/httptrigger/command.go index e2be0f91..064a0ac6 100644 --- a/pkg/fission-cli/cmd/httptrigger/command.go +++ b/pkg/fission-cli/cmd/httptrigger/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/httptrigger/create.go b/pkg/fission-cli/cmd/httptrigger/create.go index ed072d12..51190539 100644 --- a/pkg/fission-cli/cmd/httptrigger/create.go +++ b/pkg/fission-cli/cmd/httptrigger/create.go @@ -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) diff --git a/pkg/fission-cli/cmd/httptrigger/delete.go b/pkg/fission-cli/cmd/httptrigger/delete.go index bfa00d3f..12f4c608 100644 --- a/pkg/fission-cli/cmd/httptrigger/delete.go +++ b/pkg/fission-cli/cmd/httptrigger/delete.go @@ -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") diff --git a/pkg/fission-cli/cmd/httptrigger/get.go b/pkg/fission-cli/cmd/httptrigger/get.go index be78f4a5..1d60e510 100644 --- a/pkg/fission-cli/cmd/httptrigger/get.go +++ b/pkg/fission-cli/cmd/httptrigger/get.go @@ -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 { diff --git a/pkg/fission-cli/cmd/httptrigger/list.go b/pkg/fission-cli/cmd/httptrigger/list.go index 6de11097..fdcad45f 100644 --- a/pkg/fission-cli/cmd/httptrigger/list.go +++ b/pkg/fission-cli/cmd/httptrigger/list.go @@ -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) } diff --git a/pkg/fission-cli/cmd/httptrigger/parse.go b/pkg/fission-cli/cmd/httptrigger/parse.go index 43af2c92..5027ed84 100644 --- a/pkg/fission-cli/cmd/httptrigger/parse.go +++ b/pkg/fission-cli/cmd/httptrigger/parse.go @@ -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 { diff --git a/pkg/fission-cli/cmd/httptrigger/update.go b/pkg/fission-cli/cmd/httptrigger/update.go index 2fc74b2a..787a4a73 100644 --- a/pkg/fission-cli/cmd/httptrigger/update.go +++ b/pkg/fission-cli/cmd/httptrigger/update.go @@ -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") diff --git a/pkg/fission-cli/cmd/kubewatch/command.go b/pkg/fission-cli/cmd/kubewatch/command.go index f10cb431..fe86d252 100644 --- a/pkg/fission-cli/cmd/kubewatch/command.go +++ b/pkg/fission-cli/cmd/kubewatch/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/kubewatch/create.go b/pkg/fission-cli/cmd/kubewatch/create.go index dbd2327e..ae82182e 100644 --- a/pkg/fission-cli/cmd/kubewatch/create.go +++ b/pkg/fission-cli/cmd/kubewatch/create.go @@ -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 to override.") - namespace = "default" - } - - objType := flags.String("type") - if len(objType) == 0 { - fmt.Println("Object type unspecified, will watch pods. Use --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 } diff --git a/pkg/fission-cli/cmd/kubewatch/delete.go b/pkg/fission-cli/cmd/kubewatch/delete.go index bd55e637..5e8c9b5d 100644 --- a/pkg/fission-cli/cmd/kubewatch/delete.go +++ b/pkg/fission-cli/cmd/kubewatch/delete.go @@ -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 } diff --git a/pkg/fission-cli/cmd/kubewatch/list.go b/pkg/fission-cli/cmd/kubewatch/list.go index 4a7c1d20..60fed7b0 100644 --- a/pkg/fission-cli/cmd/kubewatch/list.go +++ b/pkg/fission-cli/cmd/kubewatch/list.go @@ -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") diff --git a/pkg/fission-cli/cmd/mqtrigger/command.go b/pkg/fission-cli/cmd/mqtrigger/command.go index e0cdce3e..fbd0c2fb 100644 --- a/pkg/fission-cli/cmd/mqtrigger/command.go +++ b/pkg/fission-cli/cmd/mqtrigger/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/mqtrigger/create.go b/pkg/fission-cli/cmd/mqtrigger/create.go index 7368096c..cbd65deb 100644 --- a/pkg/fission-cli/cmd/mqtrigger/create.go +++ b/pkg/fission-cli/cmd/mqtrigger/create.go @@ -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 diff --git a/pkg/fission-cli/cmd/mqtrigger/delete.go b/pkg/fission-cli/cmd/mqtrigger/delete.go index 145c21f5..ad860c44 100644 --- a/pkg/fission-cli/cmd/mqtrigger/delete.go +++ b/pkg/fission-cli/cmd/mqtrigger/delete.go @@ -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 } diff --git a/pkg/fission-cli/cmd/mqtrigger/list.go b/pkg/fission-cli/cmd/mqtrigger/list.go index b4ecec60..62879e6b 100644 --- a/pkg/fission-cli/cmd/mqtrigger/list.go +++ b/pkg/fission-cli/cmd/mqtrigger/list.go @@ -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") } diff --git a/pkg/fission-cli/cmd/mqtrigger/update.go b/pkg/fission-cli/cmd/mqtrigger/update.go index d089f2b1..1c89981b 100644 --- a/pkg/fission-cli/cmd/mqtrigger/update.go +++ b/pkg/fission-cli/cmd/mqtrigger/update.go @@ -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") diff --git a/pkg/fission-cli/cmd/package/command.go b/pkg/fission-cli/cmd/package/command.go index f7717d95..979604d3 100644 --- a/pkg/fission-cli/cmd/package/command.go +++ b/pkg/fission-cli/cmd/package/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/package/create.go b/pkg/fission-cli/cmd/package/create.go index e9a63389..f07c62a4 100644 --- a/pkg/fission-cli/cmd/package/create.go +++ b/pkg/fission-cli/cmd/package/create.go @@ -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") } diff --git a/pkg/fission-cli/cmd/package/delete.go b/pkg/fission-cli/cmd/package/delete.go index d9178836..8e413553 100644 --- a/pkg/fission-cli/cmd/package/delete.go +++ b/pkg/fission-cli/cmd/package/delete.go @@ -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") diff --git a/pkg/fission-cli/cmd/package/get.go b/pkg/fission-cli/cmd/package/get.go index 05ad9e31..5090c124 100644 --- a/pkg/fission-cli/cmd/package/get.go +++ b/pkg/fission-cli/cmd/package/get.go @@ -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, diff --git a/pkg/fission-cli/cmd/package/info.go b/pkg/fission-cli/cmd/package/info.go index b59a606a..310be992 100644 --- a/pkg/fission-cli/cmd/package/info.go +++ b/pkg/fission-cli/cmd/package/info.go @@ -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, diff --git a/pkg/fission-cli/cmd/package/list.go b/pkg/fission-cli/cmd/package/list.go index 140ea3cb..345ffa00 100644 --- a/pkg/fission-cli/cmd/package/list.go +++ b/pkg/fission-cli/cmd/package/list.go @@ -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 { diff --git a/pkg/fission-cli/cmd/package/rebuild.go b/pkg/fission-cli/cmd/package/rebuild.go index bd45786a..ec1f00ff 100644 --- a/pkg/fission-cli/cmd/package/rebuild.go +++ b/pkg/fission-cli/cmd/package/rebuild.go @@ -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, diff --git a/pkg/fission-cli/cmd/package/update.go b/pkg/fission-cli/cmd/package/update.go index df944d21..a7393989 100644 --- a/pkg/fission-cli/cmd/package/update.go +++ b/pkg/fission-cli/cmd/package/update.go @@ -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, diff --git a/pkg/fission-cli/cmd/plugin/list.go b/pkg/fission-cli/cmd/plugin/list.go index 90c54c0d..6965a460 100644 --- a/pkg/fission-cli/cmd/plugin/list.go +++ b/pkg/fission-cli/cmd/plugin/list.go @@ -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() { diff --git a/pkg/fission-cli/cmd/recorder/command.go b/pkg/fission-cli/cmd/recorder/command.go index 2d8223f1..ab402a30 100644 --- a/pkg/fission-cli/cmd/recorder/command.go +++ b/pkg/fission-cli/cmd/recorder/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/recorder/create.go b/pkg/fission-cli/cmd/recorder/create.go index d51523ed..3bcd1420 100644 --- a/pkg/fission-cli/cmd/recorder/create.go +++ b/pkg/fission-cli/cmd/recorder/create.go @@ -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 { diff --git a/pkg/fission-cli/cmd/recorder/delete.go b/pkg/fission-cli/cmd/recorder/delete.go index 45e44be4..ff1b5385 100644 --- a/pkg/fission-cli/cmd/recorder/delete.go +++ b/pkg/fission-cli/cmd/recorder/delete.go @@ -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") diff --git a/pkg/fission-cli/cmd/recorder/get.go b/pkg/fission-cli/cmd/recorder/get.go index 7cd859ba..0f89ea26 100644 --- a/pkg/fission-cli/cmd/recorder/get.go +++ b/pkg/fission-cli/cmd/recorder/get.go @@ -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", diff --git a/pkg/fission-cli/cmd/recorder/list.go b/pkg/fission-cli/cmd/recorder/list.go index cd311b77..2eeb4f95 100644 --- a/pkg/fission-cli/cmd/recorder/list.go +++ b/pkg/fission-cli/cmd/recorder/list.go @@ -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") diff --git a/pkg/fission-cli/cmd/recorder/update.go b/pkg/fission-cli/cmd/recorder/update.go index 95bb3f67..8db727ef 100644 --- a/pkg/fission-cli/cmd/recorder/update.go +++ b/pkg/fission-cli/cmd/recorder/update.go @@ -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") diff --git a/pkg/fission-cli/cmd/records/command.go b/pkg/fission-cli/cmd/records/command.go index 74aff60d..d1550a74 100644 --- a/pkg/fission-cli/cmd/records/command.go +++ b/pkg/fission-cli/cmd/records/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/records/view.go b/pkg/fission-cli/cmd/records/view.go index 075d112b..f45acc64 100644 --- a/pkg/fission-cli/cmd/records/view.go +++ b/pkg/fission-cli/cmd/records/view.go @@ -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) { diff --git a/pkg/fission-cli/cmd/replay/command.go b/pkg/fission-cli/cmd/replay/command.go index 7d897374..d34921f2 100644 --- a/pkg/fission-cli/cmd/replay/command.go +++ b/pkg/fission-cli/cmd/replay/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/replay/replay.go b/pkg/fission-cli/cmd/replay/replay.go index 87afbaa1..9c7c73c9 100644 --- a/pkg/fission-cli/cmd/replay/replay.go +++ b/pkg/fission-cli/cmd/replay/replay.go @@ -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") } diff --git a/pkg/fission-cli/cmd/spec/apply.go b/pkg/fission-cli/cmd/spec/apply.go index a13e3cc7..e36f783c 100644 --- a/pkg/fission-cli/cmd/spec/apply.go +++ b/pkg/fission-cli/cmd/spec/apply.go @@ -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") } diff --git a/pkg/fission-cli/cmd/spec/command.go b/pkg/fission-cli/cmd/spec/command.go index b76d05cf..80260510 100644 --- a/pkg/fission-cli/cmd/spec/command.go +++ b/pkg/fission-cli/cmd/spec/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/spec/destroy.go b/pkg/fission-cli/cmd/spec/destroy.go index ef05296e..34c2a374 100644 --- a/pkg/fission-cli/cmd/spec/destroy.go +++ b/pkg/fission-cli/cmd/spec/destroy.go @@ -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) diff --git a/pkg/fission-cli/cmd/spec/init.go b/pkg/fission-cli/cmd/spec/init.go index 9b163683..feaf36e9 100644 --- a/pkg/fission-cli/cmd/spec/init.go +++ b/pkg/fission-cli/cmd/spec/init.go @@ -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) diff --git a/pkg/fission-cli/cmd/spec/spec.go b/pkg/fission-cli/cmd/spec/spec.go index 74efc9a6..17c98581 100644 --- a/pkg/fission-cli/cmd/spec/spec.go +++ b/pkg/fission-cli/cmd/spec/spec.go @@ -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 } diff --git a/pkg/fission-cli/cmd/spec/validate.go b/pkg/fission-cli/cmd/spec/validate.go index fcc301e0..0a04927c 100644 --- a/pkg/fission-cli/cmd/spec/validate.go +++ b/pkg/fission-cli/cmd/spec/validate.go @@ -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") } diff --git a/pkg/fission-cli/cmd/support/command.go b/pkg/fission-cli/cmd/support/command.go index c1375dce..706d6f66 100644 --- a/pkg/fission-cli/cmd/support/command.go +++ b/pkg/fission-cli/cmd/support/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/support/dump.go b/pkg/fission-cli/cmd/support/dump.go index e21f9d19..cbd9485d 100644 --- a/pkg/fission-cli/cmd/support/dump.go +++ b/pkg/fission-cli/cmd/support/dump.go @@ -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) diff --git a/pkg/fission-cli/cmd/timetrigger/command.go b/pkg/fission-cli/cmd/timetrigger/command.go index 56bab784..bf394469 100644 --- a/pkg/fission-cli/cmd/timetrigger/command.go +++ b/pkg/fission-cli/cmd/timetrigger/command.go @@ -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{ diff --git a/pkg/fission-cli/cmd/timetrigger/create.go b/pkg/fission-cli/cmd/timetrigger/create.go index cddb9c83..20d33688 100644 --- a/pkg/fission-cli/cmd/timetrigger/create.go +++ b/pkg/fission-cli/cmd/timetrigger/create.go @@ -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 { diff --git a/pkg/fission-cli/cmd/timetrigger/delete.go b/pkg/fission-cli/cmd/timetrigger/delete.go index dfba9dec..9448cbfb 100644 --- a/pkg/fission-cli/cmd/timetrigger/delete.go +++ b/pkg/fission-cli/cmd/timetrigger/delete.go @@ -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") } diff --git a/pkg/fission-cli/cmd/timetrigger/list.go b/pkg/fission-cli/cmd/timetrigger/list.go index 567ead2a..3d767a30 100644 --- a/pkg/fission-cli/cmd/timetrigger/list.go +++ b/pkg/fission-cli/cmd/timetrigger/list.go @@ -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") diff --git a/pkg/fission-cli/cmd/timetrigger/test.go b/pkg/fission-cli/cmd/timetrigger/test.go index 5d00a31e..a21f5482 100644 --- a/pkg/fission-cli/cmd/timetrigger/test.go +++ b/pkg/fission-cli/cmd/timetrigger/test.go @@ -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") } diff --git a/pkg/fission-cli/cmd/timetrigger/update.go b/pkg/fission-cli/cmd/timetrigger/update.go index 18f7a8c1..94b6819b 100644 --- a/pkg/fission-cli/cmd/timetrigger/update.go +++ b/pkg/fission-cli/cmd/timetrigger/update.go @@ -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 { diff --git a/pkg/fission-cli/cmd/version/version.go b/pkg/fission-cli/cmd/version/version.go index f606dab4..c9271d2f 100644 --- a/pkg/fission-cli/cmd/version/version.go +++ b/pkg/fission-cli/cmd/version/version.go @@ -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 { diff --git a/pkg/fission-cli/flag/flag.go b/pkg/fission-cli/flag/flag.go index bfd77a83..5cf1b63f 100644 --- a/pkg/fission-cli/flag/flag.go +++ b/pkg/fission-cli/flag/flag.go @@ -67,133 +67,133 @@ const ( ) var ( - GlobalVerbosityFlag = Flag{Type: Int, Name: flagkey.Verbosity, Short: "v", Usage: "CLI verbosity (0 is quiet, 1 is the default, 2 is verbose)", DefaultValue: 1} - GlobalServerFlag = Flag{Type: String, Name: flagkey.Server, Usage: "Server URL"} + GlobalVerbosity = Flag{Type: Int, Name: flagkey.Verbosity, Short: "v", Usage: "CLI verbosity (0 is quiet, 1 is the default, 2 is verbose)", DefaultValue: 1} + GlobalServer = Flag{Type: String, Name: flagkey.Server, Usage: "Server URL"} - NamespaceFunctionFlag = Flag{Type: String, Name: flagkey.NamespaceFunction, Aliases: []string{"fns"}, Usage: "Namespace for function object", DefaultValue: metav1.NamespaceDefault} - NamespaceEnvironmentFlag = Flag{Type: String, Name: flagkey.NamespaceEnvironment, Aliases: []string{"envns"}, Usage: "Namespace for environment object", DefaultValue: metav1.NamespaceDefault} - NamespacePackageFlag = Flag{Type: String, Name: flagkey.NamespacePackage, Aliases: []string{"pkgns"}, Usage: "Namespace for package object", DefaultValue: metav1.NamespaceDefault} - NamespaceTriggerFlag = Flag{Type: String, Name: flagkey.NamespaceTrigger, Aliases: []string{"triggerns"}, Usage: "Namespace for trigger object", DefaultValue: metav1.NamespaceDefault} - NamespaceRecorderFlag = Flag{Type: String, Name: flagkey.NamespaceRecorder, Aliases: []string{"recorderns"}, Usage: "Namespace for recorder object", DefaultValue: metav1.NamespaceDefault} - NamespaceCanaryFlag = Flag{Type: String, Name: flagkey.NamespaceCanary, Aliases: []string{"canaryns"}, Usage: "Namespace for canary config object", DefaultValue: metav1.NamespaceDefault} + NamespaceFunction = Flag{Type: String, Name: flagkey.NamespaceFunction, Aliases: []string{"fns"}, Usage: "Namespace for function object", DefaultValue: metav1.NamespaceDefault} + NamespaceEnvironment = Flag{Type: String, Name: flagkey.NamespaceEnvironment, Aliases: []string{"envns"}, Usage: "Namespace for environment object", DefaultValue: metav1.NamespaceDefault} + NamespacePackage = Flag{Type: String, Name: flagkey.NamespacePackage, Aliases: []string{"pkgns"}, Usage: "Namespace for package object", DefaultValue: metav1.NamespaceDefault} + NamespaceTrigger = Flag{Type: String, Name: flagkey.NamespaceTrigger, Aliases: []string{"triggerns"}, Usage: "Namespace for trigger object", DefaultValue: metav1.NamespaceDefault} + NamespaceRecorder = Flag{Type: String, Name: flagkey.NamespaceRecorder, Aliases: []string{"recorderns"}, Usage: "Namespace for recorder object", DefaultValue: metav1.NamespaceDefault} + NamespaceCanary = Flag{Type: String, Name: flagkey.NamespaceCanary, Aliases: []string{"canaryns"}, Usage: "Namespace for canary config object", DefaultValue: metav1.NamespaceDefault} - RunTimeMinCPUFlag = Flag{Type: Int, Name: flagkey.RuntimeMincpu, Usage: "Minimum CPU to be assigned to pod (In millicore, minimum 1)"} - RunTimeMaxCPUFlag = Flag{Type: Int, Name: flagkey.RuntimeMaxcpu, Usage: "Maximum CPU to be assigned to pod (In millicore, minimum 1)"} - RunTimeTargetCPUFlag = Flag{Type: Int, Name: flagkey.RuntimeTargetcpu, Usage: "Target average CPU usage percentage across pods for scaling", DefaultValue: 80} - RunTimeMinMemoryFlag = Flag{Type: Int, Name: flagkey.RuntimeMinmemory, Usage: "Minimum memory to be assigned to pod (In megabyte)"} - RunTimeMaxMemoryFlag = Flag{Type: Int, Name: flagkey.RuntimeMaxmemory, Usage: "Maximum memory to be assigned to pod (In megabyte)"} + RunTimeMinCPU = Flag{Type: Int, Name: flagkey.RuntimeMincpu, Usage: "Minimum CPU to be assigned to pod (In millicore, minimum 1)"} + RunTimeMaxCPU = Flag{Type: Int, Name: flagkey.RuntimeMaxcpu, Usage: "Maximum CPU to be assigned to pod (In millicore, minimum 1)"} + RunTimeTargetCPU = Flag{Type: Int, Name: flagkey.RuntimeTargetcpu, Usage: "Target average CPU usage percentage across pods for scaling", DefaultValue: 80} + RunTimeMinMemory = Flag{Type: Int, Name: flagkey.RuntimeMinmemory, Usage: "Minimum memory to be assigned to pod (In megabyte)"} + RunTimeMaxMemory = Flag{Type: Int, Name: flagkey.RuntimeMaxmemory, Usage: "Maximum memory to be assigned to pod (In megabyte)"} - ReplicasMinFlag = Flag{Type: Int, Name: flagkey.ReplicasMinscale, Usage: "Minimum number of pods (Uses resource inputs to configure HPA)", DefaultValue: 1} - ReplicasMaxFlag = Flag{Type: Int, Name: flagkey.ReplicasMaxscale, Usage: "Maximum number of pods (Uses resource inputs to configure HPA)", DefaultValue: 1} + ReplicasMin = Flag{Type: Int, Name: flagkey.ReplicasMinscale, Usage: "Minimum number of pods (Uses resource inputs to configure HPA)", DefaultValue: 1} + ReplicasMax = Flag{Type: Int, Name: flagkey.ReplicasMaxscale, Usage: "Maximum number of pods (Uses resource inputs to configure HPA)", DefaultValue: 1} - FnNameFlag = Flag{Type: String, Name: flagkey.FnName, Usage: "Function name"} - FnSpecializationTimeoutFlag = Flag{Type: Int, Name: flagkey.FnSpecializationTimeout, Aliases: []string{"st"}, Usage: "Timeout for newdeploy to wait for function pod creation", DefaultValue: fv1.DefaultSpecializationTimeOut} - FnEnvNameFlag = Flag{Type: String, Name: flagkey.FnEnvironmentName, Usage: "Environment name for function"} - FnCodeFlag = Flag{Type: String, Name: flagkey.FnCode, Usage: "Local path or URL for single file source code"} - FnKeepURLFlag = Flag{Type: Bool, Name: flagkey.PkgKeepURL, Aliases: []string{"keepurl"}, Usage: "Keep the providing URL in archive instead of downloading file from it. (If set, no checksum will be generated for file integrity check. You must ensure the file won't be changed.)"} - FnPkgNameFlag = Flag{Type: String, Name: flagkey.FnPackageName, Aliases: []string{"pkg"}, Usage: "Name of the existing package (--deploy and --src and --env will be ignored), should be in the same namespace as the function"} - FnEntryPointFlag = Flag{Type: String, Name: flagkey.FnEntrypoint, Aliases: []string{"entry"}, Usage: "Entry point for environment v2 to load with"} - FnBuildCmdFlag = Flag{Type: String, Name: flagkey.FnBuildCmd, Usage: "Package build command for builder to run with"} - FnSecretFlag = Flag{Type: StringSlice, Name: flagkey.FnSecret, Usage: "Function access to secret, should be present in the same namespace as the function. You can provide multiple secrets using multiple --secrets flags. In the case of fn update the the secrets will be replaced by the provided list of secrets."} - FnCfgMapFlag = Flag{Type: StringSlice, Name: flagkey.FnCfgMap, Usage: "Function access to configmap, should be present in the same namespace as the function. You can provide multiple configmaps using multiple --configmap flags. In case of fn update the configmaps will be replaced by the provided list of configmaps."} - FnExecutorTypeFlag = Flag{Type: String, Name: flagkey.FnExecutorType, Usage: "Executor type for execution; one of 'poolmgr', 'newdeploy'", DefaultValue: types.ExecutorTypePoolmgr} - FnExecutionTimeoutFlag = Flag{Type: Int, Name: flagkey.FnExecutionTimeout, Aliases: []string{"ft"}, Usage: "Time duration to wait for the response while executing the function", DefaultValue: 60} - FnLogPodFlag = Flag{Type: String, Name: flagkey.FnLogPod, Usage: "Function pod name (use the latest pod name if unspecified)"} - FnLogFollowFlag = Flag{Type: Bool, Name: flagkey.FnLogFollow, Short: "f", Usage: "Specify if the logs should be streamed"} - FnLogDetailFlag = Flag{Type: Bool, Name: flagkey.FnLogDetail, Short: "d", Usage: "Display detailed information"} - FnLogDBTypeFlag = Flag{Type: String, Name: flagkey.FnLogDBType, Usage: "Log database type, e.g. influxdb (currently only influxdb is supported)", DefaultValue: "influxdb"} - FnLogReverseQueryFlag = Flag{Type: Bool, Name: flagkey.FnLogReverseQuery, Short: "r", Usage: "Specify the log reverse query base on time, it will be invalid if the 'follow' flag is specified"} - FnLogCountFlag = Flag{Type: Int, Name: flagkey.FnLogCount, Usage: "Get N most recent log records", DefaultValue: 20} - FnTestBodyFlag = Flag{Type: String, Name: flagkey.FnTestBody, Short: "b", Usage: "Request body"} - FnTestTimeoutFlag = Flag{Type: Duration, Name: flagkey.FnTestTimeout, Short: "t", Usage: "Length of time to wait for the response. If set to zero or negative number, no timeout is set", DefaultValue: 30 * time.Second} - FnTestHeaderFlag = Flag{Type: StringSlice, Name: flagkey.FnTestHeader, Short: "H", Usage: "Request headers"} - FnTestQueryFlag = Flag{Type: StringSlice, Name: flagkey.FnTestQuery, Short: "q", Usage: "Request query parameters: -q key1=value1 -q key2=value2"} + FnName = Flag{Type: String, Name: flagkey.FnName, Usage: "Function name"} + FnSpecializationTimeout = Flag{Type: Int, Name: flagkey.FnSpecializationTimeout, Aliases: []string{"st"}, Usage: "Timeout for newdeploy to wait for function pod creation", DefaultValue: fv1.DefaultSpecializationTimeOut} + FnEnvName = Flag{Type: String, Name: flagkey.FnEnvironmentName, Usage: "Environment name for function"} + FnCode = Flag{Type: String, Name: flagkey.FnCode, Usage: "Local path or URL for single file source code"} + FnKeepURL = Flag{Type: Bool, Name: flagkey.PkgKeepURL, Aliases: []string{"keepurl"}, Usage: "Keep the providing URL in archive instead of downloading file from it. (If set, no checksum will be generated for file integrity check. You must ensure the file won't be changed.)"} + FnPkgName = Flag{Type: String, Name: flagkey.FnPackageName, Aliases: []string{"pkg"}, Usage: "Name of the existing package (--deploy and --src and --env will be ignored), should be in the same namespace as the function"} + FnEntryPoint = Flag{Type: String, Name: flagkey.FnEntrypoint, Aliases: []string{"entry"}, Usage: "Entry point for environment v2 to load with"} + FnBuildCmd = Flag{Type: String, Name: flagkey.FnBuildCmd, Usage: "Package build command for builder to run with"} + FnSecret = Flag{Type: StringSlice, Name: flagkey.FnSecret, Usage: "Function access to secret, should be present in the same namespace as the function. You can provide multiple secrets using multiple --secrets flags. In the case of fn update the the secrets will be replaced by the provided list of secrets."} + FnCfgMap = Flag{Type: StringSlice, Name: flagkey.FnCfgMap, Usage: "Function access to configmap, should be present in the same namespace as the function. You can provide multiple configmaps using multiple --configmap flags. In case of fn update the configmaps will be replaced by the provided list of configmaps."} + FnExecutorType = Flag{Type: String, Name: flagkey.FnExecutorType, Usage: "Executor type for execution; one of 'poolmgr', 'newdeploy'", DefaultValue: types.ExecutorTypePoolmgr} + FnExecutionTimeout = Flag{Type: Int, Name: flagkey.FnExecutionTimeout, Aliases: []string{"ft"}, Usage: "Time duration to wait for the response while executing the function", DefaultValue: 60} + FnLogPod = Flag{Type: String, Name: flagkey.FnLogPod, Usage: "Function pod name (use the latest pod name if unspecified)"} + FnLogFollow = Flag{Type: Bool, Name: flagkey.FnLogFollow, Short: "f", Usage: "Specify if the logs should be streamed"} + FnLogDetail = Flag{Type: Bool, Name: flagkey.FnLogDetail, Short: "d", Usage: "Display detailed information"} + FnLogDBType = Flag{Type: String, Name: flagkey.FnLogDBType, Usage: "Log database type, e.g. influxdb (currently only influxdb is supported)", DefaultValue: "influxdb"} + FnLogReverseQuery = Flag{Type: Bool, Name: flagkey.FnLogReverseQuery, Short: "r", Usage: "Specify the log reverse query base on time, it will be invalid if the 'follow' flag is specified"} + FnLogCount = Flag{Type: Int, Name: flagkey.FnLogCount, Usage: "Get N most recent log records", DefaultValue: 20} + FnTestBody = Flag{Type: String, Name: flagkey.FnTestBody, Short: "b", Usage: "Request body"} + FnTestTimeout = Flag{Type: Duration, Name: flagkey.FnTestTimeout, Short: "t", Usage: "Length of time to wait for the response. If set to zero or negative number, no timeout is set", DefaultValue: 30 * time.Second} + FnTestHeader = Flag{Type: StringSlice, Name: flagkey.FnTestHeader, Short: "H", Usage: "Request headers"} + FnTestQuery = Flag{Type: StringSlice, Name: flagkey.FnTestQuery, Short: "q", Usage: "Request query parameters: -q key1=value1 -q key2=value2"} - HtNameFlag = Flag{Type: String, Name: flagkey.HtName, Usage: "HTTP trigger name"} - HtMethodFlag = Flag{Type: String, Name: flagkey.HtMethod, Usage: "HTTP Method: GET|POST|PUT|DELETE|HEAD", DefaultValue: http.MethodGet} - HtUrlFlag = Flag{Type: String, Name: flagkey.HtUrl, Usage: "URL pattern (See gorilla/mux supported patterns)"} - HtHostFlag = Flag{Type: String, Name: flagkey.HtHost, Usage: "Use --ingressrule instead", Deprecated: true, Substitute: flagkey.HtIngressRule} - HtIngressFlag = Flag{Type: Bool, Name: flagkey.HtIngress, Usage: "Creates ingress with same URL"} - HtIngressRuleFlag = Flag{Type: String, Name: flagkey.HtIngressRule, Usage: "Host for Ingress rule: --ingressrule host=path (the format of host/path depends on what ingress controller you used)"} - HtIngressAnnotationFlag = Flag{Type: StringSlice, Name: flagkey.HtIngressAnnotation, Usage: "Annotation for Ingress: --ingressannotation key=value (the format of annotation depends on what ingress controller you used)"} - HtIngressTLSFlag = Flag{Type: String, Name: flagkey.HtIngressTLS, Usage: "Name of the Secret contains TLS key and crt for Ingress (the usability of TLS features depends on what ingress controller you used)"} - HtFnNameFlag = Flag{Type: StringSlice, Name: flagkey.HtFnName, Usage: "Name(s) of the function for this trigger. (If 2 functions are supplied with this flag, traffic gets routed to them based on weights supplied with --weight flag.)"} - HtFnWeightFlag = Flag{Type: IntSlice, Name: flagkey.HtFnWeight, Usage: "Weight for each function supplied with --function flag, in the same order. Used for canary deployment"} - HtFnFilterFlag = Flag{Type: String, Name: flagkey.HtFilter, Usage: "Name of the function for trigger(s)"} + HtName = Flag{Type: String, Name: flagkey.HtName, Usage: "HTTP trigger name"} + HtMethod = Flag{Type: String, Name: flagkey.HtMethod, Usage: "HTTP Method: GET|POST|PUT|DELETE|HEAD", DefaultValue: http.MethodGet} + HtUrl = Flag{Type: String, Name: flagkey.HtUrl, Usage: "URL pattern (See gorilla/mux supported patterns)"} + HtHost = Flag{Type: String, Name: flagkey.HtHost, Usage: "Use --ingressrule instead", Deprecated: true, Substitute: flagkey.HtIngressRule} + HtIngress = Flag{Type: Bool, Name: flagkey.HtIngress, Usage: "Creates ingress with same URL"} + HtIngressRule = Flag{Type: String, Name: flagkey.HtIngressRule, Usage: "Host for Ingress rule: --ingressrule host=path (the format of host/path depends on what ingress controller you used)"} + HtIngressAnnotation = Flag{Type: StringSlice, Name: flagkey.HtIngressAnnotation, Usage: "Annotation for Ingress: --ingressannotation key=value (the format of annotation depends on what ingress controller you used)"} + HtIngressTLS = Flag{Type: String, Name: flagkey.HtIngressTLS, Usage: "Name of the Secret contains TLS key and crt for Ingress (the usability of TLS features depends on what ingress controller you used)"} + HtFnName = Flag{Type: StringSlice, Name: flagkey.HtFnName, Usage: "Name(s) of the function for this trigger. (If 2 functions are supplied with this flag, traffic gets routed to them based on weights supplied with --weight flag.)"} + HtFnWeight = Flag{Type: IntSlice, Name: flagkey.HtFnWeight, Usage: "Weight for each function supplied with --function flag, in the same order. Used for canary deployment"} + HtFnFilter = Flag{Type: String, Name: flagkey.HtFilter, Usage: "Name of the function for trigger(s)"} - TtNameFlag = Flag{Type: String, Name: flagkey.TtName, Usage: "Time Trigger name"} - TtCronFlag = Flag{Type: String, Name: flagkey.TtCron, Usage: "Time trigger cron spec with each asterisk representing respectively second, minute, hour, the day of the month, month and day of the week. Also supports readable formats like '@every 5m', '@hourly'"} - TtFnNameFlag = Flag{Type: String, Name: flagkey.TtFnName, Usage: "Function name"} - TtRoundFlag = Flag{Type: Int, Name: flagkey.TtRound, Usage: "Get next N rounds of invocation time", DefaultValue: 1} + TtName = Flag{Type: String, Name: flagkey.TtName, Usage: "Time Trigger name"} + TtCron = Flag{Type: String, Name: flagkey.TtCron, Usage: "Time trigger cron spec with each asterisk representing respectively second, minute, hour, the day of the month, month and day of the week. Also supports readable formats like '@every 5m', '@hourly'"} + TtFnName = Flag{Type: String, Name: flagkey.TtFnName, Usage: "Function name"} + TtRound = Flag{Type: Int, Name: flagkey.TtRound, Usage: "Get next N rounds of invocation time", DefaultValue: 1} - MqtNameFlag = Flag{Type: String, Name: flagkey.MqtName, Usage: "Message queue trigger name"} - MqtFnNameFlag = Flag{Type: String, Name: flagkey.MqtFnName, Usage: "Function name"} - MqtMQTypeFlag = Flag{Type: String, Name: flagkey.MqtMQType, Usage: "Message queue type, e.g. nats-streaming, azure-storage-queue", DefaultValue: "nats-streaming"} - MqtTopicFlag = Flag{Type: String, Name: flagkey.MqtTopic, Usage: "Message queue Topic the trigger listens on"} - MqtRespTopicFlag = Flag{Type: String, Name: flagkey.MqtRespTopic, Usage: "Topic that the function response is sent on (response discarded if unspecified)"} - MqtErrorTopicFlag = Flag{Type: String, Name: flagkey.MqtErrorTopic, Usage: "Topic that the function error messages are sent to (errors discarded if unspecified"} - MqtMaxRetriesFlag = Flag{Type: Int, Name: flagkey.MqtMaxRetries, Usage: "Maximum number of times the function will be retried upon failure", DefaultValue: 0} - MqtMsgContentTypeFlag = Flag{Type: String, Name: flagkey.MqtMsgContentType, Short: "c", Usage: "Content type of messages that publish to the topic", DefaultValue: "application/json"} + MqtName = Flag{Type: String, Name: flagkey.MqtName, Usage: "Message queue trigger name"} + MqtFnName = Flag{Type: String, Name: flagkey.MqtFnName, Usage: "Function name"} + MqtMQType = Flag{Type: String, Name: flagkey.MqtMQType, Usage: "Message queue type, e.g. nats-streaming, azure-storage-queue", DefaultValue: "nats-streaming"} + MqtTopic = Flag{Type: String, Name: flagkey.MqtTopic, Usage: "Message queue Topic the trigger listens on"} + MqtRespTopic = Flag{Type: String, Name: flagkey.MqtRespTopic, Usage: "Topic that the function response is sent on (response discarded if unspecified)"} + MqtErrorTopic = Flag{Type: String, Name: flagkey.MqtErrorTopic, Usage: "Topic that the function error messages are sent to (errors discarded if unspecified"} + MqtMaxRetries = Flag{Type: Int, Name: flagkey.MqtMaxRetries, Usage: "Maximum number of times the function will be retried upon failure", DefaultValue: 0} + MqtMsgContentType = Flag{Type: String, Name: flagkey.MqtMsgContentType, Short: "c", Usage: "Content type of messages that publish to the topic", DefaultValue: "application/json"} - RecorderNameFlag = Flag{Type: String, Name: flagkey.RecorderName, Usage: "Recorder name"} - RecorderFnFlag = Flag{Type: String, Name: flagkey.RecorderFn, Usage: "Record Function name(s): --function=fnA"} - RecorderTriggersFlag = Flag{Type: StringSlice, Name: flagkey.RecorderTriggers, Usage: "Record Trigger name(s): --trigger=trigger1,trigger2,trigger3"} - RecorderRetentionPolicyFlag = Flag{Type: String, Name: flagkey.RecorderRetentionPolicy, Usage: "Retention policy (number of days)"} - RecorderEvictionPolicyFlag = Flag{Type: String, Name: flagkey.RecorderEvictionPolcy, Usage: "Eviction policy (default LRU)"} - RecorderEnabledFlag = Flag{Type: Bool, Name: flagkey.RecorderEnabled, Usage: "Enable recorder"} - RecorderDisabledFlag = Flag{Type: Bool, Name: flagkey.RecorderDisabled, Usage: "Disable recorder"} + RecorderName = Flag{Type: String, Name: flagkey.RecorderName, Usage: "Recorder name"} + RecorderFn = Flag{Type: String, Name: flagkey.RecorderFn, Usage: "Record Function name(s): --function=fnA"} + RecorderTriggers = Flag{Type: StringSlice, Name: flagkey.RecorderTriggers, Usage: "Record Trigger name(s): --trigger=trigger1,trigger2,trigger3"} + RecorderRetentionPolicy = Flag{Type: String, Name: flagkey.RecorderRetentionPolicy, Usage: "Retention policy (number of days)"} + RecorderEvictionPolicy = Flag{Type: String, Name: flagkey.RecorderEvictionPolcy, Usage: "Eviction policy (default LRU)"} + RecorderEnabled = Flag{Type: Bool, Name: flagkey.RecorderEnabled, Usage: "Enable recorder"} + RecorderDisabled = Flag{Type: Bool, Name: flagkey.RecorderDisabled, Usage: "Disable recorder"} - RecordsFilterTimeFromFlag = Flag{Type: String, Name: flagkey.RecordsFilterTimeFrom, Usage: "Filter records by time interval; specify start of interval"} - RecordsFilterTimeToFlag = Flag{Type: String, Name: flagkey.RecordsFilterTimeTo, Usage: "Filter records by time interval; specify end of interval"} - RecordsFilterFunctionFlag = Flag{Type: String, Name: flagkey.RecordsFilterFunction, Usage: "Filter records by function"} - RecordsFilterTriggerFlag = Flag{Type: String, Name: flagkey.RecordsFilterTrigger, Usage: "Filter records by trigger"} - RecordsVerbosityFlag = Flag{Type: Bool, Name: flagkey.RecordsVerbosity, Usage: "Toggle verbosity -- view more detailed requests/responses"} - RecordsVvFlag = Flag{Type: Bool, Name: flagkey.RecordsVv, Usage: "Toggle verbosity -- view raw requests/responses"} - RecordsReqIDFlag = Flag{Type: String, Name: flagkey.RecordsReqID, Usage: "Replay a particular request by providing the reqUID (to view reqUIDs, do 'fission records view')"} + RecordsFilterTimeFrom = Flag{Type: String, Name: flagkey.RecordsFilterTimeFrom, Usage: "Filter records by time interval; specify start of interval"} + RecordsFilterTimeTo = Flag{Type: String, Name: flagkey.RecordsFilterTimeTo, Usage: "Filter records by time interval; specify end of interval"} + RecordsFilterFunction = Flag{Type: String, Name: flagkey.RecordsFilterFunction, Usage: "Filter records by function"} + RecordsFilterTrigger = Flag{Type: String, Name: flagkey.RecordsFilterTrigger, Usage: "Filter records by trigger"} + RecordsVerbosity = Flag{Type: Bool, Name: flagkey.RecordsVerbosity, Usage: "Toggle verbosity -- view more detailed requests/responses"} + RecordsVv = Flag{Type: Bool, Name: flagkey.RecordsVv, Usage: "Toggle verbosity -- view raw requests/responses"} + RecordsReqID = Flag{Type: String, Name: flagkey.RecordsReqID, Usage: "Replay a particular request by providing the reqUID (to view reqUIDs, do 'fission records view')"} - EnvNameFlag = Flag{Type: String, Name: flagkey.EnvName, Usage: "Environment name"} - EnvPoolsizeFlag = Flag{Type: Int, Name: flagkey.EnvPoolsize, Usage: "Size of the pool", DefaultValue: 3} - EnvImageFlag = Flag{Type: String, Name: flagkey.EnvImage, Usage: "Environment image URL"} - EnvBuilderImageFlag = Flag{Type: String, Name: flagkey.EnvBuilderImage, Usage: "Environment builder image URL"} - EnvBuildCmdFlag = Flag{Type: String, Name: flagkey.EnvBuildcommand, Usage: "Build command for environment builder to build source package"} - EnvKeepArchiveFlag = Flag{Type: Bool, Name: flagkey.EnvKeeparchive, Usage: "Keep the archive instead of extracting it into a directory"} - EnvExternalNetworkFlag = Flag{Type: Bool, Name: flagkey.EnvExternalNetwork, Usage: "Allow environment access external network when istio feature enabled"} - EnvTerminationGracePeriodFlag = Flag{Type: Int, Name: flagkey.EnvGracePeriod, Aliases: []string{"period"}, Usage: "Grace time (in seconds) for pod to perform connection draining before termination", DefaultValue: 360} - EnvVersionFlag = Flag{Type: Int, Name: flagkey.EnvVersion, Usage: "Environment API version (1 means v1 interface)", DefaultValue: 1} + EnvName = Flag{Type: String, Name: flagkey.EnvName, Usage: "Environment name"} + EnvPoolsize = Flag{Type: Int, Name: flagkey.EnvPoolsize, Usage: "Size of the pool", DefaultValue: 3} + EnvImage = Flag{Type: String, Name: flagkey.EnvImage, Usage: "Environment image URL"} + EnvBuilderImage = Flag{Type: String, Name: flagkey.EnvBuilderImage, Usage: "Environment builder image URL"} + EnvBuildCmd = Flag{Type: String, Name: flagkey.EnvBuildcommand, Usage: "Build command for environment builder to build source package"} + EnvKeepArchive = Flag{Type: Bool, Name: flagkey.EnvKeeparchive, Usage: "Keep the archive instead of extracting it into a directory"} + EnvExternalNetwork = Flag{Type: Bool, Name: flagkey.EnvExternalNetwork, Usage: "Allow environment access external network when istio feature enabled"} + EnvTerminationGracePeriod = Flag{Type: Int, Name: flagkey.EnvGracePeriod, Aliases: []string{"period"}, Usage: "Grace time (in seconds) for pod to perform connection draining before termination", DefaultValue: 360} + EnvVersion = Flag{Type: Int, Name: flagkey.EnvVersion, Usage: "Environment API version (1 means v1 interface)", DefaultValue: 1} - KwNameFlag = Flag{Type: String, Name: flagkey.KwName, Usage: "Watch name"} - KwFnNameFlag = Flag{Type: String, Name: flagkey.KwFnName, Usage: "Function name"} - KwNamespaceFlag = Flag{Type: String, Name: flagkey.KwNamespace, Usage: "Namespace of resource to watch"} - KwObjTypeFlag = Flag{Type: String, Name: flagkey.KwObjType, Usage: "Type of resource to watch (Pod, Service, etc.)"} - KwLabelsFlag = Flag{Type: String, Name: flagkey.KwLabels, Usage: "Label selector of the form a=b,c=d"} + KwName = Flag{Type: String, Name: flagkey.KwName, Usage: "Watch name"} + KwFnName = Flag{Type: String, Name: flagkey.KwFnName, Usage: "Function name"} + KwNamespace = Flag{Type: String, Name: flagkey.KwNamespace, Aliases: []string{"ns"}, Usage: "Namespace of resource to watch", DefaultValue: metav1.NamespaceDefault} + KwObjType = Flag{Type: String, Name: flagkey.KwObjType, Usage: "Type of resource to watch (Pod, Service, etc.)", DefaultValue: "pod"} + KwLabels = Flag{Type: String, Name: flagkey.KwLabels, Usage: "Label selector of the form a=b,c=d"} - PkgNameFlag = Flag{Type: String, Name: flagkey.PkgName, Usage: "Package name"} - PkgForceFlag = Flag{Type: Bool, Name: flagkey.PkgForce, Short: "f", Usage: "Force update a package even if it is used by one or more functions"} - PkgEnvironmentFlag = Flag{Type: String, Name: flagkey.PkgEnvironment, Usage: "Environment name"} - PkgKeepURLFlag = Flag{Type: Bool, Name: flagkey.PkgKeepURL, Aliases: []string{"keepurl"}, Usage: "Keep the providing URL in archive instead of downloading file from it. (If set, no checksum will be generated for file integrity check. You must ensure the file won't be changed.)"} - PkgBuildCmdFlag = Flag{Type: String, Name: flagkey.PkgBuildCmd, Usage: "Build command for builder to run with"} - PkgOutputFlag = Flag{Type: String, Name: flagkey.PkgOutput, Short: "o", Usage: "Output filename to save archive content"} - PkgStatusFlag = Flag{Type: String, Name: flagkey.PkgStatus, Usage: `Filter packages by status`} - PkgOrphanFlag = Flag{Type: Bool, Name: flagkey.PkgOrphan, Usage: "Orphan packages that are not referenced by any function"} - PkgDeployArchiveFlag = Flag{Type: StringSlice, Name: flagkey.PkgDeployArchive, Aliases: []string{"deploy"}, Usage: "Local path or URL for binary archive"} - PkgSrcArchiveFlag = Flag{Type: StringSlice, Name: flagkey.PkgSrcArchive, Aliases: []string{"source", "src"}, Usage: "Local path or URL for source archive"} + PkgName = Flag{Type: String, Name: flagkey.PkgName, Usage: "Package name"} + PkgForce = Flag{Type: Bool, Name: flagkey.PkgForce, Short: "f", Usage: "Force update a package even if it is used by one or more functions"} + PkgEnvironment = Flag{Type: String, Name: flagkey.PkgEnvironment, Usage: "Environment name"} + PkgKeepURL = Flag{Type: Bool, Name: flagkey.PkgKeepURL, Aliases: []string{"keepurl"}, Usage: "Keep the providing URL in archive instead of downloading file from it. (If set, no checksum will be generated for file integrity check. You must ensure the file won't be changed.)"} + PkgBuildCmd = Flag{Type: String, Name: flagkey.PkgBuildCmd, Usage: "Build command for builder to run with"} + PkgOutput = Flag{Type: String, Name: flagkey.PkgOutput, Short: "o", Usage: "Output filename to save archive content"} + PkgStatus = Flag{Type: String, Name: flagkey.PkgStatus, Usage: `Filter packages by status`} + PkgOrphan = Flag{Type: Bool, Name: flagkey.PkgOrphan, Usage: "Orphan packages that are not referenced by any function"} + PkgDeployArchive = Flag{Type: StringSlice, Name: flagkey.PkgDeployArchive, Aliases: []string{"deploy"}, Usage: "Local path or URL for binary archive"} + PkgSrcArchive = Flag{Type: StringSlice, Name: flagkey.PkgSrcArchive, Aliases: []string{"source", "src"}, Usage: "Local path or URL for source archive"} - SpecSaveFlag = Flag{Type: Bool, Name: flagkey.SpecSave, Usage: "Save to the spec directory instead of creating on cluster"} - SpecDirFlag = Flag{Type: String, Name: flagkey.SpecDir, Usage: "Directory to store specs, defaults to ./specs"} - SpecNameFlag = Flag{Type: String, Name: flagkey.SpecName, Usage: "Name for the app, applied to resources as a Kubernetes annotation"} - SpecDeployIDFlag = Flag{Type: String, Name: flagkey.SpecDeployID, Aliases: []string{"id"}, Usage: "Deployment ID for the spec deployment config"} - SpecWaitFlag = Flag{Type: Bool, Name: flagkey.SpecWait, Usage: "Wait for package builds"} - SpecWatchFlag = Flag{Type: Bool, Name: flagkey.SpecWatch, Usage: "Watch local files for change, and re-apply specs as necessary"} - SpecDeleteFlag = Flag{Type: Bool, Name: flagkey.SpecDelete, Usage: "Allow apply to delete resources that no longer exist in the specification"} + SpecSave = Flag{Type: Bool, Name: flagkey.SpecSave, Usage: "Save to the spec directory instead of creating on cluster"} + SpecDir = Flag{Type: String, Name: flagkey.SpecDir, Usage: "Directory to store specs, defaults to ./specs"} + SpecName = Flag{Type: String, Name: flagkey.SpecName, Usage: "Name for the app, applied to resources as a Kubernetes annotation"} + SpecDeployID = Flag{Type: String, Name: flagkey.SpecDeployID, Aliases: []string{"id"}, Usage: "Deployment ID for the spec deployment config"} + SpecWait = Flag{Type: Bool, Name: flagkey.SpecWait, Usage: "Wait for package builds"} + SpecWatch = Flag{Type: Bool, Name: flagkey.SpecWatch, Usage: "Watch local files for change, and re-apply specs as necessary"} + SpecDelete = Flag{Type: Bool, Name: flagkey.SpecDelete, Usage: "Allow apply to delete resources that no longer exist in the specification"} - SupportOutputFlag = Flag{Type: String, Name: flagkey.SupportOutput, Short: "o", Usage: "Output directory to save dump archive/files", DefaultValue: flagkey.DefaultSpecOutputDir} - SupportNoZipFlag = Flag{Type: Bool, Name: flagkey.SupportNoZip, Usage: "Save dump information into multiple files instead of single zip file"} + SupportOutput = Flag{Type: String, Name: flagkey.SupportOutput, Short: "o", Usage: "Output directory to save dump archive/files", DefaultValue: flagkey.DefaultSpecOutputDir} + SupportNoZip = Flag{Type: Bool, Name: flagkey.SupportNoZip, Usage: "Save dump information into multiple files instead of single zip file"} - CanaryNameFlag = Flag{Type: String, Name: flagkey.CanaryName, Usage: "Name for the canary config"} - CanaryTriggerNameFlag = Flag{Type: String, Name: flagkey.CanaryHTTPTriggerName, Usage: "Http trigger that this config references"} - CanaryNewFuncFlag = Flag{Type: String, Name: flagkey.CanaryNewFunc, Aliases: []string{"newfn"}, Usage: "New version of the function"} - CanaryOldFuncFlag = Flag{Type: String, Name: flagkey.CanaryOldFunc, Aliases: []string{"oldfn"}, Usage: "Old stable version of the function"} - CanaryWeightIncrementFlag = Flag{Type: Int, Name: flagkey.CanaryWeightIncrement, Aliases: []string{"step"}, Usage: "Weight increment step for function", DefaultValue: 20} - CanaryIncrementIntervalFlag = Flag{Type: String, Name: flagkey.CanaryIncrementInterval, Aliases: []string{"internal"}, Usage: "Weight increment interval, string representation of time.Duration, ex : 1m, 2h, 2d", DefaultValue: "2m"} - CanaryFailureThresholdFlag = Flag{Type: Int, Name: flagkey.CanaryFailureThreshold, Aliases: []string{"threshold"}, Usage: "Threshold in percentage beyond which the new version of the function is considered unstable", DefaultValue: 10} + CanaryName = Flag{Type: String, Name: flagkey.CanaryName, Usage: "Name for the canary config"} + CanaryTriggerName = Flag{Type: String, Name: flagkey.CanaryHTTPTriggerName, Usage: "Http trigger that this config references"} + CanaryNewFunc = Flag{Type: String, Name: flagkey.CanaryNewFunc, Aliases: []string{"newfn"}, Usage: "New version of the function"} + CanaryOldFunc = Flag{Type: String, Name: flagkey.CanaryOldFunc, Aliases: []string{"oldfn"}, Usage: "Old stable version of the function"} + CanaryWeightIncrement = Flag{Type: Int, Name: flagkey.CanaryWeightIncrement, Aliases: []string{"step"}, Usage: "Weight increment step for function", DefaultValue: 20} + CanaryIncrementInterval = Flag{Type: String, Name: flagkey.CanaryIncrementInterval, Aliases: []string{"internal"}, Usage: "Weight increment interval, string representation of time.Duration, ex : 1m, 2h, 2d", DefaultValue: "2m"} + CanaryFailureThreshold = Flag{Type: Int, Name: flagkey.CanaryFailureThreshold, Aliases: []string{"threshold"}, Usage: "Threshold in percentage beyond which the new version of the function is considered unstable", DefaultValue: 10} ) diff --git a/pkg/fission-cli/flag/key/key.go b/pkg/fission-cli/flag/key/key.go index d186ed02..07f18a52 100644 --- a/pkg/fission-cli/flag/key/key.go +++ b/pkg/fission-cli/flag/key/key.go @@ -116,7 +116,7 @@ const ( KwName = resourceName KwFnName = "function" - KwNamespace = "ns" + KwNamespace = "namespace" KwObjType = "type" KwLabels = "labels" diff --git a/pkg/fission-cli/util/util.go b/pkg/fission-cli/util/util.go index 9b9dcaa5..85dd8e28 100644 --- a/pkg/fission-cli/util/util.go +++ b/pkg/fission-cli/util/util.go @@ -195,8 +195,8 @@ func GetVersion(client *client.Client) info.Versions { return versions } -func GetServer(flags cli.Input) (c *client.Client, err error) { - serverUrl := flags.GlobalString(flagkey.Server) +func GetServer(input cli.Input) (c *client.Client, err error) { + serverUrl := input.GlobalString(flagkey.Server) if len(serverUrl) == 0 { // starts local portforwarder etc. serverUrl, err = GetApplicationUrl("application=fission-api") @@ -215,7 +215,7 @@ func GetServer(flags cli.Input) (c *client.Client, err error) { return client.MakeClient(serverUrl), nil } -func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.ResourceRequirements, error) { +func GetResourceReqs(input cli.Input, resReqs *v1.ResourceRequirements) (*v1.ResourceRequirements, error) { r := &v1.ResourceRequirements{} if resReqs != nil { @@ -233,8 +233,8 @@ func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res e := utils.MultiErrorWithFormat() - if flags.IsSet(flagkey.RuntimeMincpu) { - mincpu := flags.Int(flagkey.RuntimeMincpu) + if input.IsSet(flagkey.RuntimeMincpu) { + mincpu := input.Int(flagkey.RuntimeMincpu) cpuRequest, err := resource.ParseQuantity(strconv.Itoa(mincpu) + "m") if err != nil { e = multierror.Append(e, errors.Wrap(err, "Failed to parse mincpu")) @@ -242,8 +242,8 @@ func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res r.Requests[v1.ResourceCPU] = cpuRequest } - if flags.IsSet(flagkey.RuntimeMinmemory) { - minmem := flags.Int(flagkey.RuntimeMinmemory) + if input.IsSet(flagkey.RuntimeMinmemory) { + minmem := input.Int(flagkey.RuntimeMinmemory) memRequest, err := resource.ParseQuantity(strconv.Itoa(minmem) + "Mi") if err != nil { e = multierror.Append(e, errors.Wrap(err, "Failed to parse minmemory")) @@ -251,8 +251,8 @@ func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res r.Requests[v1.ResourceMemory] = memRequest } - if flags.IsSet(flagkey.RuntimeMaxcpu) { - maxcpu := flags.Int(flagkey.RuntimeMaxcpu) + if input.IsSet(flagkey.RuntimeMaxcpu) { + maxcpu := input.Int(flagkey.RuntimeMaxcpu) cpuLimit, err := resource.ParseQuantity(strconv.Itoa(maxcpu) + "m") if err != nil { e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxcpu")) @@ -260,8 +260,8 @@ func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res r.Limits[v1.ResourceCPU] = cpuLimit } - if flags.IsSet(flagkey.RuntimeMaxmemory) { - maxmem := flags.Int(flagkey.RuntimeMaxmemory) + if input.IsSet(flagkey.RuntimeMaxmemory) { + maxmem := input.Int(flagkey.RuntimeMaxmemory) memLimit, err := resource.ParseQuantity(strconv.Itoa(maxmem) + "Mi") if err != nil { e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxmemory")) @@ -297,27 +297,10 @@ func GetResourceReqs(flags cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res }, nil } -func GetSpecDir(flags cli.Input) string { - specDir := flags.String(flagkey.SpecDir) +func GetSpecDir(input cli.Input) string { + specDir := input.String(flagkey.SpecDir) if len(specDir) == 0 { specDir = "specs" } return specDir } - -// GetMetadata returns a pointer to ObjectMeta that is populated with resource name and namespace given by the user. -func GetMetadata(nameFlagText string, namespaceFlagText string, flags cli.Input) (*metav1.ObjectMeta, error) { - name := flags.String(nameFlagText) - if len(name) == 0 { - return nil, errors.Errorf("need a resource name, use --%v", nameFlagText) - } - - ns := flags.String(namespaceFlagText) - - m := &metav1.ObjectMeta{ - Name: name, - Namespace: ns, - } - - return m, nil -} diff --git a/test/tests/mqtrigger/nats/test_mqtrigger.sh b/test/tests/mqtrigger/nats/test_mqtrigger.sh index 3f13f7ca..02a1effc 100755 --- a/test/tests/mqtrigger/nats/test_mqtrigger.sh +++ b/test/tests/mqtrigger/nats/test_mqtrigger.sh @@ -65,5 +65,8 @@ if [[ "$response" != "$expectedRespOutput" ]]; then exit 1 fi +log "Deleting message queue trigger" +fission mqtrigger delete --name $mqt + log "Subscriber received expected response: $response" log "Test PASSED" diff --git a/test/tests/mqtrigger/nats/test_mqtrigger_error.sh b/test/tests/mqtrigger/nats/test_mqtrigger_error.sh index e8c0ac44..1f703945 100755 --- a/test/tests/mqtrigger/nats/test_mqtrigger_error.sh +++ b/test/tests/mqtrigger/nats/test_mqtrigger_error.sh @@ -73,4 +73,8 @@ if [[ "$response" != "$expectedRespOutput" ]]; then else log "Responses match." fi + +log "Deleting message queue trigger" +fission mqtrigger delete --name $mqt + log "Test PASSED" diff --git a/test/tests/test_archive_pruner.sh b/test/tests/test_archive_pruner.sh index 800cfa0d..9c83de9f 100755 --- a/test/tests/test_archive_pruner.sh +++ b/test/tests/test_archive_pruner.sh @@ -36,7 +36,7 @@ create_archive() { create_package() { log "Creating package" - pkg=$(fission package create --deploy "$tmp_dir/test-deploy-pkg.zip" --env $env| cut -f2 -d' '| tr -d \') + fission package create --name $1 --deploy "$tmp_dir/test-deploy-pkg.zip" --env $env } delete_package() { @@ -74,14 +74,14 @@ main() { log "created archive test-deploy-pkg.zip" # create packages with the huge archive - create_package - pkg_1=$pkg + pkg_1=$(generate_test_id) + create_package $pkg_1 get_archive_url_from_package $pkg_1 url_1=$url log "pkg: $pkg_1, archive_url : $url_1" - create_package - pkg_2=$pkg + pkg_2=$(generate_test_id) + create_package $pkg_2 get_archive_url_from_package $pkg_2 url_2=$url log "pkg: $pkg_2, archive_url : $url_2" diff --git a/test/tests/test_environments/test_go_env.sh b/test/tests/test_environments/test_go_env.sh index 135d389d..5295f860 100755 --- a/test/tests/test_environments/test_go_env.sh +++ b/test/tests/test_environments/test_go_env.sh @@ -33,7 +33,8 @@ fission env create --name $env --image $GO_RUNTIME_IMAGE --builder $GO_BUILDER_I timeout 90 bash -c "wait_for_builder $env" -pkgName=$(fission package create --src hello.go --env $env| cut -f2 -d' '| tr -d \') +pkgName=$(generate_test_id) +fission package create --name $pkgName --src hello.go --env $env # wait for build to finish at most 90s timeout 90 bash -c "waitBuild $pkgName" @@ -58,7 +59,8 @@ timeout 60 bash -c "test_fn $fn_nd 'Hello'" # Create zip file without top level directory (module-example) cd module-example && zip -r $tmp_dir/module.zip * -pkgName=$(fission package create --src $tmp_dir/module.zip --env $env| cut -f2 -d' '| tr -d \') +pkgName=$(generate_test_id) +fission package create --name $pkgName --src $tmp_dir/module.zip --env $env # wait for build to finish at most 90s timeout 90 bash -c "waitBuild $pkgName" diff --git a/test/tests/test_environments/test_java_builder.sh b/test/tests/test_environments/test_java_builder.sh index 31a9b9b0..9d9636b1 100755 --- a/test/tests/test_environments/test_java_builder.sh +++ b/test/tests/test_environments/test_java_builder.sh @@ -37,7 +37,8 @@ fission env create --name $env --image $JVM_RUNTIME_IMAGE --version 2 --keeparch timeout 90 bash -c "wait_for_builder $env" log "Creating package from the source archive" -pkg_name=`fission package create --sourcearchive $tmp_dir/java-src-pkg.zip --env $env|cut -d' ' -f 2|cut -d"'" -f 2` +pkg_name=$(generate_test_id) +fission package create --name $pkg_name --sourcearchive $tmp_dir/java-src-pkg.zip --env $env log "Created package $pkg_name" log "Checking the status of package" diff --git a/test/tests/test_environments/test_python_env.sh b/test/tests/test_environments/test_python_env.sh index 7d62a824..34dd856f 100755 --- a/test/tests/test_environments/test_python_env.sh +++ b/test/tests/test_environments/test_python_env.sh @@ -29,7 +29,6 @@ fn2=test-python-env-2-$TEST_ID fn3=test-python-env-3-$TEST_ID fn4=test-python-env-4-$TEST_ID fn5=test-python-env-5-$TEST_ID -pkg= log "Creating v1api environment ..." @@ -50,7 +49,8 @@ log "Creating package ..." pushd $ROOT/test/tests/test_environments/python_src/ zip -r $tmp_dir/src-pkg.zip * popd -pkg=$(fission package create --src $tmp_dir/src-pkg.zip --env $env_v2api | cut -f2 -d' '| tr -d \') +pkg=$(generate_test_id) +fission package create --name $pkg --src $tmp_dir/src-pkg.zip --env $env_v2api timeout 60s bash -c "waitBuild $pkg" diff --git a/test/tests/test_environments/test_tensorflow_serving_env.sh b/test/tests/test_environments/test_tensorflow_serving_env.sh index e7a020d4..a225fbc5 100755 --- a/test/tests/test_environments/test_tensorflow_serving_env.sh +++ b/test/tests/test_environments/test_tensorflow_serving_env.sh @@ -33,7 +33,8 @@ fission env create --name $env --image $TS_RUNTIME_IMAGE --version 2 --period 5 zip -r half_plus_two.zip ./half_plus_two -pkgName=$(fission package create --deploy half_plus_two.zip --env $env| cut -f2 -d' '| tr -d \') +pkgName=$(generate_test_id) +fission package create --name $pkgName --deploy half_plus_two.zip --env $env # wait for build to finish at most 90s timeout 90 bash -c "waitBuild $pkgName" diff --git a/test/tests/test_package_command.sh b/test/tests/test_package_command.sh index 4121128d..3ea91203 100755 --- a/test/tests/test_package_command.sh +++ b/test/tests/test_package_command.sh @@ -59,7 +59,8 @@ timeout 180s bash -c "wait_for_builder $env" # 1) Multiple source files (multiple inputs, Using * expression, from a directory) # Currently only * expression implemented as a test pushd $ROOT/examples/python/ -pkg1=$(fission package create --src "sourcepkg/*" --env $env --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \') +pkg1="pkg1-${TEST_ID}" +fission package create --name $pkg1 --src "sourcepkg/*" --env $env --buildcmd "./build.sh" popd # wait for build to finish at most 60s timeout 60s bash -c "waitBuild $pkg1" @@ -77,7 +78,8 @@ checkFunctionResponse $fn1 'a: 1 b: {c: 3, d: 4}' # 2) Source archive file log "Creating pacakage with source archive" zip -jr $tmp_dir/demo-src-pkg.zip $ROOT/examples/python/sourcepkg/ -pkg2=$(fission package create --src $tmp_dir/demo-src-pkg.zip --env $env --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \') +pkg2="pkg2-${TEST_ID}" +fission package create --name $pkg2 --src $tmp_dir/demo-src-pkg.zip --env $env --buildcmd "./build.sh" # wait for build to finish at most 60s timeout 60s bash -c "waitBuild $pkg2" @@ -98,7 +100,8 @@ checkFunctionResponse $fn2 'a: 1 b: {c: 3, d: 4}' # 4) Deployment files from a directory pushd $ROOT/examples/python/ -pkg4=$(fission package create --deploy "multifile/*" --env $env| cut -f2 -d' '| tr -d \') +pkg4="pkg4-${TEST_ID}" +fission package create --name $pkg4 --deploy "multifile/*" --env $env popd log "Creating function " $fn4 fission fn create --name $fn4 --pkg $pkg4 --entrypoint "main.main" @@ -118,7 +121,8 @@ mkdir $tmp_dir/deploypkg touch $tmp_dir/deploypkg/__init__.py printf 'def main():\n return "Hello, world!"' > $tmp_dir/deploypkg/hello.py zip -jr $tmp_dir/demo-deploy-pkg.zip $tmp_dir/deploypkg/ -pkg5=$(fission package create --deploy $tmp_dir/demo-deploy-pkg.zip --env $env| cut -f2 -d' '| tr -d \') +pkg5="pkg5-${TEST_ID}" +fission package create --name $pkg5 --deploy $tmp_dir/demo-deploy-pkg.zip --env $env log "Updating function " $fn5