Skip to content

Commit

Permalink
/app/status API that returns detailed app status
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Dec 19, 2024
1 parent eeb5cac commit 9d92e9e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func Start(params APIServerParams) {

// app
r.HandleFunc("/api/v1/app/info", handlers.GetCurrentAppInfo).Methods("GET")
r.HandleFunc("/api/v1/app/status", handlers.GetCurrentAppStatus).Methods("GET")
r.HandleFunc("/api/v1/app/updates", handlers.GetAppUpdates).Methods("GET")
r.HandleFunc("/api/v1/app/history", handlers.GetAppHistory).Methods("GET")
cachedRouter.HandleFunc("/api/v1/app/custom-metrics", handlers.SendCustomAppMetrics).Methods("POST", "PATCH")
Expand Down
43 changes: 43 additions & 0 deletions pkg/handlers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type GetCurrentAppInfoResponse struct {
ReleaseSequence int64 `json:"releaseSequence"`
}

type GetCurrentAppStatusResponse struct {
AppStatus appstatetypes.AppStatus `json:"appStatus"`
}

type GetAppHistoryResponse struct {
Releases []AppRelease `json:"releases"`
}
Expand Down Expand Up @@ -149,6 +153,45 @@ func GetCurrentAppInfo(w http.ResponseWriter, r *http.Request) {
JSON(w, http.StatusOK, response)
}

func GetCurrentAppStatus(w http.ResponseWriter, r *http.Request) {
clientset, err := k8sutil.GetClientset()
if err != nil {
logger.Error(errors.Wrap(err, "failed to get clientset"))
w.WriteHeader(http.StatusInternalServerError)
return
}

isIntegrationModeEnabled, err := integration.IsEnabled(r.Context(), clientset, store.GetStore().GetNamespace(), store.GetStore().GetLicense())
if err != nil {
logger.Errorf("failed to check if integration mode is enabled: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}

if isIntegrationModeEnabled {
response := GetCurrentAppStatusResponse{}

// TODO: mock app status
// mockData, err := integration.GetMockData(r.Context(), clientset, store.GetStore().GetNamespace())
// if err != nil {
// logger.Errorf("failed to get mock data: %v", err)
// w.WriteHeader(http.StatusInternalServerError)
// return
// }

// response.AppStatus = mockData.AppStatus

JSON(w, http.StatusOK, response)
return
}

response := GetCurrentAppStatusResponse{
AppStatus: store.GetStore().GetAppStatus(),
}

JSON(w, http.StatusOK, response)
}

func GetAppUpdates(w http.ResponseWriter, r *http.Request) {
if util.IsAirgap() {
JSON(w, http.StatusOK, []upstreamtypes.ChannelRelease{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type MockData struct {
AppStatus appstatetypes.State `json:"appStatus,omitempty" yaml:"appStatus,omitempty"`
AppStatus appstatetypes.State `json:"appStatus,omitempty" yaml:"appStatus,omitempty"` // TODO: detailed status
HelmChartURL string `json:"helmChartURL,omitempty" yaml:"helmChartURL,omitempty"`
CurrentRelease *MockRelease `json:"currentRelease,omitempty" yaml:"currentRelease,omitempty"`
DeployedReleases []MockRelease `json:"deployedReleases,omitempty" yaml:"deployedReleases,omitempty"`
Expand Down

0 comments on commit 9d92e9e

Please sign in to comment.