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
@@ -65,7 +65,7 @@ func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
fnName := input.String(flagkey.FnName)
|
||||
|
||||
userProvidedNS, fnNamespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
userProvidedNS, fnNamespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error retrieving namespace information")
|
||||
}
|
||||
@@ -81,13 +81,10 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
if !toSpec {
|
||||
// check for unique function names within a namespace
|
||||
fn, err := opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: fnNamespace,
|
||||
})
|
||||
if err != nil && !ferror.IsNotFound(err) {
|
||||
fn, err := opts.Client().FissionClientSet.CoreV1().Functions(fnNamespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
if err != nil && !k8serrors.IsNotFound(err) {
|
||||
return err
|
||||
} else if fn != nil {
|
||||
} else if fn.Name != "" && fn.Namespace != "" {
|
||||
return errors.New("a function with the same name already exists")
|
||||
}
|
||||
}
|
||||
@@ -155,10 +152,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
pkgMetadata = &pkg.ObjectMeta
|
||||
} else {
|
||||
// use existing package
|
||||
pkg, err = opts.Client().V1().Package().Get(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: pkgName,
|
||||
})
|
||||
pkg, err = opts.Client().FissionClientSet.CoreV1().Packages(fnNamespace).Get(input.Context(), pkgName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("read package in '%s' in Namespace: %s. Package needs to be present in the same namespace as function", pkgName, fnNamespace))
|
||||
}
|
||||
@@ -196,10 +190,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
fnName, envName))
|
||||
}
|
||||
} else {
|
||||
_, err := opts.Client().V1().Environment().Get(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: envName,
|
||||
})
|
||||
_, err := opts.Client().FissionClientSet.CoreV1().Environments(fnNamespace).Get(input.Context(), envName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNotFound {
|
||||
console.Warn(fmt.Sprintf("Environment \"%s\" does not exist. Please create the environment before executing the function. \nFor example: `fission env create --name %s --envns %s --image <image>`\n", envName, envName, fnNamespace))
|
||||
@@ -246,10 +237,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
// check the referenced secret is in the same ns as the function, if not give a warning.
|
||||
if !toSpec { // TODO: workaround in order not to block users from creating function spec, remove it.
|
||||
for _, secretName := range secretNames {
|
||||
err := opts.Client().V1().Misc().SecretExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: secretName,
|
||||
})
|
||||
err := util.SecretExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: secretName}, opts.Client().KubernetesClient)
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
@@ -279,10 +267,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
// check the referenced cfgmap is in the same ns as the function, if not give a warning.
|
||||
if !toSpec {
|
||||
for _, cfgMapName := range cfgMapNames {
|
||||
err := opts.Client().V1().Misc().ConfigMapExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: cfgMapName,
|
||||
})
|
||||
err := util.ConfigMapExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: cfgMapName}, opts.Client().KubernetesClient)
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
||||
@@ -385,7 +370,7 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := opts.Client().V1().Function().Create(opts.function)
|
||||
_, err := opts.Client().FissionClientSet.CoreV1().Functions(opts.function.ObjectMeta.Namespace).Create(input.Context(), opts.function, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating function")
|
||||
}
|
||||
@@ -434,7 +419,7 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = opts.Client().V1().HTTPTrigger().Create(ht)
|
||||
_, err = opts.Client().FissionClientSet.CoreV1().HTTPTriggers(opts.function.ObjectMeta.Namespace).Create(input.Context(), ht, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating HTTP trigger")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func Delete(input cli.Input) error {
|
||||
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
Namespace: namespace,
|
||||
}
|
||||
|
||||
err = opts.Client().V1().Function().Delete(m)
|
||||
err = opts.Client().FissionClientSet.CoreV1().Functions(namespace).Delete(input.Context(), input.String(flagkey.FnName), metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
|
||||
return nil
|
||||
|
||||
@@ -25,7 +25,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 {
|
||||
@@ -37,22 +36,16 @@ func Get(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in get function ")
|
||||
}
|
||||
fn, err := opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: namespace,
|
||||
})
|
||||
fn, err := opts.Client().FissionClientSet.CoreV1().Functions(namespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function")
|
||||
}
|
||||
|
||||
pkg, err := opts.Client().V1().Package().Get(&metav1.ObjectMeta{
|
||||
Name: fn.Spec.Package.PackageRef.Name,
|
||||
Namespace: fn.Spec.Package.PackageRef.Namespace,
|
||||
})
|
||||
pkg, err := opts.Client().FissionClientSet.CoreV1().Packages(fn.Spec.Package.PackageRef.Namespace).Get(input.Context(), fn.Spec.Package.PackageRef.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting package")
|
||||
}
|
||||
|
||||
@@ -25,7 +25,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 GetMetaSubCommand struct {
|
||||
@@ -37,15 +36,12 @@ func GetMeta(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *GetMetaSubCommand) do(input cli.Input) error {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in getting meta function ")
|
||||
}
|
||||
|
||||
fn, err := opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: namespace,
|
||||
})
|
||||
fn, err := opts.Client().FissionClientSet.CoreV1().Functions(namespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function")
|
||||
}
|
||||
|
||||
@@ -23,12 +23,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 {
|
||||
@@ -40,17 +39,16 @@ func List(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in listing function ")
|
||||
}
|
||||
|
||||
var fns []v1.Function
|
||||
if input.Bool(flagkey.AllNamespaces) {
|
||||
fns, err = opts.Client().V1().Function().List("")
|
||||
} else {
|
||||
fns, err = opts.Client().V1().Function().List(namespace)
|
||||
namespace = metav1.NamespaceAll
|
||||
}
|
||||
fns, err := opts.Client().FissionClientSet.CoreV1().Functions(namespace).List(input.Context(), metav1.ListOptions{})
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing functions")
|
||||
}
|
||||
@@ -58,7 +56,7 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
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\t%v\t%v\t%v\n", "NAME", "ENV", "EXECUTORTYPE", "MINSCALE", "MAXSCALE", "MINCPU", "MAXCPU", "MINMEMORY", "MAXMEMORY", "SECRETS", "CONFIGMAPS", "NAMESPACE")
|
||||
for _, f := range fns {
|
||||
for _, f := range fns.Items {
|
||||
secrets := f.Spec.Secrets
|
||||
configMaps := f.Spec.ConfigMaps
|
||||
var secretsList, configMapList []string
|
||||
|
||||
@@ -40,14 +40,13 @@ func Log(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *LogSubCommand) do(input cli.Input) error {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in logs for function ")
|
||||
}
|
||||
|
||||
dbType := input.String(flagkey.FnLogDBType)
|
||||
fnPod := input.String(flagkey.FnLogPod)
|
||||
kubeContext := input.String(flagkey.KubeContext)
|
||||
|
||||
logReverseQuery := !input.Bool(flagkey.FnLogFollow) && input.Bool(flagkey.FnLogReverseQuery)
|
||||
|
||||
@@ -56,15 +55,12 @@ func (opts *LogSubCommand) do(input cli.Input) error {
|
||||
recordLimit = 1000
|
||||
}
|
||||
|
||||
f, err := opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: namespace,
|
||||
})
|
||||
f, err := opts.Client().FissionClientSet.CoreV1().Functions(namespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function")
|
||||
}
|
||||
|
||||
server, err := util.GetApplicationUrl(input.Context(), "application=fission-api", kubeContext)
|
||||
server, err := util.GetApplicationUrl(input.Context(), opts.Client(), "application=fission-api")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
||||
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"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -42,35 +42,34 @@ func ListPods(input cli.Input) error {
|
||||
|
||||
func (opts *ListPodsSubCommand) do(input cli.Input) error {
|
||||
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in finding pod for function ")
|
||||
}
|
||||
// validate function
|
||||
_, err = opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: namespace,
|
||||
})
|
||||
_, err = opts.Client().FissionClientSet.CoreV1().Functions(namespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function")
|
||||
}
|
||||
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Labels: map[string]string{
|
||||
v1.FUNCTION_NAMESPACE: namespace,
|
||||
},
|
||||
selector := map[string]string{
|
||||
v1.FUNCTION_NAME: input.String(flagkey.FnName),
|
||||
}
|
||||
if len(namespace) != 0 {
|
||||
selector[v1.FUNCTION_NAMESPACE] = namespace
|
||||
}
|
||||
|
||||
pods, err := opts.Client().V1().Function().ListPods(m)
|
||||
pods, err := opts.Client().KubernetesClient.CoreV1().Pods(metav1.NamespaceAll).List(input.Context(), metav1.ListOptions{
|
||||
LabelSelector: labels.Set(selector).AsSelector().String(),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing environments")
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t\n", "NAME", "NAMESPACE", "READY", "STATUS", "IP", "EXECUTORTYPE", "MANAGED")
|
||||
for _, pod := range pods {
|
||||
for _, pod := range pods.Items {
|
||||
|
||||
// A deletion timestamp indicates that a pod is terminating. Do not count this pod.
|
||||
if pod.ObjectMeta.DeletionTimestamp != nil {
|
||||
|
||||
@@ -22,11 +22,10 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"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"
|
||||
@@ -56,7 +55,7 @@ func (opts *RunContainerSubCommand) do(input cli.Input) error {
|
||||
func (opts *RunContainerSubCommand) complete(input cli.Input) error {
|
||||
fnName := input.String(flagkey.FnName)
|
||||
|
||||
_, fnNamespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, fnNamespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in running container for function ")
|
||||
}
|
||||
@@ -70,13 +69,11 @@ func (opts *RunContainerSubCommand) complete(input cli.Input) error {
|
||||
|
||||
if !toSpec {
|
||||
// check for unique function names within a namespace
|
||||
fn, err := opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: fnNamespace,
|
||||
})
|
||||
if err != nil && !ferror.IsNotFound(err) {
|
||||
fn, err := opts.Client().FissionClientSet.CoreV1().Functions(fnNamespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
|
||||
if err != nil && !kerrors.IsNotFound(err) {
|
||||
return err
|
||||
} else if fn != nil {
|
||||
} else if fn.Name != "" && fn.Namespace != "" {
|
||||
return errors.New("a function with the same name already exists")
|
||||
}
|
||||
}
|
||||
@@ -128,12 +125,9 @@ func (opts *RunContainerSubCommand) complete(input cli.Input) error {
|
||||
// check the referenced secret is in the same ns as the function, if not give a warning.
|
||||
if !toSpec { // TODO: workaround in order not to block users from creating function spec, remove it.
|
||||
for _, secretName := range secretNames {
|
||||
err := opts.Client().V1().Misc().SecretExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: secretName,
|
||||
})
|
||||
err := util.SecretExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: secretName}, opts.Client().KubernetesClient)
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
if kerrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
} else {
|
||||
return errors.Wrapf(err, "error checking secret %s", secretName)
|
||||
@@ -154,12 +148,10 @@ func (opts *RunContainerSubCommand) complete(input cli.Input) error {
|
||||
// check the referenced cfgmap is in the same ns as the function, if not give a warning.
|
||||
if !toSpec {
|
||||
for _, cfgMapName := range cfgMapNames {
|
||||
err := opts.Client().V1().Misc().ConfigMapExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: cfgMapName,
|
||||
})
|
||||
err := util.ConfigMapExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: cfgMapName}, opts.Client().KubernetesClient)
|
||||
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
if kerrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
||||
} else {
|
||||
return errors.Wrapf(err, "error checking configmap %s", cfgMapName)
|
||||
@@ -238,7 +230,7 @@ func (opts *RunContainerSubCommand) run(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := opts.Client().V1().Function().Create(opts.function)
|
||||
_, err := opts.Client().FissionClientSet.CoreV1().Functions(opts.function.ObjectMeta.Namespace).Create(input.Context(), opts.function, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating function")
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
"go.opentelemetry.io/otel"
|
||||
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"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/httptrigger"
|
||||
@@ -52,7 +51,7 @@ func Test(input cli.Input) error {
|
||||
|
||||
func (opts *TestSubCommand) do(input cli.Input) error {
|
||||
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, namespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in testing function ")
|
||||
}
|
||||
@@ -61,14 +60,13 @@ func (opts *TestSubCommand) do(input cli.Input) error {
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: namespace,
|
||||
}
|
||||
kubeContext := input.String(flagkey.KubeContext)
|
||||
routerURL := os.Getenv("FISSION_ROUTER")
|
||||
if len(routerURL) != 0 {
|
||||
console.Warn("The environment variable FISSION_ROUTER is no longer supported for this command")
|
||||
}
|
||||
|
||||
// Portforward to the fission router
|
||||
localRouterPort, err := util.SetupPortForward(input.Context(), util.GetFissionNamespace(), "application=fission-router", kubeContext)
|
||||
localRouterPort, err := util.SetupPortForward(input.Context(), opts.Client(), util.GetFissionNamespace(), "application=fission-router")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -150,15 +148,13 @@ func (opts *TestSubCommand) do(input cli.Input) error {
|
||||
}
|
||||
|
||||
console.Errorf("Error calling function %s: %d; Please try again or fix the error: %s\n", m.Name, resp.StatusCode, string(body))
|
||||
log, err := printPodLogs(opts.Client(), m)
|
||||
err = printPodLogs(input.Context(), opts.Client(), m)
|
||||
if err != nil {
|
||||
console.Errorf("Error getting function logs from controller: %v. Try to get logs from log database.", err)
|
||||
err = Log(input)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error retrieving function log from log database")
|
||||
}
|
||||
} else {
|
||||
console.Info(log)
|
||||
}
|
||||
return errors.New("error getting function response")
|
||||
}
|
||||
@@ -224,21 +220,12 @@ func doHTTPRequest(ctx context.Context, url string, headers []string, method, bo
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func printPodLogs(client client.Interface, fnMeta *metav1.ObjectMeta) (string, error) {
|
||||
reader, statusCode, err := client.V1().Misc().PodLogs(fnMeta)
|
||||
func printPodLogs(ctx context.Context, client cmd.Client, fnMeta *metav1.ObjectMeta) error {
|
||||
err := util.FunctionPodLogs(ctx, fnMeta.Name, fnMeta.Namespace, client)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error executing get logs request")
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
body, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error reading the response body")
|
||||
return errors.Wrap(err, "error executing get logs request")
|
||||
}
|
||||
|
||||
if statusCode != http.StatusOK {
|
||||
return string(body), errors.Errorf("error getting logs from controller, status code: '%v'", statusCode)
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -51,15 +51,12 @@ func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
fnName := input.String(flagkey.FnName)
|
||||
_, fnNamespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, fnNamespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in updating function ")
|
||||
}
|
||||
|
||||
function, err := opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: fnNamespace,
|
||||
})
|
||||
function, err := opts.Client().FissionClientSet.CoreV1().Functions(fnNamespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("read function '%v'", fnName))
|
||||
}
|
||||
@@ -90,10 +87,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
// check that the referenced secret is in the same ns as the function, if not give a warning.
|
||||
for _, secretName := range secretNames {
|
||||
err := opts.Client().V1().Misc().SecretExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: secretName,
|
||||
})
|
||||
err := util.SecretExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: secretName}, opts.Client().KubernetesClient)
|
||||
if k8serrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
}
|
||||
@@ -114,10 +108,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
// check that the referenced cfgmap is in the same ns as the function, if not give a warning.
|
||||
for _, cfgMapName := range cfgMapNames {
|
||||
err := opts.Client().V1().Misc().ConfigMapExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: cfgMapName,
|
||||
})
|
||||
err := util.ConfigMapExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: cfgMapName}, opts.Client().KubernetesClient)
|
||||
if k8serrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as the function", cfgMapName, fnNamespace))
|
||||
}
|
||||
@@ -186,17 +177,14 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
function.Spec.Resources = *resReqs
|
||||
|
||||
pkg, err := opts.Client().V1().Package().Get(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: pkgName,
|
||||
})
|
||||
pkg, err := opts.Client().FissionClientSet.CoreV1().Packages(fnNamespace).Get(input.Context(), pkgName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("read package '%v.%v'. Pkg should be present in the same ns as the function", pkgName, fnNamespace))
|
||||
}
|
||||
|
||||
forceUpdate := input.Bool(flagkey.PkgForce)
|
||||
|
||||
fnList, err := _package.GetFunctionsByPackage(opts.Client(), pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace)
|
||||
fnList, err := _package.GetFunctionsByPackage(input.Context(), opts.Client(), pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting function list")
|
||||
}
|
||||
@@ -222,7 +210,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
fns = append(fns, fn)
|
||||
}
|
||||
}
|
||||
err = _package.UpdateFunctionPackageResourceVersion(opts.Client(), newPkgMeta, fns...)
|
||||
err = _package.UpdateFunctionPackageResourceVersion(input.Context(), opts.Client(), newPkgMeta, fns...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating function package reference resource version")
|
||||
}
|
||||
@@ -255,7 +243,7 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.Client().V1().Function().Update(opts.function)
|
||||
_, err := opts.Client().FissionClientSet.CoreV1().Functions(opts.function.Namespace).Update(input.Context(), opts.function, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating function")
|
||||
}
|
||||
|
||||
@@ -53,15 +53,13 @@ func (opts *UpdateContainerSubCommand) do(input cli.Input) error {
|
||||
func (opts *UpdateContainerSubCommand) complete(input cli.Input) error {
|
||||
fnName := input.String(flagkey.FnName)
|
||||
|
||||
_, fnNamespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
_, fnNamespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in updating container for function ")
|
||||
}
|
||||
|
||||
function, err := opts.Client().V1().Function().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.FnName),
|
||||
Namespace: fnNamespace,
|
||||
})
|
||||
function, err := opts.Client().FissionClientSet.CoreV1().Functions(fnNamespace).Get(input.Context(), input.String(flagkey.FnName), metav1.GetOptions{})
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("read function '%v'", fnName))
|
||||
}
|
||||
@@ -84,10 +82,7 @@ func (opts *UpdateContainerSubCommand) complete(input cli.Input) error {
|
||||
|
||||
// check that the referenced secret is in the same ns as the function, if not give a warning.
|
||||
for _, secretName := range secretNames {
|
||||
err := opts.Client().V1().Misc().SecretExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: secretName,
|
||||
})
|
||||
err := util.SecretExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: secretName}, opts.Client().KubernetesClient)
|
||||
if k8serrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
}
|
||||
@@ -108,10 +103,7 @@ func (opts *UpdateContainerSubCommand) complete(input cli.Input) error {
|
||||
|
||||
// check that the referenced cfgmap is in the same ns as the function, if not give a warning.
|
||||
for _, cfgMapName := range cfgMapNames {
|
||||
err := opts.Client().V1().Misc().ConfigMapExists(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: cfgMapName,
|
||||
})
|
||||
err := util.ConfigMapExists(input.Context(), &metav1.ObjectMeta{Namespace: fnNamespace, Name: cfgMapName}, opts.Client().KubernetesClient)
|
||||
if k8serrors.IsNotFound(err) {
|
||||
console.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as the function", cfgMapName, fnNamespace))
|
||||
}
|
||||
@@ -192,7 +184,7 @@ func (opts *UpdateContainerSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *UpdateContainerSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.Client().V1().Function().Update(opts.function)
|
||||
_, err := opts.Client().FissionClientSet.CoreV1().Functions(opts.function.Namespace).Update(input.Context(), opts.function, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating function")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user