Add controller API client interface (#1467)
This PR adds an interface for controller API client, it allows us to implement mock API client for unit testing with ease and we are able to generate spec file without accessing the real Fission server.
This commit is contained in:
@@ -24,8 +24,8 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"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"
|
||||
@@ -33,19 +33,12 @@ import (
|
||||
)
|
||||
|
||||
type CreateSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
watcher *fv1.KubernetesWatchTrigger
|
||||
}
|
||||
|
||||
func Create(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := CreateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
return (&CreateSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
@@ -119,7 +112,7 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := opts.client.WatchCreate(opts.watcher)
|
||||
_, err := opts.Client().V1().KubeWatcher().Create(opts.watcher)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating kubewatch")
|
||||
}
|
||||
|
||||
@@ -22,27 +22,19 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type DeleteSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
name string
|
||||
namespace string
|
||||
}
|
||||
|
||||
func Delete(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := DeleteSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
return (&DeleteSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
@@ -60,7 +52,7 @@ func (opts *DeleteSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) error {
|
||||
err := opts.client.WatchDelete(&metav1.ObjectMeta{
|
||||
err := opts.Client().V1().KubeWatcher().Delete(&metav1.ObjectMeta{
|
||||
Name: opts.name,
|
||||
Namespace: opts.namespace,
|
||||
})
|
||||
|
||||
@@ -23,26 +23,18 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type ListSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
namespace string
|
||||
}
|
||||
|
||||
func List(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
return (&ListSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
@@ -59,7 +51,7 @@ func (opts *ListSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
ws, err := opts.client.WatchList(opts.namespace)
|
||||
ws, err := opts.Client().V1().KubeWatcher().List(opts.namespace)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing kubewatches")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user