Procházet zdrojové kódy

Removed unused get job runs for all charts endpoint

jnfrati před 4 roky
rodič
revize
4dfdcd3920

+ 0 - 135
api/server/handlers/namespace/get_job_runs.go

@@ -1,135 +0,0 @@
-package namespace
-
-import (
-	"net/http"
-	"sort"
-	"strings"
-
-	"github.com/porter-dev/porter/api/server/authz"
-	"github.com/porter-dev/porter/api/server/handlers"
-	"github.com/porter-dev/porter/api/server/shared"
-	"github.com/porter-dev/porter/api/server/shared/apierrors"
-	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/types"
-	"github.com/porter-dev/porter/internal/models"
-	v1 "k8s.io/api/batch/v1"
-)
-
-type GetJobRunsHandler struct {
-	handlers.PorterHandlerReadWriter
-	authz.KubernetesAgentGetter
-}
-
-func NewGetJobRunsHandler(
-	config *config.Config,
-	decoderValidator shared.RequestDecoderValidator,
-	writer shared.ResultWriter,
-) *GetJobRunsHandler {
-	return &GetJobRunsHandler{
-		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
-		KubernetesAgentGetter:   authz.NewOutOfClusterAgentGetter(config),
-	}
-}
-
-func (c *GetJobRunsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	request := &types.GetJobRunsRequest{}
-
-	if ok := c.DecodeAndValidate(w, r, request); !ok {
-		return
-	}
-
-	namespace := r.Context().Value(types.NamespaceScope).(string)
-	cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
-
-	agent, err := c.GetAgent(r, cluster, "")
-
-	if err != nil {
-		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
-		return
-	}
-
-	allJobs, err := agent.ListAllJobs(namespace)
-
-	if err != nil {
-		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
-		return
-	}
-
-	var jobs []v1.Job
-
-	if strings.ToLower(request.Status) == "failed" {
-		for _, job := range allJobs {
-			if job.Status.Failed > 0 {
-				jobs = append(jobs, job)
-			}
-		}
-	} else if strings.ToLower(request.Status) == "succeeded" {
-		for _, job := range allJobs {
-			if job.Status.Succeeded > 0 {
-				jobs = append(jobs, job)
-			}
-		}
-	} else if strings.ToLower(request.Status) == "running" {
-		for _, job := range allJobs {
-			if job.Status.Active > 0 {
-				jobs = append(jobs, job)
-			}
-		}
-	} else {
-		// return all
-		jobs = append(jobs, allJobs...)
-	}
-
-	if strings.ToLower(request.Sort) == "oldest" {
-		sort.Sort(sortByOldest(jobs))
-	} else if strings.ToLower(request.Sort) == "alphabetical" {
-		sort.Sort(sortByAlphabetical(jobs))
-	} else {
-		// sort by newest
-		sort.Sort(sortByNewest(jobs))
-	}
-
-	c.WriteResult(w, r, jobs)
-}
-
-type sortByNewest []v1.Job
-
-func (s sortByNewest) Len() int {
-	return len(s)
-}
-
-func (s sortByNewest) Swap(i, j int) {
-	s[i], s[j] = s[j], s[i]
-}
-
-func (s sortByNewest) Less(i, j int) bool {
-	return s[i].CreationTimestamp.Unix() > s[j].CreationTimestamp.Unix()
-}
-
-type sortByOldest []v1.Job
-
-func (s sortByOldest) Len() int {
-	return len(s)
-}
-
-func (s sortByOldest) Swap(i, j int) {
-	s[i], s[j] = s[j], s[i]
-}
-
-func (s sortByOldest) Less(i, j int) bool {
-	return s[i].CreationTimestamp.Unix() < s[j].CreationTimestamp.Unix()
-}
-
-type sortByAlphabetical []v1.Job
-
-func (s sortByAlphabetical) Len() int {
-	return len(s)
-}
-
-func (s sortByAlphabetical) Swap(i, j int) {
-	s[i], s[j] = s[j], s[i]
-}
-
-func (s sortByAlphabetical) Less(i, j int) bool {
-	return s[i].Name < s[j].Name
-}

+ 0 - 31
api/server/router/namespace.go

@@ -743,36 +743,5 @@ func getNamespaceRoutes(
 		Router:   r,
 	})
 
-	// GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/job_runs ->
-	// namespace.NewGetJobRunsHandler
-	getJobRunsEndpoint := factory.NewAPIEndpoint(
-		&types.APIRequestMetadata{
-			Verb:   types.APIVerbGet,
-			Method: types.HTTPVerbGet,
-			Path: &types.Path{
-				Parent:       basePath,
-				RelativePath: relPath + "/job_runs",
-			},
-			Scopes: []types.PermissionScope{
-				types.UserScope,
-				types.ProjectScope,
-				types.ClusterScope,
-				types.NamespaceScope,
-			},
-		},
-	)
-
-	getJobRunsHandler := namespace.NewGetJobRunsHandler(
-		config,
-		factory.GetDecoderValidator(),
-		factory.GetResultWriter(),
-	)
-
-	routes = append(routes, &Route{
-		Endpoint: getJobRunsEndpoint,
-		Handler:  getJobRunsHandler,
-		Router:   r,
-	})
-
 	return routes, newPath
 }

+ 0 - 14
dashboard/src/shared/api.tsx

@@ -752,19 +752,6 @@ const getJobPods = baseApi<
   return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}/pods`;
 });
 
-// GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/job_runs?status={failed|completed|running|all}&sort={newest|oldest|alphabetical}
-const getJobRunsForAllCharts = baseApi<
-  {
-    status: "failed" | "completed" | "running" | "all";
-    sort: "newest" | "oldest" | "alphabetical";
-  },
-  { namespace: string; cluster_id: number; project_id: number }
->(
-  "GET",
-  ({ cluster_id, project_id, namespace }) =>
-    `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/job_runs`
-);
-
 const getPodByName = baseApi<
   {},
   {
@@ -1553,7 +1540,6 @@ export default {
   getJobs,
   getJobStatus,
   getJobPods,
-  getJobRunsForAllCharts,
   getPodByName,
   getMatchingPods,
   getMetrics,

+ 0 - 13
internal/kubernetes/agent.go

@@ -689,19 +689,6 @@ func (a *Agent) ListJobsByLabel(namespace string, labels ...Label) ([]batchv1.Jo
 	return resp.Items, nil
 }
 
-func (a *Agent) ListAllJobs(namespace string) ([]batchv1.Job, error) {
-	resp, err := a.Clientset.BatchV1().Jobs(namespace).List(
-		context.TODO(),
-		metav1.ListOptions{},
-	)
-
-	if err != nil {
-		return nil, err
-	}
-
-	return resp.Items, nil
-}
-
 // StreamJobs streams a list of jobs to the websocket writer, closing the connection once all jobs have been sent
 func (a *Agent) StreamJobs(namespace string, selectors string, rw *websocket.WebsocketSafeReadWriter) error {
 	run := func() error {