Skip to content

Commit 3602036

Browse files
Add server endpoint to list applications (#379)
Will be used for cloud shell installer health indicators, and maybe local installer
1 parent 2a0bd3f commit 3602036

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

pkg/application/waiter.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ const (
1616
waitTime = 5 * 60 * time.Second
1717
)
1818

19+
func ListAll(kubeConf *rest.Config) ([]v1beta1.Application, error) {
20+
apps, err := NewForConfig(kubeConf)
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
client := apps.Applications("")
26+
l, err := client.List(context.Background(), metav1.ListOptions{})
27+
if err != nil {
28+
return nil, err
29+
}
30+
31+
return l.Items, nil
32+
}
33+
1934
func Waiter(kubeConf *rest.Config, repo string, appFunc func(app *v1beta1.Application) (bool, error), timeout func() error) error {
2035
conf := config.Read()
2136
ctx := context.Background()

pkg/server/applications.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package server
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gin-gonic/gin"
7+
"github.com/pluralsh/plural/pkg/application"
8+
"github.com/pluralsh/plural/pkg/kubernetes"
9+
)
10+
11+
func listApplications(c *gin.Context) error {
12+
kubeConf, err := kubernetes.KubeConfig()
13+
if err != nil {
14+
return err
15+
}
16+
17+
apps, err := application.ListAll(kubeConf)
18+
if err != nil {
19+
return err
20+
}
21+
22+
c.Header("Content-Type", "application/json")
23+
c.JSON(http.StatusOK, apps)
24+
return nil
25+
}

pkg/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func SetUpRouter() *gin.Engine {
2020
v1.POST("/setup", serverFunc(setupCli))
2121
v1.GET("/health", healthcheck)
2222
v1.GET("/configuration", serverFunc(configuration))
23+
v1.GET("/applications", serverFunc(listApplications))
2324
v1.POST("/context/configuration", serverFunc(contextConfiguration))
2425
}
2526
return r

0 commit comments

Comments
 (0)