openshift_master_facts_default_predicates.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # pylint: disable=missing-docstring
  2. from ansible.errors import AnsibleError
  3. from ansible.plugins.lookup import LookupBase
  4. class LookupModule(LookupBase):
  5. # pylint: disable=too-many-branches,too-many-statements,too-many-arguments
  6. def run(self, terms, variables=None, regions_enabled=True, short_version=None,
  7. **kwargs):
  8. predicates = []
  9. if short_version is None:
  10. if 'openshift_release' in variables:
  11. release = variables['openshift_release']
  12. if release.startswith('v'):
  13. short_version = release[1:]
  14. else:
  15. short_version = release
  16. short_version = '.'.join(short_version.split('.')[0:2])
  17. elif 'openshift_version' in variables:
  18. version = variables['openshift_version']
  19. short_version = '.'.join(version.split('.')[0:2])
  20. else:
  21. # pylint: disable=line-too-long
  22. raise AnsibleError("Either OpenShift needs to be installed or openshift_release needs to be specified")
  23. if short_version not in ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'latest']:
  24. raise AnsibleError("Unknown short_version %s" % short_version)
  25. if short_version == 'latest':
  26. short_version = '3.11'
  27. # Predicates ordered according to OpenShift Origin source:
  28. # origin/vendor/k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
  29. if short_version in ['3.6']:
  30. predicates.extend([
  31. {'name': 'NoVolumeZoneConflict'},
  32. {'name': 'MaxEBSVolumeCount'},
  33. {'name': 'MaxGCEPDVolumeCount'},
  34. {'name': 'MatchInterPodAffinity'},
  35. {'name': 'NoDiskConflict'},
  36. {'name': 'GeneralPredicates'},
  37. {'name': 'PodToleratesNodeTaints'},
  38. {'name': 'CheckNodeMemoryPressure'},
  39. {'name': 'CheckNodeDiskPressure'},
  40. ])
  41. if short_version in ['3.7', '3.8']:
  42. predicates.extend([
  43. {'name': 'NoVolumeZoneConflict'},
  44. {'name': 'MaxEBSVolumeCount'},
  45. {'name': 'MaxGCEPDVolumeCount'},
  46. {'name': 'MaxAzureDiskVolumeCount'},
  47. {'name': 'MatchInterPodAffinity'},
  48. {'name': 'NoDiskConflict'},
  49. {'name': 'GeneralPredicates'},
  50. {'name': 'PodToleratesNodeTaints'},
  51. {'name': 'CheckNodeMemoryPressure'},
  52. {'name': 'CheckNodeDiskPressure'},
  53. {'name': 'NoVolumeNodeConflict'},
  54. ])
  55. if short_version in ['3.9', '3.10', '3.11']:
  56. predicates.extend([
  57. {'name': 'NoVolumeZoneConflict'},
  58. {'name': 'MaxEBSVolumeCount'},
  59. {'name': 'MaxGCEPDVolumeCount'},
  60. {'name': 'MaxAzureDiskVolumeCount'},
  61. {'name': 'MatchInterPodAffinity'},
  62. {'name': 'NoDiskConflict'},
  63. {'name': 'GeneralPredicates'},
  64. {'name': 'PodToleratesNodeTaints'},
  65. {'name': 'CheckNodeMemoryPressure'},
  66. {'name': 'CheckNodeDiskPressure'},
  67. {'name': 'CheckVolumeBinding'},
  68. ])
  69. if regions_enabled:
  70. region_predicate = {
  71. 'name': 'Region',
  72. 'argument': {
  73. 'serviceAffinity': {
  74. 'labels': ['region']
  75. }
  76. }
  77. }
  78. predicates.append(region_predicate)
  79. return predicates