Skip to content

Commit

Permalink
Added NodeAffinity condition for pop eye job
Browse files Browse the repository at this point in the history
  • Loading branch information
itisallgood committed Oct 25, 2024
1 parent 60eb08e commit 1ce4931
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions playbooks/robusta_playbooks/popeye.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@
from collections import defaultdict
from datetime import datetime
from json import JSONDecodeError
from typing import Any, Dict, List, Literal, Optional

from hikaru.model.rel_1_26 import Container, PodSpec, ResourceRequirements
from typing import Any, Dict, List, Optional

from hikaru.model.rel_1_26 import (
Affinity,
Container,
NodeAffinity,
NodeSelector,
NodeSelectorRequirement,
NodeSelectorTerm,
PodSpec,
ResourceRequirements,
)
from pydantic import BaseModel, ValidationError

from robusta.api import (
RUNNER_SERVICE_ACCOUNT,
EnrichmentAnnotation,
Expand All @@ -18,8 +28,8 @@
FindingSource,
FindingType,
PodRunningParams,
RobustaJob,
PopeyeScanReportBlock,
RobustaJob,
ScanReportRow,
ScanType,
action,
Expand Down Expand Up @@ -128,6 +138,23 @@ def popeye_scan(event: ExecutionBaseEvent, params: PopeyeParams):
resources = ResourceRequirements(
limits={"memory": (str(POPEYE_MEMORY_LIMIT))},
)
affinity = Affinity(
nodeAffinity=NodeAffinity(
requiredDuringSchedulingIgnoredDuringExecution=NodeSelector(
nodeSelectorTerms=[
NodeSelectorTerm(
matchExpressions=[
NodeSelectorRequirement(
key="kubernetes.io/arch",
operator="NotIn",
values=["arm64"],
)
]
)
]
)
)
)
spec = PodSpec(
serviceAccountName=params.service_account_name,
containers=[
Expand All @@ -142,6 +169,7 @@ def popeye_scan(event: ExecutionBaseEvent, params: PopeyeParams):
resources=resources,
)
],
affinity=affinity,
restartPolicy="Never",
**params.popeye_job_spec,
)
Expand Down Expand Up @@ -257,5 +285,5 @@ def clean_up_k8s_logs_from_job_output(logs: str) -> str:
if endline_pos == -1:
logs = ""
else:
logs = logs[endline_pos + 1:]
logs = logs[endline_pos + 1 :]
return logs

0 comments on commit 1ce4931

Please sign in to comment.