Skip to content

Commit c8d10e9

Browse files
committed
refactor(cli): replace runValidation positional params with validationConfig struct
Extract 11 positional parameters of runValidation into a flat validationConfig struct, improving readability and extensibility. Follows the same pattern used by bundleCmdOptions and validateAgentConfig. Closes #264
1 parent 5fcebe3 commit c8d10e9

File tree

1 file changed

+55
-28
lines changed

1 file changed

+55
-28
lines changed

pkg/cli/validate.go

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -194,35 +194,51 @@ func deployAgentForValidation(ctx context.Context, cfg *validateAgentConfig) (*s
194194
return snap, source, nil
195195
}
196196

197+
// validationConfig holds all parameters for a validation run.
198+
type validationConfig struct {
199+
// Input
200+
phases []validator.Phase
201+
202+
// Output
203+
output string
204+
outFormat serializer.Format
205+
206+
// Validator deployment
207+
validationNamespace string
208+
cleanup bool
209+
imagePullSecrets []string
210+
noCluster bool
211+
212+
// Scheduling
213+
tolerations []corev1.Toleration
214+
215+
// Behavior
216+
failOnError bool
217+
218+
// Evidence
219+
evidenceDir string
220+
}
221+
197222
// runValidation runs validation using the container-per-validator engine.
198223
func runValidation(
199224
ctx context.Context,
200225
rec *recipe.RecipeResult,
201226
snap *snapshotter.Snapshot,
202-
phases []validator.Phase,
203-
output string,
204-
outFormat serializer.Format,
205-
failOnError bool,
206-
validationNamespace string,
207-
cleanup bool,
208-
imagePullSecrets []string,
209-
noCluster bool,
210-
tolerations []corev1.Toleration,
211-
evidenceDir string,
227+
cfg validationConfig,
212228
) error {
213229

214-
slog.Info("running validation", "phases", phases)
230+
slog.Info("running validation", "phases", cfg.phases)
215231

216232
v := validator.New(
217233
validator.WithVersion(version),
218-
validator.WithNamespace(validationNamespace),
219-
validator.WithCleanup(cleanup),
220-
validator.WithImagePullSecrets(imagePullSecrets),
221-
validator.WithNoCluster(noCluster),
222-
validator.WithTolerations(tolerations),
234+
validator.WithNamespace(cfg.validationNamespace),
235+
validator.WithCleanup(cfg.cleanup),
236+
validator.WithImagePullSecrets(cfg.imagePullSecrets),
237+
validator.WithNoCluster(cfg.noCluster),
238+
validator.WithTolerations(cfg.tolerations),
223239
)
224240

225-
results, err := v.ValidatePhases(ctx, phases, rec, snap)
241+
results, err := v.ValidatePhases(ctx, cfg.phases, rec, snap)
226242
if err != nil {
227243
return errors.Wrap(errors.ErrCodeInternal, "validation failed", err)
228244
}
@@ -235,7 +251,7 @@ func runValidation(
235251
combined := ctrf.MergeReports("aicr", version, reports)
236252

237253
// Serialize combined report
238-
ser, serErr := serializer.NewFileWriterOrStdout(outFormat, output)
254+
ser, serErr := serializer.NewFileWriterOrStdout(cfg.outFormat, cfg.output)
239255
if serErr != nil {
240256
return errors.Wrap(errors.ErrCodeInternal, "failed to create output writer", serErr)
241257
}
@@ -264,28 +280,28 @@ func runValidation(
264280
}
265281

266282
// If cleanup is disabled, provide helpful debugging info
267-
if !cleanup {
283+
if !cfg.cleanup {
268284
slog.Info("cleanup disabled - Jobs and RBAC kept for debugging",
269-
"namespace", validationNamespace,
285+
"namespace", cfg.validationNamespace,
270286
"runID", v.RunID)
271-
slog.Info("to inspect Job logs: kubectl logs -l aicr.nvidia.com/job -n " + validationNamespace)
272-
slog.Info("to list Jobs: kubectl get jobs -n " + validationNamespace)
273-
slog.Info("to cleanup manually: kubectl delete jobs -l app.kubernetes.io/name=aicr -n " + validationNamespace)
287+
slog.Info("to inspect Job logs: kubectl logs -l aicr.nvidia.com/job -n " + cfg.validationNamespace)
288+
slog.Info("to list Jobs: kubectl get jobs -n " + cfg.validationNamespace)
289+
slog.Info("to cleanup manually: kubectl delete jobs -l app.kubernetes.io/name=aicr -n " + cfg.validationNamespace)
274290
}
275291

276292
// Generate conformance evidence if requested.
277-
if evidenceDir != "" {
293+
if cfg.evidenceDir != "" {
278294
evidenceCtx, evidenceCancel := context.WithTimeout(ctx, 30*time.Second) //nolint:mnd // Evidence rendering is fast, 30s is generous
279295
defer evidenceCancel()
280296

281-
renderer := evidence.New(evidence.WithOutputDir(evidenceDir))
297+
renderer := evidence.New(evidence.WithOutputDir(cfg.evidenceDir))
282298
if renderErr := renderer.Render(evidenceCtx, combined); renderErr != nil {
283299
return errors.Wrap(errors.ErrCodeInternal, "evidence rendering failed", renderErr)
284300
}
285-
slog.Info("conformance evidence written", "dir", evidenceDir)
301+
slog.Info("conformance evidence written", "dir", cfg.evidenceDir)
286302
}
287303

288-
if failOnError && anyFailed {
304+
if cfg.failOnError && anyFailed {
289305
return errors.New(errors.ErrCodeInternal, "validation failed: one or more phases did not pass")
290306
}
291307

@@ -531,7 +547,18 @@ Run validation without failing on check errors (informational mode):
531547
return err
532548
}
533549

534-
return runValidation(ctx, rec, snap, phases, cmd.String("output"), serializer.FormatJSON, failOnError, validationNamespace, cmd.Bool("cleanup"), cmd.StringSlice("image-pull-secret"), cmd.Bool("no-cluster"), tolerations, evidenceDir)
550+
return runValidation(ctx, rec, snap, validationConfig{
551+
phases: phases,
552+
output: cmd.String("output"),
553+
outFormat: serializer.FormatJSON,
554+
failOnError: failOnError,
555+
validationNamespace: validationNamespace,
556+
cleanup: cmd.Bool("cleanup"),
557+
imagePullSecrets: cmd.StringSlice("image-pull-secret"),
558+
noCluster: cmd.Bool("no-cluster"),
559+
tolerations: tolerations,
560+
evidenceDir: evidenceDir,
561+
})
535562
},
536563
}
537564
}

0 commit comments

Comments
 (0)