Support application removal request.

This commit is contained in:
Thomas E Lackey 2023-12-21 13:08:01 -06:00
parent 4a1a46facc
commit 0f021ceb08
3 changed files with 33 additions and 10 deletions

View File

@ -153,7 +153,6 @@ def dump_known_requests(filename, requests):
@click.command() @click.command()
@click.option("--kube-config", help="Provide a config file for a k8s deployment") @click.option("--kube-config", help="Provide a config file for a k8s deployment")
@click.option("--kube-config", help="Provide a config file for a k8s deployment")
@click.option("--laconic-config", help="Provide a config file for laconicd", required=True) @click.option("--laconic-config", help="Provide a config file for laconicd", required=True)
@click.option("--image-registry", help="Provide a container image registry url for this k8s cluster") @click.option("--image-registry", help="Provide a container image registry url for this k8s cluster")
@click.option("--deployment-parent-dir", help="Create deployment directories beneath this directory", required=True) @click.option("--deployment-parent-dir", help="Create deployment directories beneath this directory", required=True)
@ -237,9 +236,20 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_
if d.attributes.request: if d.attributes.request:
deployments_by_request[d.attributes.request] = d deployments_by_request[d.attributes.request] = d
# Find removal requests.
removals_by_request = {}
removal_requests = laconic.app_deployment_removal_requests()
for r in removal_requests:
if r.attributes.request:
removals_by_request[r.attributes.request] = r
requests_to_execute = [] requests_to_execute = []
for r in requests_by_name.values(): for r in requests_by_name.values():
if r.id not in deployments_by_request: if r.id in deployments_by_request:
print(f"Found satisfied request for {r.id} at {deployments_by_request[r.id].names[0]}")
elif r.id in removals_by_request:
print(f"Found removal request for {r.id} at {removals_by_request[r.id].id}")
else:
if r.id not in previous_requests: if r.id not in previous_requests:
print(f"Request {r.id} needs to processed.") print(f"Request {r.id} needs to processed.")
requests_to_execute.append(r) requests_to_execute.append(r)
@ -247,8 +257,6 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_
print( print(
f"Skipping unsatisfied request {r.id} because we have seen it before." f"Skipping unsatisfied request {r.id} because we have seen it before."
) )
else:
print(f"Found satisfied request {r.id} at {deployments_by_request[r.id].names[0]}")
print("Found %d unsatisfied request(s) to process." % len(requests_to_execute)) print("Found %d unsatisfied request(s) to process." % len(requests_to_execute))

View File

@ -146,11 +146,17 @@ class LaconicRegistryClient:
raise Exception("Cannot locate record:", name_or_id) raise Exception("Cannot locate record:", name_or_id)
return None return None
def app_deployment_requests(self): def app_deployment_requests(self, all=True):
return self.list_records({"type": "ApplicationDeploymentRequest"}, True) return self.list_records({"type": "ApplicationDeploymentRequest"}, all)
def app_deployments(self): def app_deployments(self, all=True):
return self.list_records({"type": "ApplicationDeploymentRecord"}) return self.list_records({"type": "ApplicationDeploymentRecord"}, all)
def app_deployment_removal_requests(self, all=True):
return self.list_records({"type": "ApplicationDeploymentRemovalRequest"}, all)
def app_deployment_removals(self, all=True):
return self.list_records({"type": "ApplicationDeploymentRemovalRecord"}, all)
def publish(self, record, names=[]): def publish(self, record, names=[]):
tmpdir = tempfile.mkdtemp() tmpdir = tempfile.mkdtemp()
@ -165,11 +171,16 @@ class LaconicRegistryClient:
cmd("laconic", "-c", self.config_file, "cns", "record", "publish", "--filename", record_fname) cmd("laconic", "-c", self.config_file, "cns", "record", "publish", "--filename", record_fname)
)["id"] )["id"]
for name in names: for name in names:
cmd("laconic", "-c", self.config_file, "cns", "name", "set", name, new_record_id) self.set_name(name, new_record_id)
return new_record_id return new_record_id
finally: finally:
cmd("rm", "-rf", tmpdir) cmd("rm", "-rf", tmpdir)
def set_name(self, name, record_id):
cmd("laconic", "-c", self.config_file, "cns", "name", "set", name, record_id)
def delete_name(self, name):
cmd("laconic", "-c", self.config_file, "cns", "name", "delete", name)
def file_hash(filename): def file_hash(filename):
return hashlib.sha1(open(filename).read().encode()).hexdigest() return hashlib.sha1(open(filename).read().encode()).hexdigest()

View File

@ -20,7 +20,10 @@ from stack_orchestrator.repos import setup_repositories
from stack_orchestrator.build import build_containers from stack_orchestrator.build import build_containers
from stack_orchestrator.build import build_npms from stack_orchestrator.build import build_npms
from stack_orchestrator.build import build_webapp from stack_orchestrator.build import build_webapp
from stack_orchestrator.deploy.webapp import run_webapp, deploy_webapp, deploy_webapp_from_registry from stack_orchestrator.deploy.webapp import (run_webapp,
deploy_webapp,
deploy_webapp_from_registry,
undeploy_webapp_from_registry)
from stack_orchestrator.deploy import deploy from stack_orchestrator.deploy import deploy
from stack_orchestrator import version from stack_orchestrator import version
from stack_orchestrator.deploy import deployment from stack_orchestrator.deploy import deployment
@ -54,6 +57,7 @@ cli.add_command(build_webapp.command, "build-webapp")
cli.add_command(run_webapp.command, "run-webapp") cli.add_command(run_webapp.command, "run-webapp")
cli.add_command(deploy_webapp.command, "deploy-webapp") cli.add_command(deploy_webapp.command, "deploy-webapp")
cli.add_command(deploy_webapp_from_registry.command, "deploy-webapp-from-registry") cli.add_command(deploy_webapp_from_registry.command, "deploy-webapp-from-registry")
cli.add_command(undeploy_webapp_from_registry.command, "undeploy-webapp-from-registry")
cli.add_command(deploy.command, "deploy") # deploy is an alias for deploy-system cli.add_command(deploy.command, "deploy") # deploy is an alias for deploy-system
cli.add_command(deploy.command, "deploy-system") cli.add_command(deploy.command, "deploy-system")
cli.add_command(deployment.command, "deployment") cli.add_command(deployment.command, "deployment")