Skip to content

Commit

Permalink
Prepare kubernetes worker (#946)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Jul 5, 2024
1 parent bf2b485 commit 0d2853e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
20 changes: 18 additions & 2 deletions osism/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class Config:
task_default_queue = "default"
task_track_started = (True,)
task_routes = {
"osism.tasks.ansible.*": {"queue": "osism-ansible"},
"osism.tasks.ceph.*": {"queue": "ceph-ansible"},
"osism.tasks.conductor.*": {"queue": "conductor"},
"osism.tasks.kolla.*": {"queue": "kolla-ansible"},
"osism.tasks.kubernetes.*": {"queue": "kubernetes"},
"osism.tasks.netbox.*": {"queue": "netbox"},
"osism.tasks.ansible.*": {"queue": "osism-ansible"},
"osism.tasks.reconciler.*": {"queue": "reconciler"},
"osism.tasks.openstack.*": {"queue": "openstack"},
"osism.tasks.reconciler.*": {"queue": "reconciler"},
}


Expand Down Expand Up @@ -129,6 +130,21 @@ def run_ansible_in_environment(
env=env,
)

# execute roles from kubernetes
elif worker == "kubernetes":
if locking:
lock.acquire()

command = f"/run.sh {role} {joined_arguments}"
logger.info(f"RUN {command}")
p = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
env=env,
)

# execute roles from ceph-ansible
elif worker == "ceph-ansible":
if locking:
Expand Down
27 changes: 27 additions & 0 deletions osism/tasks/kubernetes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0

from celery import Celery

from osism.tasks import Config, run_ansible_in_environment

app = Celery("kubernetes")
app.config_from_object(Config)


@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
pass


@app.task(bind=True, name="osism.tasks.kubernetes.run")
def run(self, environment, playbook, arguments, publish=True, auto_release_time=3600):
return run_ansible_in_environment(
self.request.id,
"kubernetes",
environment,
playbook,
arguments,
publish,
False,
auto_release_time,
)

0 comments on commit 0d2853e

Please sign in to comment.