argoproj / argo-workflows

Workflow Engine for Kubernetes
https://argo-workflows.readthedocs.io/
Apache License 2.0
15.11k stars 3.21k forks source link

Better Messaging for YAML errors in Linter #9550

Open ProjitB opened 2 years ago

ProjitB commented 2 years ago

Summary

What change needs making?

Enhancing yaml parsing debug messages to give more descriptive linting / debug information.

Use Cases

The Argo linter is heavily used for validating workflow configurations before actually running them (for correctness purposes). As yaml keys aren't order dependent, common yaml issues like duplicate keys should be caught with better error messages.

Ex.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: debug-template
spec:
  entrypoint: failing-template
  templates:
  - name: failing-template
    container:
      image: alpine:latest
      command: [sh, -c]
      args: ["echo some random text"]
      ...
      ...
      command: [bash, -c]

Taking a quick glance at a template, sometimes we add in a key again (in this case the command key). However, on doing so, the linter fails with this:

> argo template lint issue.yaml    
✖ found nothing to lint in the specified paths, failing...

Verbose:

> argo template lint issue.yaml -v
DEBU[2022-09-08T15:13:24.085Z] CLI version                                   version="{v3.2.8+8de5416.dirty 2022-02-05T05:11:22Z 8de5416ac6b8f5640a8603e374d99a18a04b5c8d v3.2.8 dirty go1.17.6 gc darwin/arm64}"
DEBU[2022-09-08T15:13:24.085Z] Client options                                opts="(argoServerOpts=(url=,path=,secure=true,insecureSkipVerify=false,http=false),instanceID=)"
I0908 15:13:24.086964   31877 loader.go:372] Config loaded from file:  /Users/user1/.kube/config
I0908 15:13:24.093480   31877 loader.go:372] Config loaded from file:  /Users/user1/.kube/config
✖ found nothing to lint in the specified paths, failing...

The above messaging is confusing and very hard to debug. Ideally these kinds of relatively common errors should be caught?

1r0npipe commented 1 year ago

I would add also the thing of using the better output message if checking the dozens of files in one directory, for example by this command:argo lint ./ (lint all in current dir), but the output is like:

ERRO[current_date_time_stamp] yaml file at index 0 is not valid: error converting YAML to JSON: yaml: line 28: could not find expected ':'
✔ no linting errors found!

so basically no error but the error shown here is not clear which file is affected from:

ls -la | wc -l                                                                                                                                                                                                             
      25

24 files in fact (including line total) which one in fact is affected? I I use loglevel flag, it still doesn't uncover it:

argo lint ./ --loglevel error                                                                                                                                                                                          
ERRO[current_date_time_stamp] yaml file at index 0 is not valid: error converting YAML to JSON: yaml: line 28: could not find expected ':'
✔ no linting errors found!

could it be like:

ERRO[current_date_time_stamp] [<file_name.yaml>] yaml file at index 0 is not valid: error converting YAML to JSON: yaml: line 28: could not find expected ':'

or

ERRO[current_date_time_stamp]  yaml file <file_name.yaml> at index 0 is not valid: error converting YAML to JSON: yaml: line 28: could not find expected ':'

Thank you!