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
|
||||
env *fv1.Environment
|
||||
cmd.CommandActioner
|
||||
env *fv1.Environment
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -72,7 +65,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
m := opts.env.Metadata
|
||||
|
||||
envList, err := opts.client.EnvironmentList(m.Namespace)
|
||||
envList, err := opts.Client().V1().Environment().List(m.Namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if len(envList) > 0 {
|
||||
@@ -92,7 +85,7 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = opts.client.EnvironmentCreate(opts.env)
|
||||
_, err = opts.Client().V1().Environment().Create(opts.env)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating environment")
|
||||
}
|
||||
|
||||
@@ -22,25 +22,17 @@ 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
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -49,7 +41,7 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
Namespace: input.String(flagkey.NamespaceEnvironment),
|
||||
}
|
||||
|
||||
err := opts.client.EnvironmentDelete(m)
|
||||
err := opts.Client().V1().Environment().Delete(m)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting environment")
|
||||
}
|
||||
|
||||
@@ -24,25 +24,17 @@ 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 GetSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
}
|
||||
|
||||
func Get(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
return (&GetSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
@@ -51,7 +43,7 @@ func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
Namespace: input.String(flagkey.NamespaceEnvironment),
|
||||
}
|
||||
|
||||
env, err := opts.client.EnvironmentGet(m)
|
||||
env, err := opts.Client().V1().Environment().Get(m)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting environment")
|
||||
}
|
||||
|
||||
@@ -23,29 +23,21 @@ 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
|
||||
}
|
||||
|
||||
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 {
|
||||
envs, err := opts.client.EnvironmentList(input.String(flagkey.NamespaceEnvironment))
|
||||
envs, err := opts.Client().V1().Environment().List(input.String(flagkey.NamespaceEnvironment))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing environments")
|
||||
}
|
||||
|
||||
@@ -24,27 +24,19 @@ 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"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
type UpdateSubCommand struct {
|
||||
client *client.Client
|
||||
env *fv1.Environment
|
||||
cmd.CommandActioner
|
||||
env *fv1.Environment
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -56,7 +48,7 @@ func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
env, err := opts.client.EnvironmentGet(&metav1.ObjectMeta{
|
||||
env, err := opts.Client().V1().Environment().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.EnvName),
|
||||
Namespace: input.String(flagkey.NamespaceEnvironment),
|
||||
})
|
||||
@@ -74,7 +66,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.client.EnvironmentUpdate(opts.env)
|
||||
_, err := opts.Client().V1().Environment().Update(opts.env)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating environment")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user