feature: Added command to list pods managed by fission for environment/function (#2207)
This commit is contained in:
@@ -19,12 +19,13 @@ package v1
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client/rest"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/controller/client/rest"
|
||||
"github.com/fission/fission/pkg/generator/encoder"
|
||||
v1generator "github.com/fission/fission/pkg/generator/v1"
|
||||
)
|
||||
@@ -40,6 +41,7 @@ type (
|
||||
Update(env *fv1.Environment) (*metav1.ObjectMeta, error)
|
||||
Delete(m *metav1.ObjectMeta) error
|
||||
List(ns string) ([]fv1.Environment, error)
|
||||
ListPods(m *metav1.ObjectMeta) ([]apiv1.Pod, error)
|
||||
}
|
||||
|
||||
Environment struct {
|
||||
@@ -163,3 +165,38 @@ func (c *Environment) List(ns string) ([]fv1.Environment, error) {
|
||||
|
||||
return envs, nil
|
||||
}
|
||||
|
||||
func (c *Environment) ListPods(m *metav1.ObjectMeta) ([]apiv1.Pod, error) {
|
||||
relativeUrl := fmt.Sprintf("environments/%s/pods", m.Name)
|
||||
|
||||
values := url.Values{}
|
||||
if len(m.Labels) != 0 {
|
||||
if envns, ok := m.Labels[fv1.ENVIRONMENT_NAMESPACE]; ok && len(envns) != 0 {
|
||||
values.Add(fv1.ENVIRONMENT_NAMESPACE, envns)
|
||||
|
||||
}
|
||||
if extype, ok := m.Labels[fv1.EXECUTOR_TYPE]; ok && len(extype) != 0 {
|
||||
values.Add(fv1.EXECUTOR_TYPE, extype)
|
||||
}
|
||||
}
|
||||
|
||||
relativeUrl = fmt.Sprintf("%s?%s", relativeUrl, values.Encode())
|
||||
resp, err := c.client.Get(relativeUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := handleResponse(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pods := make([]apiv1.Pod, 0)
|
||||
err = json.Unmarshal(body, &pods)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pods, nil
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package fake
|
||||
|
||||
import (
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
@@ -50,3 +51,7 @@ func (c *FakeEnvironment) Delete(m *metav1.ObjectMeta) error {
|
||||
func (c *FakeEnvironment) List(ns string) ([]fv1.Environment, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *FakeEnvironment) ListPods(m *metav1.ObjectMeta) ([]apiv1.Pod, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package fake
|
||||
|
||||
import (
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
@@ -54,3 +55,7 @@ func (c *FakeFunction) Delete(m *metav1.ObjectMeta) error {
|
||||
func (c *FakeFunction) List(functionNamespace string) ([]fv1.Function, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *FakeFunction) ListPods(m *metav1.ObjectMeta) ([]apiv1.Pod, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ package v1
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
@@ -38,6 +40,7 @@ type (
|
||||
Update(f *fv1.Function) (*metav1.ObjectMeta, error)
|
||||
Delete(m *metav1.ObjectMeta) error
|
||||
List(functionNamespace string) ([]fv1.Function, error)
|
||||
ListPods(m *metav1.ObjectMeta) ([]apiv1.Pod, error)
|
||||
}
|
||||
|
||||
Function struct {
|
||||
@@ -176,3 +179,34 @@ func (c *Function) List(functionNamespace string) ([]fv1.Function, error) {
|
||||
|
||||
return funcs, nil
|
||||
}
|
||||
|
||||
func (c *Function) ListPods(m *metav1.ObjectMeta) ([]apiv1.Pod, error) {
|
||||
relativeUrl := fmt.Sprintf("functions/%s/pods", m.Name)
|
||||
|
||||
values := url.Values{}
|
||||
if len(m.Labels) != 0 {
|
||||
if fns, ok := m.Labels[fv1.FUNCTION_NAMESPACE]; ok && len(fns) != 0 {
|
||||
values.Add(fv1.FUNCTION_NAMESPACE, fns)
|
||||
}
|
||||
}
|
||||
|
||||
relativeUrl = fmt.Sprintf("%s?%s", relativeUrl, values.Encode())
|
||||
resp, err := c.client.Get(relativeUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := handleResponse(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pods := make([]apiv1.Pod, 0)
|
||||
err = json.Unmarshal(body, &pods)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pods, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user