mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-23 17:28:44 +00:00
App status badge (#1818)
This commit is contained in:
parent
c46e3f979e
commit
3815570294
2 changed files with 71 additions and 47 deletions
9
Gopkg.lock
generated
9
Gopkg.lock
generated
|
|
@ -48,6 +48,14 @@
|
|||
pruneopts = ""
|
||||
revision = "09c41003ee1d5015b75f331e52215512e7145b8d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:2e37a5d64464ac14b838a0d3aa677eb0e61de44124a25e338d0cf6cd48b8fe71"
|
||||
name = "github.com/ajstarks/svgo"
|
||||
packages = ["."]
|
||||
pruneopts = ""
|
||||
revision = "6ce6a3bcf6cde6c5007887677ebd148ec30f42a4"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:0cac9c70f3308d54ed601878aa66423eb95c374616fdd7d2ea4e2d18b045ae62"
|
||||
|
|
@ -1575,6 +1583,7 @@
|
|||
input-imports = [
|
||||
"github.com/Masterminds/semver",
|
||||
"github.com/TomOnTime/utfutil",
|
||||
"github.com/ajstarks/svgo",
|
||||
"github.com/ant31/crd-validation/pkg",
|
||||
"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1",
|
||||
"github.com/argoproj/argo/util",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
svg "github.com/ajstarks/svgo"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
appv1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/pkg/client/clientset/versioned"
|
||||
)
|
||||
|
||||
|
|
@ -21,93 +22,107 @@ type Handler struct {
|
|||
appClientset versioned.Interface
|
||||
}
|
||||
|
||||
const (
|
||||
syncTextOffStart = 3
|
||||
lightBlue = "fill:rgb(200,321,233);stroke:black"
|
||||
red = "fill:rgb(255,43,0);stroke:black"
|
||||
lightGreen = "fill:rgb(127,255,131);stroke:black"
|
||||
yellow = "fill:rgb(255,251,92);stroke:black"
|
||||
orange = "fill:rgb(255,145,0);stroke:black"
|
||||
teal = "fill:rgb(109,202,205);stroke:black"
|
||||
purple = "fill:rgb(178,102,255);stroke:black"
|
||||
darkgreen = "fill:rgb(0,204,0);stroke:black"
|
||||
|
||||
pageWidth = 2000
|
||||
pageHeight = 2000
|
||||
xStart = 0
|
||||
yStart = 0
|
||||
badgeHeight = 25
|
||||
//badgeCurve is the rx/ry value for the round rectangle for each badge
|
||||
badgeCurve = 2
|
||||
textFormat = "font-size:11;fill:black"
|
||||
yText = 17
|
||||
//xHealthText is x pos where text for health badge and edge case badges start
|
||||
xHealthText = 3
|
||||
nameMissingLength = 120
|
||||
badgeBuffer = 7
|
||||
notFoundBadgeBuffer = 6
|
||||
)
|
||||
|
||||
//ServeHTTP returns badge with health and sync status for application
|
||||
//(or an error badge if wrong query or application name is given)
|
||||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
//Sample url: http://localhost:8080/api/badge?name=123
|
||||
keys, ok := r.URL.Query()["name"]
|
||||
|
||||
//error when you add another query after name = and do like http://localhost:8080/api/badge?name=123/hadfkjajdhj
|
||||
|
||||
pageWidth := 2000
|
||||
pageHeight := 2000
|
||||
xStart := 0
|
||||
yStart := 0
|
||||
badgeHeight := 25
|
||||
//badgeCurve is the rx/ry value for the round rectangle for each badge
|
||||
badgeCurve := 2
|
||||
textFormat := "font-size:11;fill:black"
|
||||
|
||||
if !ok || len(keys[0]) < 1 {
|
||||
svgOne := svg.New(w)
|
||||
svgOne.Start(pageWidth, pageHeight)
|
||||
svgOne.Roundrect(xStart, yStart, 120, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(200,321,233);stroke:black;stroke-width:0.7")
|
||||
svgOne.Text(4, 18, "Param 'name=' missing", textFormat)
|
||||
svgOne.Roundrect(xStart, yStart, nameMissingLength, badgeHeight, badgeCurve, badgeCurve, lightBlue)
|
||||
svgOne.Text(xHealthText, yText, "Param 'name=' missing", textFormat)
|
||||
svgOne.End()
|
||||
return
|
||||
}
|
||||
|
||||
key := keys[0]
|
||||
//if another query is added after the appplication name and is separated by a /
|
||||
//if another query is added after the appplication name and is separated by a / this will make sure it only looks at
|
||||
//what is between the name= and / and will open the applicaion by that name
|
||||
q := strings.Split(key, "/")
|
||||
key = q[0]
|
||||
app, err := h.appClientset.ArgoprojV1alpha1().Applications(h.namespace).Get(key, v1.GetOptions{})
|
||||
if err != nil {
|
||||
notFoundBadgeLength := len("Application"+key+" not found") * notFoundBadgeBuffer
|
||||
svgTwo := svg.New(w)
|
||||
svgTwo.Start(pageWidth, pageHeight)
|
||||
svgTwo.Roundrect(xStart, yStart, 114, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(255,43,0);stroke:black;stroke-width:0.7")
|
||||
svgTwo.Text(3, 18, "Application not found", textFormat)
|
||||
svgTwo.Text(4, 30, key)
|
||||
svgTwo.Roundrect(xStart, yStart, notFoundBadgeLength, badgeHeight, badgeCurve, badgeCurve, red)
|
||||
svgTwo.Text(xHealthText, yText, "Application '"+key+"' not found", textFormat)
|
||||
svgTwo.End()
|
||||
return
|
||||
}
|
||||
|
||||
health := app.Status.Health.Status
|
||||
status := "Unknown"
|
||||
//status := app.Status.Sync.Status
|
||||
healthBadgeLength := len(health) * 7
|
||||
status := app.Status.Sync.Status
|
||||
|
||||
healthBadgeLength := len(health) * badgeBuffer
|
||||
//healthBadgeLength is where the sync badge starts along with being the length of the health badge
|
||||
syncBadgeLength := len(status) * 7
|
||||
syncTextStart := healthBadgeLength + 3
|
||||
syncBadgeLength := len(status) * badgeBuffer
|
||||
|
||||
syncTextStart := healthBadgeLength + syncTextOffStart
|
||||
|
||||
svgThree := svg.New(w)
|
||||
svgThree.Start(pageWidth, pageHeight)
|
||||
xHealthText := 3
|
||||
yText := 18
|
||||
|
||||
switch health {
|
||||
case "Healthy":
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(127,255,131);stroke:black;stroke-width:0.7")
|
||||
case appv1.HealthStatusHealthy:
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, lightGreen)
|
||||
svgThree.Text(xHealthText, yText, health, textFormat)
|
||||
case "Progressing":
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(255,251,92);stroke:black;stroke-width:0.7")
|
||||
case appv1.HealthStatusProgressing:
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, yellow)
|
||||
svgThree.Text(xHealthText, yText, health, textFormat)
|
||||
case "Suspended":
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(255,145,0);stroke:black;stroke-width:0.7")
|
||||
case appv1.HealthStatusSuspended:
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, orange)
|
||||
svgThree.Text(xHealthText, yText, health, textFormat)
|
||||
case "Degraded":
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(109,202,205);stroke:black;stroke-width:0.7")
|
||||
case appv1.HealthStatusDegraded:
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, teal)
|
||||
svgThree.Text(xHealthText, yText, health, textFormat)
|
||||
case "Missing":
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(255,36,36);stroke:black;stroke-width:0.7")
|
||||
case appv1.HealthStatusMissing:
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, red)
|
||||
svgThree.Text(xHealthText, yText, health, textFormat)
|
||||
default:
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(178,102,255);stroke:black;stroke-width:0.7")
|
||||
svgThree.Roundrect(xStart, yStart, healthBadgeLength, badgeHeight, badgeCurve, badgeCurve, purple)
|
||||
svgThree.Text(xHealthText, yText, health, textFormat)
|
||||
}
|
||||
switch status {
|
||||
case "Synced":
|
||||
svgThree.Roundrect(healthBadgeLength, yStart, syncBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(0,204,0);stroke:black;stroke-width:0.7")
|
||||
svgThree.Text(syncTextStart, yText, status, textFormat)
|
||||
case "OutOfSync":
|
||||
svgThree.Roundrect(healthBadgeLength, yStart, syncBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(255,57,57);stroke:black;stroke-width:0.7")
|
||||
svgThree.Text(syncTextStart, yText, status, textFormat)
|
||||
case appv1.SyncStatusCodeSynced:
|
||||
svgThree.Roundrect(healthBadgeLength, yStart, syncBadgeLength, badgeHeight, badgeCurve, badgeCurve, darkgreen)
|
||||
svgThree.Text(syncTextStart, yText, string(status), textFormat)
|
||||
case appv1.SyncStatusCodeOutOfSync:
|
||||
svgThree.Roundrect(healthBadgeLength, yStart, syncBadgeLength, badgeHeight, badgeCurve, badgeCurve, red)
|
||||
svgThree.Text(syncTextStart, yText, string(status), textFormat)
|
||||
default:
|
||||
svgThree.Roundrect(healthBadgeLength, yStart, syncBadgeLength, badgeHeight, badgeCurve, badgeCurve, "fill:rgb(209,155,177);stroke:black;stroke-width:0.7")
|
||||
svgThree.Text(syncTextStart, yText, status, textFormat)
|
||||
svgThree.Roundrect(healthBadgeLength, yStart, syncBadgeLength, badgeHeight, badgeCurve, badgeCurve, purple)
|
||||
svgThree.Text(syncTextStart, yText, string(status), textFormat)
|
||||
}
|
||||
|
||||
svgThree.End()
|
||||
}
|
||||
|
||||
//func (h string, s string) rectangle() {
|
||||
|
||||
//}/
|
||||
|
|
|
|||
Loading…
Reference in a new issue