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"
|
||||
@@ -34,19 +34,12 @@ import (
|
||||
)
|
||||
|
||||
type CreateSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
trigger *fv1.MessageQueueTrigger
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -164,7 +157,7 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := opts.client.MessageQueueTriggerCreate(opts.trigger)
|
||||
_, err := opts.Client().V1().MessageQueueTrigger().Create(opts.trigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "create message queue trigger")
|
||||
}
|
||||
|
||||
@@ -22,26 +22,18 @@ 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
|
||||
metadata *metav1.ObjectMeta
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -61,7 +53,7 @@ func (opts *DeleteSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) error {
|
||||
err := opts.client.MessageQueueTriggerDelete(opts.metadata)
|
||||
err := opts.Client().V1().MessageQueueTrigger().Delete(opts.metadata)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting message queue trigger")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
mqts, err := opts.client.MessageQueueTriggerList(input.String(flagkey.MqtMQType), opts.namespace)
|
||||
mqts, err := opts.Client().V1().MessageQueueTrigger().List(input.String(flagkey.MqtMQType), opts.namespace)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing message queue triggers")
|
||||
}
|
||||
|
||||
@@ -23,26 +23,18 @@ 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"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type UpdateSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
trigger *fv1.MessageQueueTrigger
|
||||
}
|
||||
|
||||
func Update(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := UpdateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
return (&UpdateSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
@@ -54,7 +46,7 @@ func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
mqt, err := opts.client.MessageQueueTriggerGet(&metav1.ObjectMeta{
|
||||
mqt, err := opts.Client().V1().MessageQueueTrigger().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.MqtName),
|
||||
Namespace: input.String(flagkey.NamespaceTrigger),
|
||||
})
|
||||
@@ -111,7 +103,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.client.MessageQueueTriggerUpdate(opts.trigger)
|
||||
_, err := opts.Client().V1().MessageQueueTrigger().Update(opts.trigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating message queue trigger")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user