Use Kubernetes Client instead of Controller APIs from CLI (#2605)
Use the Kubernetes and Fission Client from CLI instead of Controller API. This removes port-forwarding for the controller across Fission CLI mostly. * Use configurable client in CLI * Move resource namespace under cmd client * use server to get fission version * get archive with URL Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> Co-authored-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
co-authored by
Sanket Sudake
parent
261bf24974
commit
b71a36dc1c
@@ -54,7 +54,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) (err error) {
|
||||
ht := input.String(flagkey.CanaryHTTPTriggerName)
|
||||
newFunc := input.String(flagkey.CanaryNewFunc)
|
||||
oldFunc := input.String(flagkey.CanaryOldFunc)
|
||||
_, fnNs, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
|
||||
_, fnNs, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in creating canaryconfig")
|
||||
}
|
||||
@@ -69,10 +70,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) (err error) {
|
||||
}
|
||||
|
||||
// check that the trigger exists in the same namespace.
|
||||
htTrigger, err := opts.Client().V1().HTTPTrigger().Get(&metav1.ObjectMeta{
|
||||
Name: ht,
|
||||
Namespace: fnNs,
|
||||
})
|
||||
htTrigger, err := opts.Client().FissionClientSet.CoreV1().HTTPTriggers(fnNs).Get(input.Context(), ht, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error finding http trigger referenced in the canary config")
|
||||
}
|
||||
@@ -95,7 +93,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) (err error) {
|
||||
|
||||
// check that the functions exist in the same namespace
|
||||
fnList := []string{newFunc, oldFunc}
|
||||
err = util.CheckFunctionExistence(opts.Client(), fnList, fnNs)
|
||||
err = util.CheckFunctionExistence(input.Context(), opts.Client(), fnList, fnNs)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error checking functions existence")
|
||||
}
|
||||
@@ -124,7 +122,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) (err error) {
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.Client().V1().CanaryConfig().Create(opts.canary)
|
||||
_, err := opts.Client().FissionClientSet.CoreV1().CanaryConfigs(opts.canary.ObjectMeta.Namespace).Create(input.Context(), opts.canary, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating canary config")
|
||||
}
|
||||
|
||||
@@ -37,16 +37,12 @@ func Delete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) (err error) {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting canaryConfig ")
|
||||
}
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.CanaryName),
|
||||
Namespace: namespace,
|
||||
}
|
||||
|
||||
err = opts.Client().V1().CanaryConfig().Delete(m)
|
||||
err = opts.Client().FissionClientSet.CoreV1().CanaryConfigs(namespace).Delete(input.Context(), input.String(flagkey.CanaryName), metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
|
||||
return nil
|
||||
@@ -54,6 +50,6 @@ func (opts *DeleteSubCommand) run(input cli.Input) (err error) {
|
||||
return errors.Wrap(err, "error deleting canary config")
|
||||
}
|
||||
|
||||
fmt.Printf("canaryconfig '%v.%v' deleted\n", m.Name, m.Namespace)
|
||||
fmt.Printf("canaryconfig '%v.%v' deleted\n", input.String(flagkey.CanaryName), namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"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 {
|
||||
@@ -40,15 +39,12 @@ func Get(input cli.Input) error {
|
||||
|
||||
func (opts *GetSubCommand) run(input cli.Input) (err error) {
|
||||
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting canary config")
|
||||
}
|
||||
|
||||
canaryCfg, err := opts.Client().V1().CanaryConfig().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.CanaryName),
|
||||
Namespace: namespace,
|
||||
})
|
||||
canaryCfg, err := opts.Client().FissionClientSet.CoreV1().CanaryConfigs(namespace).Get(input.Context(), input.String(flagkey.CanaryName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting canary config")
|
||||
}
|
||||
|
||||
@@ -22,12 +22,11 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
v1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"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 {
|
||||
@@ -48,7 +47,7 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) complete(input cli.Input) (err error) {
|
||||
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
_, opts.namespace, err = opts.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in listing canary config ")
|
||||
}
|
||||
@@ -57,19 +56,18 @@ func (opts *ListSubCommand) complete(input cli.Input) (err error) {
|
||||
|
||||
func (opts *ListSubCommand) run(input cli.Input) (err error) {
|
||||
|
||||
var canaryCfgs []v1.CanaryConfig
|
||||
if input.Bool(flagkey.AllNamespaces) {
|
||||
canaryCfgs, err = opts.Client().V1().CanaryConfig().List("")
|
||||
} else {
|
||||
canaryCfgs, err = opts.Client().V1().CanaryConfig().List(opts.namespace)
|
||||
opts.namespace = metav1.NamespaceAll
|
||||
}
|
||||
canaryCfgs, err := opts.Client().FissionClientSet.CoreV1().CanaryConfigs(opts.namespace).List(input.Context(), metav1.ListOptions{})
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing canary config")
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "TRIGGER", "FUNCTION-N", "FUNCTION-N-1", "WEIGHT-INCREMENT", "INTERVAL", "FAILURE-THRESHOLD", "FAILURE-TYPE", "STATUS")
|
||||
for _, canaryCfg := range canaryCfgs {
|
||||
for _, canaryCfg := range canaryCfgs.Items {
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
canaryCfg.ObjectMeta.Name, canaryCfg.Spec.Trigger, canaryCfg.Spec.NewFunction, canaryCfg.Spec.OldFunction, canaryCfg.Spec.WeightIncrement, canaryCfg.Spec.WeightIncrementDuration,
|
||||
canaryCfg.Spec.FailureThreshold, canaryCfg.Spec.FailureType, canaryCfg.Status.Status)
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"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 {
|
||||
@@ -49,8 +48,7 @@ func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) (err error) {
|
||||
// get the current config
|
||||
name := input.String(flagkey.CanaryName)
|
||||
_, ns, err := util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
_, ns, err := opts.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating canary config")
|
||||
}
|
||||
@@ -64,10 +62,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) (err error) {
|
||||
return errors.Wrap(err, "error parsing time duration")
|
||||
}
|
||||
|
||||
canaryCfg, err := opts.Client().V1().CanaryConfig().Get(&metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: ns,
|
||||
})
|
||||
canaryCfg, err := opts.Client().FissionClientSet.CoreV1().CanaryConfigs(ns).Get(input.Context(), input.String(flagkey.CanaryName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting canary config")
|
||||
}
|
||||
@@ -96,7 +91,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) (err error) {
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.Client().V1().CanaryConfig().Update(opts.canary)
|
||||
_, err := opts.Client().FissionClientSet.CoreV1().CanaryConfigs(opts.canary.ObjectMeta.Namespace).Update(input.Context(), opts.canary, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating canary config")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user