Skip to content

Commit

Permalink
Merge pull request #42 from truenas/NAS-130250
Browse files Browse the repository at this point in the history
NAS-130250 / 24.10 / Validate k8s to docker migration file
  • Loading branch information
Qubad786 authored Aug 2, 2024
2 parents 2cba1d8 + eab915d commit e3f18cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps_validation/validate_app_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .app_version import validate_app_version_file
from .ix_values import validate_ix_values_schema
from .json_schema_utils import VERSION_VALIDATION_SCHEMA
from .validate_k8s_to_docker_migration import validate_k8s_to_docker_migrations
from .validate_questions import validate_questions_yaml
from .validate_templates import validate_templates

Expand Down Expand Up @@ -89,6 +90,9 @@ def validate_catalog_item_version(
except ValidationErrors as v:
verrors.extend(v)

validate_k8s_to_docker_migrations(
verrors, os.path.join(version_path, 'migrations'), f'{schema}.migrations.migrate_from_kubernetes'
)
# validate_app_migrations(verrors, version_path, f'{schema}.app_migrations')
# FIXME: Add validation for app migrations

Expand Down
15 changes: 15 additions & 0 deletions apps_validation/validate_k8s_to_docker_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import contextlib
import os.path

from apps_exceptions import ValidationErrors


def validate_k8s_to_docker_migrations(verrors: ValidationErrors, app_migration_path: str, schema: str):
file_to_check_path = os.path.join(app_migration_path, 'migrate_from_kubernetes')
with contextlib.suppress(FileNotFoundError):
with open(file_to_check_path, 'r') as r:
if not r.readline().startswith('#!'):
verrors.add(schema, 'Migration file should start with shebang line')

if not os.access(file_to_check_path, os.X_OK):
verrors.add(schema, 'Migration file is not executable')

0 comments on commit e3f18cb

Please sign in to comment.