feat: Return more information from api/v1/org/:org/applications
@@ -2,9 +2,12 @@ package v1
import (
"encoding/json"
+ "fmt"
"net/http"
+ "github.com/fatih/color"
"github.com/julienschmidt/httprouter"
+ "github.com/suse/carrier/deployments"
"github.com/suse/carrier/internal/application"
"github.com/suse/carrier/internal/cli/clients"
)
@@ -31,7 +34,41 @@ func (hc ApplicationsController) Index(w http.ResponseWriter, r *http.Request) {
return
}
- js, err := json.Marshal(apps)
+ result := []map[string]interface{}{}
+ for _, app := range apps {
+ status, err := client.KubeClient.DeploymentStatus(
+ deployments.WorkloadsDeploymentID,
+ fmt.Sprintf("app.kubernetes.io/part-of=%s,app.kubernetes.io/name=%s",
+ org, app.Name))
+ if handleError(w, err, 500) {
+ return
+ }
+
+ routes, err := client.KubeClient.ListIngressRoutes(
+ deployments.WorkloadsDeploymentID,
+ app.Name)
+ if err != nil {
+ routes = []string{err.Error()}
+ }
+
+ var bonded = []string{}
+ bound, err := app.Services()
+ if err != nil {
+ bonded = append(bonded, color.RedString(err.Error()))
+ } else {
+ for _, service := range bound {
+ bonded = append(bonded, service.Name())
+ }
+ }
+ result = append(result, map[string]interface{}{
+ "name": app.Name,
+ "status": status,
+ "routes": routes,
+ "services": bonded,
+ })
+ }
+
+ js, err := json.Marshal(result)
if handleError(w, err, 500) {
return
}
