Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to include the resources limits and requests #155

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions operator/charts/netchecks/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ data:
"repository":{{ .Values.probeConfig.image.repository | quote }},
"tag":{{ .Values.probeConfig.image.tag | default .Chart.AppVersion | quote }}
},
{{- if .Values.probeConfig.resources }}
"resources": {{ .Values.probeConfig.resources | toJson }},
{{- end }}
{{- if .Values.probeConfig.tolerations }}
"tolerations": {{ .Values.probeConfig.tolerations| toJson }},
{{- end }}
{{- if .Values.probeConfig.affinity }}
"affinity": {{ .Values.probeConfig.affinity | toJson }},
{{- end }}
"imagePullSecrets": {{ .Values.probeConfig.imagePullSecrets | toJson }},
"podAnnotations": {{ .Values.probeConfig.podAnnotations | toJson }}
}
Expand Down
2 changes: 2 additions & 0 deletions operator/netchecks_operator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ProbeConfig(BaseModel):
image: ImageConfig = ImageConfig()
resources: dict[str, dict] = {}
verbose: bool = False # Don't enable until the operator has been modified to split stdout and stderr
tolerations: list[dict] = []
affinity: dict[str, dict] = {}


class Config(BaseSettings):
Expand Down
75 changes: 75 additions & 0 deletions operator/netchecks_operator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
V1Volume,
V1VolumeMount,
V1SecretVolumeSource,
V1ResourceRequirements,
V1Toleration
)
from structlog import get_logger
from rich import print
Expand Down Expand Up @@ -684,7 +686,29 @@ def create_job_spec(

if disable_redaction:
command.append("--disable-redaction")

resources1 = {}

try:
str1={}
resource=settings.probe.resources

if "limits" in resource:
str1["limits"]=resource["limits"]
else:
str1["limits"]=None

if "requests" in resource:
str1["requests"]=resource["requests"]
else:
str1["requests"]=None

print(str1)
resources1=client.V1ResourceRequirements(requests=str1["requests"],limits=str1["limits"])

except:
pass

logger.info("Probe command", command=command)
container = client.V1Container(
name="netcheck",
Expand All @@ -693,10 +717,61 @@ def create_job_spec(
image_pull_policy=settings.probe.image.pullPolicy,
command=command,
volume_mounts=volume_mounts,
resources=resources1,
env=[
# V1EnvVar(name="NETCHECK_CONFIG", value="/netcheck/")
],
)

# Tolerations
tolerations = []
try:
for i in settings.probe.tolerations:
if "key" in i:
key = i["key"]
else:
key = None
if "operator" in i:
operator=i["operator"]
else:
operator = None
if "effect" in i:
effect=i["effect"]
else:
effect = None
if "value" in i:
value=i["value"]
else:
value = None
if "toleration_seconds" in i:
toleration_seconds=i["tolerationSeconds"]
else:
toleration_seconds = None
tolerations.append(client.V1Toleration(effect,key,operator,toleration_seconds,value))
except:
pass

# NodeAffinity
print(settings.probe.affinity)
node_selector_terms=[]
match_expressions=[]
affinity={}

try:
for i in settings.probe.affinity["nodeAffinity"]["requiredDuringSchedulingIgnoredDuringExecution"]["nodeSelectorTerms"]:
for x in i["matchExpressions"]:
match_expressions.append(client.V1NodeSelectorRequirement(key=x["key"],operator=x["operator"],values=x["values"]))
node_selector_terms.append(client.V1NodeSelectorTerm(match_expressions=match_expressions))
match_expressions=[]

required_during = client.V1NodeSelector(node_selector_terms=node_selector_terms)
node_affinity = client.V1NodeAffinity(required_during_scheduling_ignored_during_execution=required_during)
affinity = client.V1Affinity(node_affinity=node_affinity)
print(affinity)
except:
pass


# Create and configure a pod spec section
labels = get_common_labels(name)
labels["app.kubernetes.io/component"] = "probe"
Expand Down