Skip to content

Commit 7382df4

Browse files
authored
Merge pull request #48 from godon-dev/fix/strain-aware-validation
fix: make config validation strain-aware, support http recon service
2 parents 939cd05 + bbe16fc commit 7382df4

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

controller/config.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,22 @@ def validate_guardrails_v03(breeder_config):
218218
)
219219

220220
# Validate reconnaissance fields
221-
required_recon_fields = ['service', 'query']
221+
required_recon_fields = ['service']
222222
missing_fields = [f for f in required_recon_fields if f not in recon]
223223

224224
if missing_fields:
225225
raise ValueError(
226226
f"Guardrail {idx} ({guardrail['name']}): 'reconnaissance' missing required fields: {', '.join(missing_fields)}"
227227
)
228228

229-
# Validate service type
230-
valid_services = ['prometheus'] # Extend as needed
229+
valid_services = ['prometheus', 'http']
231230
if recon['service'] not in valid_services:
232231
raise ValueError(
233232
f"Guardrail {idx} ({guardrail['name']}): service '{recon['service']}' not supported. "
234233
f"Valid services: {', '.join(valid_services)}"
235234
)
236235

237-
# Validate query is string
238-
if not isinstance(recon['query'], str) or recon['query'].strip() == "":
236+
if 'query' in recon and (not isinstance(recon['query'], str) or recon['query'].strip() == ""):
239237
raise ValueError(
240238
f"Guardrail {idx} ({guardrail['name']}): 'query' must be a non-empty string"
241239
)
@@ -254,7 +252,7 @@ def validate_guardrails_v03(breeder_config):
254252
)
255253

256254
if 'interval' in recon:
257-
if not isinstance(recon['interval'], int) or recon['interval'] < 1:
255+
if not isinstance(recon['interval'], (int, float)) or recon['interval'] < 0:
258256
raise ValueError(
259257
f"Guardrail {idx} ({guardrail['name']}): 'interval' must be an integer >= 1"
260258
)
@@ -459,18 +457,19 @@ def validate_minimal(breeder_config, strict_mode=True):
459457
"Example: effectuation: {targetRefs: ['my-server', '550e8400-...']}"
460458
)
461459

462-
# Support multiple settings categories (sysctl, sysfs, cpufreq, ethtool)
460+
# Strain-specific validation: settings and recon constraints are strain-dependent.
461+
# For unknown/non-linux_performance strains, skip domain validation and rely on preflight.
462+
breeder_type = breeder_config.get('breeder', {}).get('type', '')
463463
supported_categories = ['sysctl', 'sysfs', 'cpufreq', 'ethtool']
464464
settings = breeder_config.get('settings', {})
465465

466-
# Check if at least one supported category exists
467-
has_any_category = any(category in settings for category in supported_categories)
468-
469-
if not has_any_category:
470-
errors.append(
471-
f"Missing settings configuration. "
472-
f"At least one category required: {', '.join(supported_categories)}"
473-
)
466+
if breeder_type == 'linux_performance':
467+
has_any_category = any(category in settings for category in supported_categories)
468+
if not has_any_category:
469+
errors.append(
470+
f"Missing settings configuration. "
471+
f"At least one category required: {', '.join(supported_categories)}"
472+
)
474473

475474
# Validate constraints structure for all present categories
476475
for category in supported_categories:
@@ -589,7 +588,9 @@ def validate_minimal(breeder_config, strict_mode=True):
589588
continue
590589

591590
# Check required fields
592-
required_recon_fields = ['service', 'query']
591+
required_recon_fields = ['service']
592+
if breeder_type == 'linux_performance':
593+
required_recon_fields.append('query')
593594
missing_fields = [f for f in required_recon_fields if f not in recon]
594595

595596
if missing_fields:
@@ -601,7 +602,7 @@ def validate_minimal(breeder_config, strict_mode=True):
601602

602603
# Validate service type
603604
if 'service' in recon:
604-
valid_services = ['prometheus'] # Extend as needed
605+
valid_services = ['prometheus', 'http']
605606
if recon['service'] not in valid_services:
606607
obj_name = objective.get('name', f'#{idx}')
607608
errors.append(
@@ -633,7 +634,7 @@ def validate_minimal(breeder_config, strict_mode=True):
633634
)
634635

635636
if 'interval' in recon:
636-
if not isinstance(recon['interval'], int) or recon['interval'] < 1:
637+
if not isinstance(recon['interval'], (int, float)) or recon['interval'] < 0:
637638
obj_name = objective.get('name', f'#{idx}')
638639
errors.append(
639640
f"Objective {idx} ({obj_name}): 'interval' must be an integer >= 1"

0 commit comments

Comments
 (0)