Skip to content

Commit

Permalink
Decouple Env Page from KAM; Show unsynced apps (1785, 1949) (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Chong <kykchong@redhat.com>

Signed-off-by: Keith Chong <kykchong@redhat.com>
  • Loading branch information
keithchong committed Jan 13, 2023
1 parent 0cc2af1 commit 35299f0
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions pkg/httpapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ func (a *APIRouter) GetApplicationHistory(w http.ResponseWriter, r *http.Request
http.Error(w, fmt.Sprintf("failed to get list of application, err: %v", err), http.StatusBadRequest)
return
}
// At this point, if there are no apps as generated by KAM, then check if there are any
// apps in general, where the app name is the environment name. Users aren't expected to use both
// KAM generated apps and custom apps in their GitOps repo.
if len(appList.Items) == 0 {
listOptions = nil
listOptions = append(listOptions, ctrlclient.InNamespace(""), ctrlclient.MatchingFields{
"metadata.name": fmt.Sprintf("%s", envName),
})
err = a.k8sClient.List(r.Context(), appList, listOptions...)
if err != nil {
log.Printf("ERROR: failed to get application list: %v", err)
http.Error(w, fmt.Sprintf("failed to get list of application, err: %v", err), http.StatusBadRequest)
return
}
}

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

// At this point, if there are no apps as generated by KAM, then check if there are any
// apps in general, where the app name is the environment name. Users aren't expected to use both
// KAM generated apps and custom apps in their GitOps repo.
// We should error out if we don't have the environments as applications
if len(appList.Items) == 0 {
listOptions = nil
listOptions = append(listOptions, ctrlclient.InNamespace(""), ctrlclient.MatchingFields{
"metadata.name": fmt.Sprintf("%s", envName),
})
err = a.k8sClient.List(r.Context(), appList, listOptions...)
if err != nil {
log.Printf("ERROR: failed to get application list: %v", err)
http.Error(w, fmt.Sprintf("failed to get list of application, err: %v", err), http.StatusBadRequest)
return
}
}

for _, a := range appList.Items {
if a.Spec.Source.RepoURL == parsedRepoURL.String() {
app = &a
Expand All @@ -359,9 +390,7 @@ func (a *APIRouter) GetApplicationDetails(w http.ResponseWriter, r *http.Request

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

revisionMeta := RevisionMeta{
Expand Down Expand Up @@ -393,9 +422,13 @@ func (a *APIRouter) GetApplicationDetails(w http.ResponseWriter, r *http.Request
Status: string(aResource.Status),
})
case kindSecret, kindSealedSecret:
secretHealth := ""
if aResource.Health != nil {
secretHealth = string(aResource.Health.Status)
}
envResources[kindSecret] = append(envResources[kindSecret], envHealthResource{
Name: aResource.Name,
Health: string(aResource.Health.Status),
Health: secretHealth,
Status: string(aResource.Status),
})
case kindRoute:
Expand Down

0 comments on commit 35299f0

Please sign in to comment.