You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.5 KiB

Automatically derive defaults versions from checksums (#11906) * Automatically derive defaults versions from checksums Currently, when updating checksums, we manually update the default versions. However, AFAICT, for all components where we have checksums, we're using the newest version out of those checksums. Codify this in the `_version` defaults variables definition to make the process automatic and reduce manual steps (as well as the diff size during reviews). We assume the versions are sorted, with newest first. This should be guaranteed by the pre-commit hooks. * Validate checksums are ordered by versions, newest first * Generalize render-readme-versions hook for other static files The pre-commit hook introduced a142f40e2 (Update versions in README.md with pre-commit, 2025-01-21) allow to update our README with new versions. It turns out other "static" files (== which don't interpret Ansible variables) also use the default version (in that case, our Dockefiles, but there might be others) The Dockerfile breaks if the variable they use (`kube_version`) is a Jinja template. For helping with automatic version upgrade, generalize the hook to deal with other static files, and make a template out of the Dockerfile. * Dockerfile: template kube_version with pre-commit instead of runtime * Validate all versions/checksums are strings in pre-commit All the ansible/python tooling for version is for version strings. YAML unhelpfully consider some stuff as number, so enforce this. * Stringify checksums versions
2 weeks ago
  1. #!/usr/bin/env ansible-playbook
  2. ---
  3. - name: Check all checksums are sorted by version
  4. hosts: localhost
  5. connection: local
  6. gather_facts: false
  7. vars:
  8. fallback_ip: 'bypass tasks in kubespray-defaults'
  9. _keys: "{{ query('ansible.builtin.varnames', '^.+_checksums$') }}"
  10. _values: "{{ query('ansible.builtin.vars', *_keys) | map('dict2items') }}"
  11. _components_archs_values: "{{ _keys | zip(_values) | community.general.dict | dict2items | subelements('value') }}"
  12. _minimal_data_needed: "{{ _components_archs_values | map(attribute='0.key') | zip(_components_archs_values | map(attribute='1')) }}"
  13. roles:
  14. - kubespray-defaults
  15. tasks:
  16. - name: Check all versions are strings
  17. assert:
  18. that: "{{ item.1.value | reject('string') == [] }}"
  19. quiet: true
  20. loop: "{{ _minimal_data_needed }}"
  21. loop_control:
  22. label: "{{ item.0 }}:{{ item.1.key }}"
  23. - name: Check all checksums are sorted by version
  24. vars:
  25. actual: "{{ item.1.value.keys() | map('string') | reverse}}"
  26. sorted: "{{ item.1.value.keys() | map('string') | community.general.version_sort }}"
  27. assert:
  28. that: actual == sorted
  29. quiet: true
  30. msg: "{{ actual | ansible.utils.fact_diff(sorted) }}"
  31. loop: "{{ _minimal_data_needed }}"
  32. loop_control:
  33. label: "{{ item.0 }}:{{ item.1.key }}"
  34. when:
  35. - item.1.value is not string
  36. - (item.1.value | dict2items)[0].value is string or
  37. (item.1.value | dict2items)[0].value is number
  38. # only do list, the others are checksums with a different structure