Skip to content

Commit 35299f0

Browse files
authored
Decouple Env Page from KAM; Show unsynced apps (1785, 1949) (#32)
Signed-off-by: Keith Chong <[email protected]> Signed-off-by: Keith Chong <[email protected]>
1 parent 0cc2af1 commit 35299f0

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

pkg/httpapi/api.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ func (a *APIRouter) GetApplicationHistory(w http.ResponseWriter, r *http.Request
261261
http.Error(w, fmt.Sprintf("failed to get list of application, err: %v", err), http.StatusBadRequest)
262262
return
263263
}
264+
// At this point, if there are no apps as generated by KAM, then check if there are any
265+
// apps in general, where the app name is the environment name. Users aren't expected to use both
266+
// KAM generated apps and custom apps in their GitOps repo.
267+
if len(appList.Items) == 0 {
268+
listOptions = nil
269+
listOptions = append(listOptions, ctrlclient.InNamespace(""), ctrlclient.MatchingFields{
270+
"metadata.name": fmt.Sprintf("%s", envName),
271+
})
272+
err = a.k8sClient.List(r.Context(), appList, listOptions...)
273+
if err != nil {
274+
log.Printf("ERROR: failed to get application list: %v", err)
275+
http.Error(w, fmt.Sprintf("failed to get list of application, err: %v", err), http.StatusBadRequest)
276+
return
277+
}
278+
}
264279

265280
for _, a := range appList.Items {
266281
if a.Spec.Source.RepoURL == parsedRepoURL.String() {
@@ -285,8 +300,7 @@ func (a *APIRouter) GetApplicationHistory(w http.ResponseWriter, r *http.Request
285300
}
286301
commitInfo, err := a.getCommitInfo(app.Name, revision)
287302
if err != nil {
288-
log.Printf("ERROR: failed to retrieve revision metadata for app %s: %v", appName, err)
289-
http.Error(w, fmt.Sprintf("failed to retrieve revision metadata for app %s, err: %v", appName, err), http.StatusBadRequest)
303+
log.Printf("WARNING: failed to retrieve revision metadata for app %s: %v. The app might be unsynced.", appName, err)
290304
}
291305
hist := envHistory{
292306
Author: commitInfo["author"],
@@ -337,6 +351,23 @@ func (a *APIRouter) GetApplicationDetails(w http.ResponseWriter, r *http.Request
337351
return
338352
}
339353

354+
// At this point, if there are no apps as generated by KAM, then check if there are any
355+
// apps in general, where the app name is the environment name. Users aren't expected to use both
356+
// KAM generated apps and custom apps in their GitOps repo.
357+
// We should error out if we don't have the environments as applications
358+
if len(appList.Items) == 0 {
359+
listOptions = nil
360+
listOptions = append(listOptions, ctrlclient.InNamespace(""), ctrlclient.MatchingFields{
361+
"metadata.name": fmt.Sprintf("%s", envName),
362+
})
363+
err = a.k8sClient.List(r.Context(), appList, listOptions...)
364+
if err != nil {
365+
log.Printf("ERROR: failed to get application list: %v", err)
366+
http.Error(w, fmt.Sprintf("failed to get list of application, err: %v", err), http.StatusBadRequest)
367+
return
368+
}
369+
}
370+
340371
for _, a := range appList.Items {
341372
if a.Spec.Source.RepoURL == parsedRepoURL.String() {
342373
app = &a
@@ -359,9 +390,7 @@ func (a *APIRouter) GetApplicationDetails(w http.ResponseWriter, r *http.Request
359390

360391
commitInfo, err := a.getCommitInfo(app.Name, revision)
361392
if err != nil {
362-
log.Printf("ERROR: failed to retrieve revision metadata for app %s: %v", appName, err)
363-
http.Error(w, fmt.Sprintf("failed to retrieve revision metadata for app %s, err: %v", appName, err), http.StatusBadRequest)
364-
return
393+
log.Printf("Warning: failed to retrieve revision metadata for app %s: %v. The app might be unsynced", appName, err)
365394
}
366395

367396
revisionMeta := RevisionMeta{
@@ -393,9 +422,13 @@ func (a *APIRouter) GetApplicationDetails(w http.ResponseWriter, r *http.Request
393422
Status: string(aResource.Status),
394423
})
395424
case kindSecret, kindSealedSecret:
425+
secretHealth := ""
426+
if aResource.Health != nil {
427+
secretHealth = string(aResource.Health.Status)
428+
}
396429
envResources[kindSecret] = append(envResources[kindSecret], envHealthResource{
397430
Name: aResource.Name,
398-
Health: string(aResource.Health.Status),
431+
Health: secretHealth,
399432
Status: string(aResource.Status),
400433
})
401434
case kindRoute:

0 commit comments

Comments
 (0)