Refactor plugin & version subcommands (#1359)
This commit is contained in:
@@ -23,7 +23,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -32,12 +31,13 @@ import (
|
|||||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/environment"
|
"github.com/fission/fission/pkg/fission-cli/cmd/environment"
|
||||||
_package "github.com/fission/fission/pkg/fission-cli/cmd/package"
|
_package "github.com/fission/fission/pkg/fission-cli/cmd/package"
|
||||||
|
plugincmd "github.com/fission/fission/pkg/fission-cli/cmd/plugin"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||||
"github.com/fission/fission/pkg/fission-cli/cmd/support"
|
"github.com/fission/fission/pkg/fission-cli/cmd/support"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/cmd/version"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/log"
|
||||||
"github.com/fission/fission/pkg/fission-cli/plugin"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/util"
|
|
||||||
"github.com/fission/fission/pkg/info"
|
"github.com/fission/fission/pkg/info"
|
||||||
|
"github.com/fission/fission/pkg/plugin"
|
||||||
"github.com/fission/fission/pkg/types"
|
"github.com/fission/fission/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -59,16 +59,15 @@ func NewCliApp() *cli.App {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "fission"
|
app.Name = "fission"
|
||||||
app.Usage = "Serverless functions for Kubernetes"
|
app.Usage = "Serverless functions for Kubernetes"
|
||||||
app.Version = info.Version
|
app.HideVersion = true
|
||||||
cli.VersionPrinter = versionPrinter
|
|
||||||
app.CustomAppHelpTemplate = helpTemplate
|
app.CustomAppHelpTemplate = helpTemplate
|
||||||
app.ExtraInfo = func() map[string]string {
|
app.ExtraInfo = func() map[string]string {
|
||||||
info := map[string]string{}
|
pluginInfo := map[string]string{}
|
||||||
for _, pmd := range plugin.FindAll() {
|
for _, pmd := range plugin.FindAll() {
|
||||||
names := strings.Join(append([]string{pmd.Name}, pmd.Aliases...), ", ")
|
names := strings.Join(append([]string{pmd.Name}, pmd.Aliases...), ", ")
|
||||||
info[names] = pmd.Usage
|
pluginInfo[names] = pmd.Usage
|
||||||
}
|
}
|
||||||
return info
|
return pluginInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
@@ -312,6 +311,10 @@ func NewCliApp() *cli.App {
|
|||||||
{Name: "list", Usage: "List all canary configs in a namespace", Flags: []cli.Flag{canaryNamespaceFlag}, Action: canaryConfigList},
|
{Name: "list", Usage: "List all canary configs in a namespace", Flags: []cli.Flag{canaryNamespaceFlag}, Action: canaryConfigList},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginSubCommands := []cli.Command{
|
||||||
|
{Name: "list", Usage: "List installed client plugins", Action: urfavecli.Wrapper(plugincmd.List)},
|
||||||
|
}
|
||||||
|
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
{Name: "function", Aliases: []string{"fn"}, Usage: "Create, update and manage functions", Subcommands: fnSubcommands},
|
{Name: "function", Aliases: []string{"fn"}, Usage: "Create, update and manage functions", Subcommands: fnSubcommands},
|
||||||
{Name: "httptrigger", Aliases: []string{"ht", "route"}, Usage: "Manage HTTP triggers (routes) for functions", Subcommands: htSubcommands},
|
{Name: "httptrigger", Aliases: []string{"ht", "route"}, Usage: "Manage HTTP triggers (routes) for functions", Subcommands: htSubcommands},
|
||||||
@@ -325,8 +328,9 @@ func NewCliApp() *cli.App {
|
|||||||
{Name: "package", Aliases: []string{"pkg"}, Usage: "Manage packages", Subcommands: pkgSubCommands},
|
{Name: "package", Aliases: []string{"pkg"}, Usage: "Manage packages", Subcommands: pkgSubCommands},
|
||||||
{Name: "spec", Aliases: []string{"specs"}, Usage: "Manage a declarative app specification", Subcommands: specSubCommands},
|
{Name: "spec", Aliases: []string{"specs"}, Usage: "Manage a declarative app specification", Subcommands: specSubCommands},
|
||||||
{Name: "support", Usage: "Collect an archive of diagnostic information for support", Subcommands: supportSubCommands},
|
{Name: "support", Usage: "Collect an archive of diagnostic information for support", Subcommands: supportSubCommands},
|
||||||
cmdPlugin,
|
|
||||||
{Name: "canary-config", Aliases: []string{}, Usage: "Create, Update and manage Canary Configs", Subcommands: canarySubCommands},
|
{Name: "canary-config", Aliases: []string{}, Usage: "Create, Update and manage Canary Configs", Subcommands: canarySubCommands},
|
||||||
|
{Name: "plugin", Aliases: []string{"plugins"}, Usage: "Manage Fission CLI plugins", Subcommands: pluginSubCommands},
|
||||||
|
{Name: "version", Usage: "Version information", Action: urfavecli.Wrapper(version.Version)},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Before = cliHook
|
app.Before = cliHook
|
||||||
@@ -335,10 +339,6 @@ func NewCliApp() *cli.App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleNoCommand(ctx *cli.Context) error {
|
func handleNoCommand(ctx *cli.Context) error {
|
||||||
if ctx.GlobalBool("version") {
|
|
||||||
versionPrinter(ctx)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if ctx.GlobalBool("plugin") {
|
if ctx.GlobalBool("plugin") {
|
||||||
bs, err := json.Marshal(plugin.Metadata{
|
bs, err := json.Marshal(plugin.Metadata{
|
||||||
Version: info.Version,
|
Version: info.Version,
|
||||||
@@ -399,16 +399,6 @@ To install it for your local Fission CLI:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func versionPrinter(_ *cli.Context) {
|
|
||||||
client := util.GetApiClient(util.GetServerUrl())
|
|
||||||
ver := util.GetVersion(client)
|
|
||||||
bs, err := yaml.Marshal(ver)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Error formatting versions: " + err.Error())
|
|
||||||
}
|
|
||||||
fmt.Print(string(bs))
|
|
||||||
}
|
|
||||||
|
|
||||||
func flagValueParser(args []string) error {
|
func flagValueParser(args []string) error {
|
||||||
// all input value for flags are properly set
|
// all input value for flags are properly set
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2016 The Fission Authors.
|
Copyright 2019 The Fission Authors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -14,32 +14,31 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package fission_cli
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
"github.com/fission/fission/pkg/fission-cli/plugin"
|
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||||
|
"github.com/fission/fission/pkg/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdPlugin = cli.Command{
|
type ListSubCommand struct {
|
||||||
Name: "plugin",
|
client *client.Client
|
||||||
Aliases: []string{"plugins"},
|
|
||||||
Usage: "Manage Fission CLI plugins",
|
|
||||||
Subcommands: []cli.Command{
|
|
||||||
{
|
|
||||||
Name: "list",
|
|
||||||
Usage: "List installed client plugins",
|
|
||||||
Action: pluginList,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pluginList(_ *cli.Context) error {
|
func List(flags cli.Input) error {
|
||||||
|
opts := &ListSubCommand{
|
||||||
|
client: cmd.GetServer(flags),
|
||||||
|
}
|
||||||
|
return opts.do(flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (opts *ListSubCommand) do(flags cli.Input) error {
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||||
fmt.Fprintln(w, "NAME\tVERSION\tPATH")
|
fmt.Fprintln(w, "NAME\tVERSION\tPATH")
|
||||||
for _, p := range plugin.FindAll() {
|
for _, p := range plugin.FindAll() {
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2019 The Fission Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
|
|
||||||
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/log"
|
||||||
|
"github.com/fission/fission/pkg/fission-cli/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
type VersionSubCommand struct {
|
||||||
|
client *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func Version(flags cli.Input) error {
|
||||||
|
opts := &VersionSubCommand{
|
||||||
|
client: cmd.GetServer(flags),
|
||||||
|
}
|
||||||
|
return opts.do(flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (opts *VersionSubCommand) do(flags cli.Input) error {
|
||||||
|
ver := util.GetVersion(opts.client)
|
||||||
|
bs, err := yaml.Marshal(ver)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error formatting versions: " + err.Error())
|
||||||
|
}
|
||||||
|
fmt.Print(string(bs))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -31,6 +31,8 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
"github.com/fission/fission/pkg/controller/client"
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
"github.com/fission/fission/pkg/fission-cli/log"
|
||||||
|
"github.com/fission/fission/pkg/info"
|
||||||
|
"github.com/fission/fission/pkg/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetApiClient(serverUrl string) *client.Client {
|
func GetApiClient(serverUrl string) *client.Client {
|
||||||
@@ -180,3 +182,33 @@ func CheckFunctionExistence(fissionClient *client.Client, functions []string, fn
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetVersion(client *client.Client) info.Versions {
|
||||||
|
// Fetch client versions
|
||||||
|
versions := info.Versions{
|
||||||
|
Client: map[string]info.BuildMeta{
|
||||||
|
"fission/core": info.BuildInfo(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pmd := range plugin.FindAll() {
|
||||||
|
versions.Client[pmd.Name] = info.BuildMeta{
|
||||||
|
Version: pmd.Version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
serverInfo, err := client.ServerInfo()
|
||||||
|
if err != nil {
|
||||||
|
log.Warn(fmt.Sprintf("Error getting Fission API version: %v", err))
|
||||||
|
serverInfo = &info.ServerInfo{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch server versions
|
||||||
|
versions.Server = map[string]info.BuildMeta{
|
||||||
|
"fission/core": serverInfo.Build,
|
||||||
|
}
|
||||||
|
|
||||||
|
// FUTURE: fetch versions of plugins server-side
|
||||||
|
|
||||||
|
return versions
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package util
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/fission/fission/pkg/controller/client"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/log"
|
|
||||||
"github.com/fission/fission/pkg/fission-cli/plugin"
|
|
||||||
"github.com/fission/fission/pkg/info"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Versions is a container of versions of the client (and its plugins) and server (and its plugins).
|
|
||||||
type Versions struct {
|
|
||||||
Client map[string]info.BuildMeta `json:"client"`
|
|
||||||
Server map[string]info.BuildMeta `json:"server"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVersion(client *client.Client) Versions {
|
|
||||||
// Fetch client versions
|
|
||||||
versions := Versions{
|
|
||||||
Client: map[string]info.BuildMeta{
|
|
||||||
"fission/core": info.BuildInfo(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, pmd := range plugin.FindAll() {
|
|
||||||
versions.Client[pmd.Name] = info.BuildMeta{
|
|
||||||
Version: pmd.Version,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
serverInfo, err := client.ServerInfo()
|
|
||||||
if err != nil {
|
|
||||||
log.Warn(fmt.Sprintf("Error getting Fission API version: %v", err))
|
|
||||||
serverInfo = &info.ServerInfo{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch server versions
|
|
||||||
versions.Server = map[string]info.BuildMeta{
|
|
||||||
"fission/core": serverInfo.Build,
|
|
||||||
}
|
|
||||||
|
|
||||||
// FUTURE: fetch versions of plugins server-side
|
|
||||||
|
|
||||||
return versions
|
|
||||||
}
|
|
||||||
@@ -43,6 +43,12 @@ type (
|
|||||||
Build BuildMeta `json:"Build,omitempty"`
|
Build BuildMeta `json:"Build,omitempty"`
|
||||||
ServerTime Time `json:"ServerTime,omitempty"`
|
ServerTime Time `json:"ServerTime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Versions is a container of versions of the client (and its plugins) and server (and its plugins).
|
||||||
|
Versions struct {
|
||||||
|
Client map[string]BuildMeta `json:"client"`
|
||||||
|
Server map[string]BuildMeta `json:"server"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildInfo() BuildMeta {
|
func BuildInfo() BuildMeta {
|
||||||
|
|||||||
+1
-1
@@ -323,7 +323,7 @@ check_gitcommit_version() {
|
|||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
# ensure we run tests against with the same git commit version of CLI & server
|
# ensure we run tests against with the same git commit version of CLI & server
|
||||||
ip=$(fission --version|grep "GitCommit"|tr -d ' '|uniq -c|grep "2 GitCommit")
|
ip=$(fission version|grep "GitCommit"|tr -d ' '|uniq -c|grep "2 GitCommit")
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user