Skip to content

Commit e4f31e9

Browse files
fix: default argocd verification hits application specific endpoint for health check (#987)
Signed-off-by: Aditya Choudhari <48932219+adityachoudhari26@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 55ca816 commit e4f31e9

8 files changed

Lines changed: 55 additions & 14 deletions

File tree

‎apps/workspace-engine/pkg/jobagents/argo/argoapp_test.go‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,10 @@ func TestBuildArgoLinks(t *testing.T) {
278278

279279
func TestVerifications_ValidConfig(t *testing.T) {
280280
a := New(&mockUpserter{}, &mockDeleter{}, &mockSetter{}, &mockManifestGetter{})
281-
config := oapi.JobAgentConfig{
282-
"serverUrl": "argocd.example.com",
283-
"apiKey": "test-token",
284-
}
281+
job := testJob()
282+
config := job.DispatchContext.JobAgentConfig
285283

286-
specs, err := a.Verifications(config)
284+
specs, err := a.Verifications(config, job.DispatchContext)
287285
require.NoError(t, err)
288286
require.Len(t, specs, 1)
289287
assert.Equal(t, "argocd-application-health", specs[0].Name)
@@ -293,14 +291,20 @@ func TestVerifications_ValidConfig(t *testing.T) {
293291

294292
func TestVerifications_MissingServerUrl(t *testing.T) {
295293
a := New(&mockUpserter{}, &mockDeleter{}, &mockSetter{}, &mockManifestGetter{})
296-
specs, err := a.Verifications(oapi.JobAgentConfig{"apiKey": "token"})
294+
specs, err := a.Verifications(
295+
oapi.JobAgentConfig{"apiKey": "token", "template": "yaml"},
296+
testJob().DispatchContext,
297+
)
297298
require.NoError(t, err)
298299
assert.Nil(t, specs)
299300
}
300301

301302
func TestVerifications_MissingApiKey(t *testing.T) {
302303
a := New(&mockUpserter{}, &mockDeleter{}, &mockSetter{}, &mockManifestGetter{})
303-
specs, err := a.Verifications(oapi.JobAgentConfig{"serverUrl": "addr"})
304+
specs, err := a.Verifications(
305+
oapi.JobAgentConfig{"serverUrl": "addr", "template": "yaml"},
306+
testJob().DispatchContext,
307+
)
304308
require.NoError(t, err)
305309
assert.Nil(t, specs)
306310
}

‎apps/workspace-engine/pkg/jobagents/argo/argocd_verification.go‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
)
99

1010
// Verifications returns the ArgoCD application health check spec built from
11-
// the agent config. The provider URL uses the serverUrl from config; the
12-
// specific application path is resolved at measurement time via the
13-
// provider context.
11+
// the agent config and dispatch context. The dispatch context is used to
12+
// render the application template and determine the specific application
13+
// name to query.
1414
func (a *ArgoApplication) Verifications(
1515
config oapi.JobAgentConfig,
16+
dispatchCtx *oapi.DispatchContext,
1617
) ([]oapi.VerificationMetricSpec, error) {
1718
serverAddr, ok := config["serverUrl"].(string)
1819
if !ok || serverAddr == "" {
@@ -22,12 +23,25 @@ func (a *ArgoApplication) Verifications(
2223
if !ok || apiKey == "" {
2324
return nil, nil
2425
}
26+
template, ok := config["template"].(string)
27+
if !ok || template == "" {
28+
return nil, nil
29+
}
30+
if dispatchCtx == nil {
31+
return nil, fmt.Errorf("missing dispatch context for application template rendering")
32+
}
33+
34+
app, err := TemplateApplication(dispatchCtx, template)
35+
if err != nil {
36+
return nil, fmt.Errorf("render application template: %w", err)
37+
}
38+
MakeApplicationK8sCompatible(app)
2539

2640
baseURL := serverAddr
2741
if !strings.HasPrefix(baseURL, "https://") {
2842
baseURL = "https://" + baseURL
2943
}
30-
appURL := fmt.Sprintf("%s/api/v1/applications", baseURL)
44+
appURL := fmt.Sprintf("%s/api/v1/applications/%s", baseURL, app.Name)
3145

3246
method := oapi.GET
3347
timeout := "5s"

‎apps/workspace-engine/pkg/jobagents/registry.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (r *Registry) Dispatch(ctx context.Context, job *oapi.Job) error {
8585
func (r *Registry) AgentVerifications(
8686
agentType string,
8787
config oapi.JobAgentConfig,
88+
dispatchCtx *oapi.DispatchContext,
8889
) ([]oapi.VerificationMetricSpec, error) {
8990
dispatcher, ok := r.dispatchers[agentType]
9091
if !ok {
@@ -96,7 +97,7 @@ func (r *Registry) AgentVerifications(
9697
return nil, nil
9798
}
9899

99-
return v.Verifications(config)
100+
return v.Verifications(config, dispatchCtx)
100101
}
101102

102103
func (r *Registry) Plan(

‎apps/workspace-engine/pkg/jobagents/types/types.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ type Dispatchable interface {
1919
// the job.
2020
type Verifiable interface {
2121
Type() string
22-
Verifications(config oapi.JobAgentConfig) ([]oapi.VerificationMetricSpec, error)
22+
Verifications(
23+
config oapi.JobAgentConfig,
24+
dispatchCtx *oapi.DispatchContext,
25+
) ([]oapi.VerificationMetricSpec, error)
2326
}
2427

2528
// Plannable is optionally implemented by a Dispatchable to compute the

‎apps/workspace-engine/svc/controllers/jobdispatch/dispatcher.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type AgentVerifier interface {
1919
AgentVerifications(
2020
agentType string,
2121
config oapi.JobAgentConfig,
22+
dispatchCtx *oapi.DispatchContext,
2223
) ([]oapi.VerificationMetricSpec, error)
2324
}
2425

‎apps/workspace-engine/svc/controllers/jobdispatch/reconcile.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ func Reconcile(
6969

7070
var agentSpecs []oapi.VerificationMetricSpec
7171
if verifier != nil {
72-
agentSpecs, err = verifier.AgentVerifications(agent.Type, job.JobAgentConfig)
72+
agentSpecs, err = verifier.AgentVerifications(
73+
agent.Type,
74+
job.JobAgentConfig,
75+
job.DispatchContext,
76+
)
7377
if err != nil {
7478
return nil, err
7579
}

‎apps/workspace-engine/svc/controllers/jobdispatch/reconcile_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type mockVerifier struct {
113113
func (m *mockVerifier) AgentVerifications(
114114
agentType string,
115115
_ oapi.JobAgentConfig,
116+
_ *oapi.DispatchContext,
116117
) ([]oapi.VerificationMetricSpec, error) {
117118
return m.specs[agentType], nil
118119
}

‎response.json‎

Lines changed: 13 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)