-
Notifications
You must be signed in to change notification settings - Fork 3
Cleaned simple kubernetes manager #66
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
Open
iripiri
wants to merge
5
commits into
master
Choose a base branch
from
cleaned-simple-kubernetes-manager
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a689958
fix Dockerfile to build and install executable
iripiri b7f46ae
fixed schema bug, added log messages
iripiri 879ae8e
added simple kubernetes manager with simplified JSON schema
iripiri 3a75fbd
deleted unused code, updated state changes & reading in controller na…
iripiri d78de89
small fixes
iripiri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
components: | ||
- type: generic | ||
category: manager | ||
name: Generic Manager | ||
location: VM Iris | ||
uuid: eddb51a0-557b-4848-ac7a-faccc7c51fa3 | ||
|
||
- category: manager | ||
type: kubernetes-simple | ||
name: Simple Kubernetes Manager | ||
location: VM Iris | ||
uuid: 4f8fb73e-7e74-11eb-8f63-f3ccc3ab82f6 | ||
namespace: villas-controller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
villas/controller/components/managers/kubernetes_simple.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from villas.controller.components.managers.kubernetes import KubernetesManager | ||
from villas.controller.components.simulators.kubernetes import KubernetesJob | ||
|
||
|
||
def build_parameters(sim_name, jobname, image, adls=3600, | ||
privileged=False, name=None, uuid=None): | ||
parameters = { | ||
'type': 'kubernetes', | ||
'category': 'simulator', | ||
'uuid': uuid, | ||
'name': name or sim_name, | ||
'properties': { | ||
'job': { | ||
'apiVersion': 'batch/v1', | ||
'kind': 'Job', | ||
'metadata': { | ||
'name': jobname | ||
}, | ||
'spec': { | ||
'activeDeadlineSeconds': adls, | ||
'backoffLimit': 2, | ||
'template': { | ||
'spec': { | ||
'restartPolicy': 'Never', | ||
'containers': [ | ||
{ | ||
'image': image, | ||
'imagePullPolicy': 'Always', | ||
'name': 'jobcontainer', | ||
'securityContext': { | ||
'privileged': privileged | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return parameters | ||
|
||
|
||
class KubernetesManagerSimple(KubernetesManager): | ||
|
||
def __init__(self, **args): | ||
super().__init__(**args) | ||
|
||
def create(self, payload): | ||
params = payload.get('parameters', {}) | ||
sim_name = payload.get('name', 'Kubernetes Simulator') | ||
jobname = params.get('jobname', 'noname') | ||
adls = params.get('activeDeadlineSeconds', 3600) | ||
if type(adls) is str: | ||
adls = int(adls) | ||
image = params.get('image') | ||
name = params.get('name') | ||
privileged = params.get('privileged', False) | ||
uuid = params.get('uuid') | ||
self.logger.info('uuid:') | ||
self.logger.info(uuid) | ||
|
||
if image is None: | ||
self.logger.error('No image given, will try super.create') | ||
super().create(payload) | ||
return | ||
|
||
parameters = build_parameters( | ||
sim_name=sim_name, | ||
jobname=jobname, | ||
image=image, | ||
adls=adls, | ||
privileged=privileged, | ||
name=name, | ||
uuid=uuid | ||
) | ||
|
||
comp = KubernetesJob(self, **parameters) | ||
self.add_component(comp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -84,6 +84,8 @@ def _drain_publish_queue(self): | |||||||||
self.producer.publish(body, **kwargs) | ||||||||||
except queue.Empty: | ||||||||||
pass | ||||||||||
except TimeoutError: | ||||||||||
LOGGER.warn('TimeoutError, let kombu reconnect..') | ||||||||||
Comment on lines
+87
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Include the caught exception in the log message to aid debugging, e.g.,
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
|
||||||||||
def on_iteration(self): | ||||||||||
# Drain publish queue | ||||||||||
|
Empty file.
33 changes: 33 additions & 0 deletions
33
villas/controller/schemas/manager/kubernetes-simple/create.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
$schema: http://json-schema.org/draft-04/schema# | ||
|
||
type: object | ||
title: 'Simple Kubernetes Job' | ||
required: | ||
- image | ||
properties: | ||
name: | ||
type: string | ||
title: 'Simulator Name' | ||
default: 'Kubernetes Simulator' | ||
uuid: | ||
type: string | ||
title: UUID | ||
default: 8dfd03b2-1c78-11ec-9621-0242ac130002 | ||
jobname: | ||
type: string | ||
title: 'Jobname' | ||
default: myjob | ||
activeDeadlineSeconds: | ||
type: number | ||
title: activeDeadlineSeconds | ||
default: 3600 | ||
image: | ||
type: string | ||
title: Image | ||
default: perl | ||
privileged: | ||
type: boolean | ||
title: Privileged | ||
default: false | ||
description: 'WARNING: If true, the container has root privileges on the host' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use LOGGER.warning instead of the deprecated LOGGER.warn for consistency with the Python logging API.
Copilot uses AI. Check for mistakes.