|
| 1 | +""" |
| 2 | +Copyright 2025 Google LLC |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +""" |
| 16 | + |
| 17 | +from ..core.commands import run_command_for_value |
| 18 | +from .console import xpk_exit, xpk_print |
| 19 | +from ..commands.config import xpk_cfg |
| 20 | +from ..core.config import DEPENDENCIES_KEY |
| 21 | +from ..commands.version import get_xpk_version |
| 22 | + |
| 23 | + |
| 24 | +validation_commands = { |
| 25 | + 'kubectl': { |
| 26 | + 'command': 'kubectl --help', |
| 27 | + 'message': ( |
| 28 | + '`kubectl` not installed. Please follow' |
| 29 | + ' https://github.com/AI-Hypercomputer/xpk?tab=readme-ov-file#prerequisites' |
| 30 | + ' to install xpk prerequisites.' |
| 31 | + ), |
| 32 | + }, |
| 33 | + 'kjob': { |
| 34 | + 'command': 'kubectl kjob --help', |
| 35 | + 'message': ( |
| 36 | + '`kjobctl` not installed. Please follow' |
| 37 | + ' https://github.com/AI-Hypercomputer/xpk?tab=readme-ov-file#prerequisites' |
| 38 | + ' to install xpk prerequisites.' |
| 39 | + ), |
| 40 | + }, |
| 41 | + 'gcloud': { |
| 42 | + 'command': 'gcloud version', |
| 43 | + 'message': ( |
| 44 | + '`gcloud not installed. Please follow' |
| 45 | + ' https://github.com/AI-Hypercomputer/xpk?tab=readme-ov-file#prerequisites' |
| 46 | + ' to install xpk prerequisites.' |
| 47 | + ), |
| 48 | + }, |
| 49 | + 'docker': { |
| 50 | + 'command': 'docker version', |
| 51 | + 'message': ( |
| 52 | + '`docker` not installed. Please follow' |
| 53 | + ' https://github.com/AI-Hypercomputer/xpk?tab=readme-ov-file#prerequisites' |
| 54 | + ' to install xpk prerequisites.' |
| 55 | + ), |
| 56 | + }, |
| 57 | + 'kueuectl': { |
| 58 | + 'command': 'kubectl kueue --help', |
| 59 | + 'message': ( |
| 60 | + '`kueuectl` not installed. Please follow' |
| 61 | + ' https://github.com/AI-Hypercomputer/xpk?tab=readme-ov-file#prerequisites' |
| 62 | + ' to install xpk prerequisites.' |
| 63 | + ), |
| 64 | + }, |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +def validate_dependencies(): |
| 69 | + deps_version = xpk_cfg.get(DEPENDENCIES_KEY) |
| 70 | + xpk_version = get_xpk_version() |
| 71 | + if deps_version is None or deps_version != xpk_version: |
| 72 | + for name, check in validation_commands.items(): |
| 73 | + cmd, message = check['command'], check['message'] |
| 74 | + code, _ = run_command_for_value( |
| 75 | + cmd, f'Validate {name} installation.', None |
| 76 | + ) |
| 77 | + if code != 0: |
| 78 | + xpk_print(message) |
| 79 | + xpk_exit(code) |
| 80 | + xpk_cfg.set(DEPENDENCIES_KEY, get_xpk_version()) |
0 commit comments