mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
* feat(api): hard-fork CRD API group argoproj.io -> deploy.hanzo.ai
Hanzo CD hard-fork, phase 1.1. Single source of truth is
pkg/apis/application/register.go's Group constant (Application/AppProject/
ApplicationSet all derive their FullName from it); every other Go call-site
that hardcoded the literal group string is updated to match: the 3 generated
informer GVRs, the app-of-apps nested-Application detector in types.go, the
resource-tree Application-kind cache populator, the 3 NotFound error
constructors in server/application, and the applicationset-controller's
leader-election Lease name/ID (kept in lockstep across Go source + RBAC
resourceNames, or leader election would get RBAC-denied on startup).
CRD YAMLs (application/appproject/applicationset) and every RBAC apiGroups
rule that actually governs our 3 CRDs are repointed to deploy.hanzo.ai, across
both manifests/base/* (namespaced Roles) and manifests/cluster-rbac/* (cluster
scope). Two adjacent things that share the "argoproj.io" string but are NOT
ours are deliberately left untouched: gitops-engine's health-check dispatch
for Argo Workflows' `Workflow` kind, and argocd-server-clusterrole's second
apiGroups block granting read on Argo Workflows' `workflows` resource — both
belong to a separate, unrelated Argoproj-family project we are not forking.
Also untouched, per explicit scope: annotation/label keys (argocd.argoproj.io/*)
and finalizers (*.argoproj.io) that track already-applied live resources, and
argocd-cm.yaml's resource.customizations.ignoreResourceUpdates keys (a narrow
app-of-apps diffing nicety, not build- or RBAC-relevant).
CGO_ENABLED=0 go build ./... verified green.
* ci: wire canonical hanzo.yml + cicd.yml (Hanzo CD image build)
Phase 1.3. Follows the same one-way pattern every hanzo/lux/zoo repo uses:
hanzo.yml declares the image (root Dockerfile -> ghcr.io/hanzoai/deploy) and a
fast go-build sanity test (the multi-stage Dockerfile build is the slow, real
gate); cicd.yml is the ~10-line trigger shim importing hanzoai/ci's reusable
build workflow on the arc pool, secrets from KMS only.
No `deploy:` block yet, matching the hanzoai/cms build-only-first-cutover
pattern: this repo's own live hanzo-cd namespace runs the whole Hanzo fleet's
GitOps, so the prod image/CRD swap is a deliberate separate action (see the
[HELD] universe PR), never an automatic rollout on merge. Every PR/push still
builds and pushes an immutable ghcr.io/hanzoai/deploy:sha-<7>-amd64 image.
* feat(ui): rebrand Argo CD -> Hanzo CD (title, favicon, logo, sidebar)
Phase 1.2. User-facing "Argo CD"/"ArgoCD" text replaced with "Hanzo CD"
across the login page, help modal, settings screens, version-info panel,
sync-options warning, fullscreen-logs title, app.tsx page titles, and
index.html's <title>/noscript text (dropped the now-wrong upstream CLI
doc link rather than invent a hanzo.ai URL that doesn't exist).
Logo/favicon assets replaced with the canonical Hanzo mark (never
hand-drawn, copied from ~/work/hanzo/logo/dist): the two real usages of
Argo's logo collapse onto one Hanzo glyph (mono + white variants) at the
same 5 call sites (login icon + footer, login.scss $logoPath/
$logoNegativePath, sidebar text-logo), preserving the existing CSS
invert() filters so both the light login panel and dark sidebar still
render correctly. Old argologo.svg/argo_o.svg/argo.png deleted (no
longer referenced). favicon-{16x16,32x32}.png added at
ui/src/assets/favicon/ (index.html's links to that path were previously
dead - the directory didn't exist in this checkout). package.json name
argo-cd-ui -> hanzo-cd-ui.
Left alone, deliberately: the two Kubernetes resource-kind icon sets
under ui/src/assets/images/resources/ (unrelated to branding), and
upstream doc/project links (argoproj.io, argo-cd.readthedocs.io) since
we have no equivalent hanzo.ai docs to point to yet - except the login
footer logo's outbound link, which now points to hanzo.ai instead of
argoproj.io (a Hanzo-branded mark linking to the upstream project it
was forked from read as an obvious leftover).
* feat(module): rename Go module github.com/argoproj/argo-cd/v3 -> github.com/hanzoai/deploy
Phase 2. No version suffix on the new path (org policy: never publish our
own Go modules above v1.x.x / with a v2+ suffix) — this fork starts a fresh
v0/v1 module identity rather than carrying the v3 the upstream fork point
had reached.
Mechanical, symmetric rewrite: 704 .go files (import statements only; two
disjoint substitutions applied specific-first so the nested gitops-engine
module path never double-matches), plus go.mod (module line, the
gitops-engine require+replace pair, version reset to v0.0.0-... since a
suffix-less path can't carry a v3 semver), gitops-engine/go.mod, Makefile
(ldflags PACKAGE + 2 TEST_MODULE filters), .golangci.yaml, .goreleaser.yaml,
.mockery.yaml (+ gitops-engine's), Procfile, the codegen/proto generation
scripts (hack/generate-proto.sh, update-codegen.sh, update-openapi.sh), and
20 .proto files' go_package options. Also one OpenTelemetry tracer name
string in gitops-engine/pkg/sync/sync_context.go (a cosmestic label, not an
import, but worth keeping consistent).
CGO_ENABLED=0 go build ./... verified green for both the root module and
the nested gitops-engine module; go vet clean on both; go mod tidy run
(network available) to reconcile go.sum, dependency set unchanged.
Left alone, deliberately: doc-only mentions (docs/snyk/*.html scan reports,
gitops-engine/README.md), a comment-only reference in
.github/workflows/release.yaml, and one Renovate bot config line — none are
build- or codegen-load-bearing. Also left alone: comments citing upstream
GitHub issue URLs (github.com/argoproj/argo-cd/issues/NNNNN) and a handful
of test fixtures using "https://github.com/argoproj/argo-cd.git" as a
representative example repo URL — both are accurate historical/test-data
references, not stale self-references.
---------
Co-authored-by: Hanzo Dev <[email protected]>
563 lines
25 KiB
Go
563 lines
25 KiB
Go
package badge
|
|
|
|
import (
|
|
"fmt"
|
|
"image/color"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/deploy/pkg/apis/application/v1alpha1"
|
|
appclientset "github.com/hanzoai/deploy/pkg/client/clientset/versioned/fake"
|
|
"github.com/hanzoai/deploy/util/settings"
|
|
|
|
"github.com/hanzoai/deploy/gitops-engine/pkg/health"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
)
|
|
|
|
func argoCDSecret() *corev1.Secret {
|
|
return &corev1.Secret{
|
|
ObjectMeta: metav1.ObjectMeta{Name: "argocd-secret", Namespace: "default"},
|
|
Data: map[string][]byte{
|
|
"admin.password": []byte("test"),
|
|
"server.secretkey": []byte("test"),
|
|
},
|
|
}
|
|
}
|
|
|
|
func argoCDCm() *corev1.ConfigMap {
|
|
return &corev1.ConfigMap{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "argocd-cm",
|
|
Namespace: "default",
|
|
Labels: map[string]string{
|
|
"app.kubernetes.io/part-of": "argocd",
|
|
},
|
|
},
|
|
Data: map[string]string{
|
|
"statusbadge.enabled": "true",
|
|
},
|
|
}
|
|
}
|
|
|
|
func testApp() *v1alpha1.Application {
|
|
return &v1alpha1.Application{
|
|
ObjectMeta: metav1.ObjectMeta{Name: "test-app", Namespace: "default"},
|
|
Status: v1alpha1.ApplicationStatus{
|
|
Sync: v1alpha1.SyncStatus{Status: v1alpha1.SyncStatusCodeSynced},
|
|
Health: v1alpha1.AppHealthStatus{Status: health.HealthStatusHealthy},
|
|
OperationState: &v1alpha1.OperationState{
|
|
SyncResult: &v1alpha1.SyncOperationResult{
|
|
Revision: "aa29b85",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func testApp2() *v1alpha1.Application {
|
|
return &v1alpha1.Application{
|
|
ObjectMeta: metav1.ObjectMeta{Name: "test-app", Namespace: "argocd-test"},
|
|
Status: v1alpha1.ApplicationStatus{
|
|
Sync: v1alpha1.SyncStatus{Status: v1alpha1.SyncStatusCodeSynced},
|
|
Health: v1alpha1.AppHealthStatus{Status: health.HealthStatusHealthy},
|
|
OperationState: &v1alpha1.OperationState{
|
|
SyncResult: &v1alpha1.SyncOperationResult{
|
|
Revision: "aa29b85",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func testApp3() *v1alpha1.Application {
|
|
return &v1alpha1.Application{
|
|
ObjectMeta: metav1.ObjectMeta{Name: "test-app", Namespace: "argocd-test"},
|
|
Status: v1alpha1.ApplicationStatus{
|
|
Sync: v1alpha1.SyncStatus{Status: v1alpha1.SyncStatusCodeSynced},
|
|
Health: v1alpha1.AppHealthStatus{Status: health.HealthStatusHealthy},
|
|
OperationState: &v1alpha1.OperationState{
|
|
SyncResult: &v1alpha1.SyncOperationResult{
|
|
Revision: "aa29b85ababababababab",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func testProject() *v1alpha1.AppProject {
|
|
return &v1alpha1.AppProject{
|
|
ObjectMeta: metav1.ObjectMeta{Name: "test-project", Namespace: "default"},
|
|
Spec: v1alpha1.AppProjectSpec{},
|
|
}
|
|
}
|
|
|
|
func TestHandlerFeatureIsEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.NotContains(t, response, "(aa29b85)")
|
|
}
|
|
|
|
func TestHandlerFeatureProjectIsEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
projectTests := []struct {
|
|
testApp []*v1alpha1.Application
|
|
response int
|
|
apiEndPoint string
|
|
namespace string
|
|
health string
|
|
status string
|
|
healthColor color.RGBA
|
|
statusColor color.RGBA
|
|
}{
|
|
{
|
|
createApplications([]string{"Healthy:Synced", "Healthy:Synced"}, []string{"default", "default"}, "test"),
|
|
http.StatusOK, "/api/badge?project=default", "test", "Healthy", "Synced", Green, Green,
|
|
},
|
|
{
|
|
createApplications([]string{"Healthy:Synced", "Healthy:OutOfSync"}, []string{"test-project", "test-project"}, "default"),
|
|
http.StatusOK, "/api/badge?project=test-project", "default", "Healthy", "OutOfSync", Green, Orange,
|
|
},
|
|
{
|
|
createApplications([]string{"Healthy:Synced", "Degraded:Synced"}, []string{"default", "default"}, "test"),
|
|
http.StatusOK, "/api/badge?project=default", "test", "Degraded", "Synced", Red, Green,
|
|
},
|
|
{
|
|
createApplications([]string{"Healthy:Synced", "Degraded:OutOfSync"}, []string{"test-project", "test-project"}, "default"),
|
|
http.StatusOK, "/api/badge?project=test-project", "default", "Degraded", "OutOfSync", Red, Orange,
|
|
},
|
|
{
|
|
createApplications([]string{"Healthy:Synced", "Healthy:Synced"}, []string{"test-project", "default"}, "test"),
|
|
http.StatusOK, "/api/badge?project=default&project=test-project", "test", "Healthy", "Synced", Green, Green,
|
|
},
|
|
{
|
|
createApplications([]string{"Healthy:OutOfSync", "Healthy:Synced"}, []string{"test-project", "default"}, "default"),
|
|
http.StatusOK, "/api/badge?project=default&project=test-project", "default", "Healthy", "OutOfSync", Green, Orange,
|
|
},
|
|
{
|
|
createApplications([]string{"Degraded:Synced", "Healthy:Synced"}, []string{"test-project", "default"}, "test"),
|
|
http.StatusOK, "/api/badge?project=default&project=test-project", "test", "Degraded", "Synced", Red, Green,
|
|
},
|
|
{
|
|
createApplications([]string{"Degraded:OutOfSync", "Healthy:OutOfSync"}, []string{"test-project", "default"}, "default"),
|
|
http.StatusOK, "/api/badge?project=default&project=test-project", "default", "Degraded", "OutOfSync", Red, Orange,
|
|
},
|
|
{
|
|
createApplications([]string{"Unknown:Unknown", "Unknown:Unknown"}, []string{"test-project", "default"}, "default"),
|
|
http.StatusOK, "/api/badge?project=", "default", "Unknown", "Unknown", Purple, Purple,
|
|
},
|
|
{
|
|
createApplications([]string{"Unknown:Unknown", "Unknown:Unknown"}, []string{"test-project", "default"}, "default"),
|
|
http.StatusBadRequest, "/api/badge?project=test$project", "default", "Unknown", "Unknown", Purple, Purple,
|
|
},
|
|
{
|
|
createApplications([]string{"Unknown:Unknown", "Unknown:Unknown"}, []string{"test-project", "default"}, "default"),
|
|
http.StatusOK, "/api/badge?project=unknown", "default", "Unknown", "Unknown", Purple, Purple,
|
|
},
|
|
{
|
|
createApplications([]string{"Unknown:Unknown", "Unknown:Unknown"}, []string{"test-project", "default"}, "default"),
|
|
http.StatusBadRequest, "/api/badge?name=foo_bar", "default", "Unknown", "Unknown", Purple, Purple,
|
|
},
|
|
{
|
|
createApplications([]string{"Unknown:Unknown", "Unknown:Unknown"}, []string{"test-project", "default"}, "default"),
|
|
http.StatusOK, "/api/badge?name=foobar", "default", "Not Found", "", Purple, Purple,
|
|
},
|
|
{
|
|
createApplicationsWithName([]string{"Healthy:Synced"}, []string{"default"}, "test", "test.application"),
|
|
http.StatusOK, "/api/badge?name=test.application-0", "test", "Healthy", "Synced", Green, Green,
|
|
},
|
|
{
|
|
createApplicationsWithName([]string{"Healthy:Synced"}, []string{"default"}, "test", "test.invalid_name"),
|
|
http.StatusBadRequest, "/api/badge?name=test.invalid_name-0", "test", "Healthy", "Synced", Green, Green,
|
|
},
|
|
}
|
|
for _, tt := range projectTests {
|
|
argoCDCm := argoCDCm()
|
|
argoCDSecret := argoCDSecret()
|
|
argoCDCm.Namespace = tt.namespace
|
|
argoCDSecret.Namespace = tt.namespace
|
|
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm, argoCDSecret), tt.namespace)
|
|
objects := []runtime.Object{testProject()}
|
|
for _, v := range tt.testApp {
|
|
objects = append(objects, v)
|
|
}
|
|
handler := NewHandler(appclientset.NewSimpleClientset(objects...), settingsMgr, tt.namespace, []string{})
|
|
rr := httptest.NewRecorder()
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, tt.apiEndPoint, http.NoBody)
|
|
require.NoError(t, err)
|
|
handler.ServeHTTP(rr, req)
|
|
require.Equal(t, tt.response, rr.Result().StatusCode)
|
|
if rr.Result().StatusCode != http.StatusBadRequest {
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
response := rr.Body.String()
|
|
require.Greater(t, len(response), 2)
|
|
assert.Equal(t, toRGBString(tt.healthColor), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(tt.statusColor), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, tt.health, leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, tt.status, rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "\"20\"", svgHeightPattern.FindStringSubmatch(response)[2])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHandlerNamespacesIsEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Application in allowed namespace", func(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp2()), settingsMgr, "default", []string{"argocd-test"})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&namespace=argocd-test", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.NotContains(t, response, "(aa29b85)")
|
|
})
|
|
|
|
t.Run("Application in disallowed namespace", func(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp2()), settingsMgr, "default", []string{"argocd-test"})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&namespace=kube-system", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
require.Equal(t, http.StatusOK, rr.Result().StatusCode)
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Purple), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Purple), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Not Found", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Empty(t, rightTextPattern.FindStringSubmatch(response)[1])
|
|
})
|
|
|
|
t.Run("Request with illegal namespace", func(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp2()), settingsMgr, "default", []string{"argocd-test"})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&namespace=kube()system", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
require.Equal(t, http.StatusBadRequest, rr.Result().StatusCode)
|
|
})
|
|
}
|
|
|
|
func TestHandlerFeatureIsEnabledKeepFullRevisionIsEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp3()), settingsMgr, "argocd-test", []string{""})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&revision=true&keepFullRevision=true", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.Contains(t, response, "(aa29b85ababababababab)")
|
|
}
|
|
|
|
func TestHandlerFeatureIsEnabledKeepFullRevisionIsDisabled(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp3()), settingsMgr, "argocd-test", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&revision=true&keepFullRevision=false", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.Contains(t, response, "(aa29b85)")
|
|
}
|
|
|
|
func TestHandlerFeatureIsEnabledKeepFullRevisionAndWidthIsEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp3()), settingsMgr, "argocd-test", []string{""})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&revision=true&keepFullRevision=true&width=500", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "500", svgWidthPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.Contains(t, response, "(aa29b85ababababababab)")
|
|
}
|
|
|
|
func createApplicationFeatureProjectIsEnabled(healthStatus health.HealthStatusCode, syncStatus v1alpha1.SyncStatusCode, appName, projectName, namespace string) *v1alpha1.Application {
|
|
return &v1alpha1.Application{
|
|
ObjectMeta: metav1.ObjectMeta{Name: appName, Namespace: namespace},
|
|
Status: v1alpha1.ApplicationStatus{
|
|
Sync: v1alpha1.SyncStatus{Status: syncStatus},
|
|
Health: v1alpha1.AppHealthStatus{Status: healthStatus},
|
|
OperationState: &v1alpha1.OperationState{
|
|
SyncResult: &v1alpha1.SyncOperationResult{},
|
|
},
|
|
},
|
|
Spec: v1alpha1.ApplicationSpec{
|
|
Project: projectName,
|
|
},
|
|
}
|
|
}
|
|
|
|
func createApplications(appCombo, projectName []string, namespace string) []*v1alpha1.Application {
|
|
return createApplicationsWithName(appCombo, projectName, namespace, "app")
|
|
}
|
|
|
|
func createApplicationsWithName(appCombo, projectName []string, namespace string, namePrefix string) []*v1alpha1.Application {
|
|
apps := make([]*v1alpha1.Application, len(appCombo))
|
|
healthStatus := func(healthType string) health.HealthStatusCode {
|
|
switch healthType {
|
|
case "Healthy":
|
|
return health.HealthStatusHealthy
|
|
case "Degraded":
|
|
return health.HealthStatusDegraded
|
|
default:
|
|
return health.HealthStatusUnknown
|
|
}
|
|
}
|
|
syncStatus := func(syncType string) v1alpha1.SyncStatusCode {
|
|
switch syncType {
|
|
case "Synced":
|
|
return v1alpha1.SyncStatusCodeSynced
|
|
case "OutOfSync":
|
|
return v1alpha1.SyncStatusCodeOutOfSync
|
|
default:
|
|
return v1alpha1.SyncStatusCodeUnknown
|
|
}
|
|
}
|
|
for k, v := range appCombo {
|
|
a := strings.Split(v, ":")
|
|
healthApp := healthStatus(a[0])
|
|
syncApp := syncStatus(a[1])
|
|
appName := fmt.Sprintf("%s-%v", namePrefix, k)
|
|
apps[k] = createApplicationFeatureProjectIsEnabled(healthApp, syncApp, appName, projectName[k], namespace)
|
|
}
|
|
return apps
|
|
}
|
|
|
|
func TestHandlerFeatureIsEnabledRevisionIsEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&revision=true", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.Contains(t, response, "(aa29b85)")
|
|
}
|
|
|
|
func TestHandlerRevisionIsEnabledNoOperationState(t *testing.T) {
|
|
t.Parallel()
|
|
app := testApp()
|
|
app.Status.OperationState = nil
|
|
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(app), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&revision=true", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.NotContains(t, response, "(aa29b85)")
|
|
}
|
|
|
|
func TestHandlerRevisionIsEnabledShortCommitSHA(t *testing.T) {
|
|
t.Parallel()
|
|
app := testApp()
|
|
app.Status.OperationState.SyncResult.Revision = "abc"
|
|
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(app), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&revision=true", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
response := rr.Body.String()
|
|
assert.Contains(t, response, "(abc)")
|
|
}
|
|
|
|
func TestHandlerRevisionIsEnabledMultipleSources(t *testing.T) {
|
|
t.Parallel()
|
|
app := testApp()
|
|
app.Status.OperationState.SyncResult.Revision = ""
|
|
app.Status.OperationState.SyncResult.Revisions = []string{"aa29b85", "cf41g63"}
|
|
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(app), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&revision=true", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
response := rr.Body.String()
|
|
assert.Contains(t, response, "(aa29b85)")
|
|
assert.NotContains(t, response, "(cf41g63)")
|
|
}
|
|
|
|
func TestHandlerFeatureIsDisabled(t *testing.T) {
|
|
t.Parallel()
|
|
argoCDCmDisabled := argoCDCm()
|
|
delete(argoCDCmDisabled.Data, "statusbadge.enabled")
|
|
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewSimpleClientset(argoCDCmDisabled, argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Purple), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Purple), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Unknown", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Unknown", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "test-app")
|
|
assert.Equal(t, "\"20\"", svgHeightPattern.FindStringSubmatch(response)[2])
|
|
}
|
|
|
|
func TestHandlerApplicationNameInBadgeIsEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewSimpleClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app&showAppName=true", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.NotContains(t, response, "(aa29b85)")
|
|
|
|
assert.Equal(t, "test-app", titleTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, fmt.Sprintf("\"%d\"", svgHeightWithAppName), svgHeightPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, fmt.Sprintf("\"%d\"", badgeRowHeight), leftRectYCoodPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, fmt.Sprintf("\"%d\"", badgeRowHeight), rightRectYCoodPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, fmt.Sprintf("\"%d\"", badgeRowHeight), revisionRectYCoodPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, fmt.Sprintf("\"%d\"", logoYCoodWithAppName), logoYCoodPattern.FindStringSubmatch(response)[2])
|
|
}
|
|
|
|
func TestHandlerApplicationNameInBadgeIsDisabled(t *testing.T) {
|
|
t.Parallel()
|
|
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewSimpleClientset(argoCDCm(), argoCDSecret()), "default")
|
|
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/api/badge?name=test-app", http.NoBody)
|
|
require.NoError(t, err)
|
|
|
|
rr := httptest.NewRecorder()
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
|
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
|
|
|
response := rr.Body.String()
|
|
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, toRGBString(Green), rightRectColorPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Healthy", leftTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "Synced", rightTextPattern.FindStringSubmatch(response)[1])
|
|
assert.Equal(t, "\"20\"", svgHeightPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, "\"0\"", leftRectYCoodPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, "\"0\"", rightRectYCoodPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, "\"0\"", revisionRectYCoodPattern.FindStringSubmatch(response)[2])
|
|
assert.Equal(t, "\"2\"", logoYCoodPattern.FindStringSubmatch(response)[2])
|
|
assert.NotContains(t, response, "test-app")
|
|
}
|