Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError exception on un-indented kustomize resources #207

Open
alvarogonzalez-packlink opened this issue Jun 21, 2023 · 4 comments
Open
Labels
bug Something isn't working

Comments

@alvarogonzalez-packlink

1️⃣ Description

If I try to run yamlfixer on a simple kustomization.yaml file where the resources section is unindented, I get a ValueError exception

📑 Steps to Reproduce

Steps to reproduce the behavior:

I have this kustomization.yaml:

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base

I run yamlfixer on it and it fails:

% yamlfixer -dn ./apps/elasticsearch-eck/overlays/devops/kustomization.yaml
DEBUG: yamlfixer v0.9.15
DEBUG: arguments=Namespace(backup=False, backupsuffix='.orig', debug=True, diffto='/dev/null', ext='yaml,yml,yamllint', forcecolors=False, followsymlinks=False, listfixers=False, nosyntax=False, nochange=True, recurse=0, jsonsummary=False, plainsummary=False, summary=False, tabsize=2, config_file=None, config_data=None, filenames=['./apps/elasticsearch-eck/overlays/devops/kustomization.yaml'])
DEBUG: Fixing ./apps/elasticsearch-eck/overlays/devops/kustomization.yaml ...
DEBUG: Executing linter with 'yamllint --format parsable --strict -'
DEBUG: Linter's exit code is 1
DEBUG: (5+0, 1+0) => [wrong indentation: expected at least 1 (indentation)]
DEBUG: Calling fix_wrong_indentation("", "- ../../base")
Traceback (most recent call last):
  File "/Users/alvaro/.local/bin/yamlfixer", line 8, in <module>
    sys.exit(run())
  File "/Users/alvaro/.local/pipx/venvs/yamlfixer-opt-nc/lib/python3.10/site-packages/yamlfixer/__main__.py", line 151, in run
    return yfixer.fix()
  File "/Users/alvaro/.local/pipx/venvs/yamlfixer-opt-nc/lib/python3.10/site-packages/yamlfixer/yamlfixer.py", line 167, in fix
    (status, unidiff) = filetofix.fix()
  File "/Users/alvaro/.local/pipx/venvs/yamlfixer-opt-nc/lib/python3.10/site-packages/yamlfixer/filefixer.py", line 211, in fix
    handled = ProblemFixer(self, linenumber, colnumber, problem)()
  File "/Users/alvaro/.local/pipx/venvs/yamlfixer-opt-nc/lib/python3.10/site-packages/yamlfixer/problemfixer.py", line 55, in __call__
    getattr(self, methodname)(left, right)
  File "/Users/alvaro/.local/pipx/venvs/yamlfixer-opt-nc/lib/python3.10/site-packages/yamlfixer/problemfixer.py", line 256, in fix_wrong_indentation
    expected = int(parts[3])
ValueError: invalid literal for int() with base 10: 'at'

I indent the resources section:

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base

Now it works perfectly:

% yamlfixer -dn ./apps/elasticsearch-eck/overlays/devops/kustomization.yaml
DEBUG: yamlfixer v0.9.15
DEBUG: arguments=Namespace(backup=False, backupsuffix='.orig', debug=True, diffto='/dev/null', ext='yaml,yml,yamllint', forcecolors=False, followsymlinks=False, listfixers=False, nosyntax=False, nochange=True, recurse=0, jsonsummary=False, plainsummary=False, summary=False, tabsize=2, config_file=None, config_data=None, filenames=['./apps/elasticsearch-eck/overlays/devops/kustomization.yaml'])
DEBUG: Fixing ./apps/elasticsearch-eck/overlays/devops/kustomization.yaml ...
DEBUG: Executing linter with 'yamllint --format parsable --strict -'
DEBUG: Linter's exit code is 0
DEBUG: passed linter's strict mode

2️⃣ Expected behavior

  • It either runs until the end, or catches the exception
  • The error message details which file had a problem

3️⃣ Scripts

N/A

ℹ️ Environment details

  • macOS 13.4
  • Python 3.9.16 (main, Apr 29 2023, 01:52:19)
  • yamlfixer v0.9.15
  • zsh 5.9 (x86_64-apple-darwin22.0) [No plugins or frameworks]
@alvarogonzalez-packlink alvarogonzalez-packlink added the bug Something isn't working label Jun 21, 2023
@tamere-allo-peter
Copy link
Member

I think you've installed a recent version of yamllint, for which the lint output formatting has changed a bit. I need to work to bring yamlfixer back up-to-date wrt yamllint, unfortunately this will have to wait until I've got more time on my hands. Please could you install an earlier version of yamllint in the meantime, this should solve this problem (yamllint v1.26 should be fine) ?

@alvarogonzalez-packlink
Copy link
Author

alvarogonzalez-packlink commented Jun 22, 2023

Yep, now that I check, last yamllint version working is 1.28.0. With 1.29.0 fails.

1.29 says:

./file.yaml:5:1: [error] wrong indentation: expected at least 1 (indentation)

1.28 says:

./file.yaml:5:1: [error] wrong indentation: expected 2 but found 0 (indentation)

Maybe, meanwhile, the install_requires can be changed from yamllint >= 1.27.1 to `yamllint >= 1.27.1, <1.29' or something like that?

Edit: the change: adrienverge/yamllint#491

@tamere-allo-peter
Copy link
Member

Yes in the meantime that could be a solution. Anyway thanks a lot for your feedback and your help in diagnosing this problem. Have a nice day.

@alvarogonzalez-packlink
Copy link
Author

Thank you too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants