Revert recent laconicd deployment changes to restore production webapp deployer function. (#895)
All checks were successful
Lint Checks / Run linter (push) Successful in 49s
Publish / Build and publish (push) Successful in 1m26s
Smoke Test / Run basic test suite (push) Successful in 4m31s
Webapp Test / Run webapp test suite (push) Successful in 4m55s
Deploy Test / Run deploy test suite (push) Successful in 5m22s
Database Test / Run database hosting test on kind/k8s (push) Successful in 8m42s

Reviewed-on: #895
This commit is contained in:
Thomas E Lackey 2024-07-27 17:04:03 +00:00
parent 432bd4113d
commit 2f5b0cdd13
2 changed files with 31 additions and 40 deletions

View File

@ -66,8 +66,8 @@ def process_app_deployment_request(
fqdn = f"{requested_name}.{default_dns_suffix}" fqdn = f"{requested_name}.{default_dns_suffix}"
# 3. check ownership of existing dnsrecord vs this request # 3. check ownership of existing dnsrecord vs this request
dns_lrn = f"{dns_record_namespace}/{fqdn}" dns_crn = f"{dns_record_namespace}/{fqdn}"
dns_record = laconic.get_record(dns_lrn) dns_record = laconic.get_record(dns_crn)
if dns_record: if dns_record:
matched_owner = match_owner(app_deployment_request, dns_record) matched_owner = match_owner(app_deployment_request, dns_record)
if not matched_owner and dns_record.attributes.request: if not matched_owner and dns_record.attributes.request:
@ -77,9 +77,9 @@ def process_app_deployment_request(
logger.log(f"Matched DnsRecord ownership: {matched_owner}") logger.log(f"Matched DnsRecord ownership: {matched_owner}")
else: else:
raise Exception("Unable to confirm ownership of DnsRecord %s for request %s" % raise Exception("Unable to confirm ownership of DnsRecord %s for request %s" %
(dns_lrn, app_deployment_request.id)) (dns_crn, app_deployment_request.id))
elif "preexisting" == fqdn_policy: elif "preexisting" == fqdn_policy:
raise Exception(f"No pre-existing DnsRecord {dns_lrn} could be found for request {app_deployment_request.id}.") raise Exception(f"No pre-existing DnsRecord {dns_crn} could be found for request {app_deployment_request.id}.")
# 4. get build and runtime config from request # 4. get build and runtime config from request
env_filename = None env_filename = None
@ -90,14 +90,14 @@ def process_app_deployment_request(
file.write("%s=%s\n" % (k, shlex.quote(str(v)))) file.write("%s=%s\n" % (k, shlex.quote(str(v))))
# 5. determine new or existing deployment # 5. determine new or existing deployment
# a. check for deployment lrn # a. check for deployment crn
app_deployment_lrn = f"{deployment_record_namespace}/{fqdn}" app_deployment_crn = f"{deployment_record_namespace}/{fqdn}"
if app_deployment_request.attributes.deployment: if app_deployment_request.attributes.deployment:
app_deployment_lrn = app_deployment_request.attributes.deployment app_deployment_crn = app_deployment_request.attributes.deployment
if not app_deployment_lrn.startswith(deployment_record_namespace): if not app_deployment_crn.startswith(deployment_record_namespace):
raise Exception("Deployment CRN %s is not in a supported namespace" % app_deployment_request.attributes.deployment) raise Exception("Deployment CRN %s is not in a supported namespace" % app_deployment_request.attributes.deployment)
deployment_record = laconic.get_record(app_deployment_lrn) deployment_record = laconic.get_record(app_deployment_crn)
deployment_dir = os.path.join(deployment_parent_dir, fqdn) deployment_dir = os.path.join(deployment_parent_dir, fqdn)
# At present we use this to generate a unique but stable ID for the app's host container # At present we use this to generate a unique but stable ID for the app's host container
# TODO: implement support to derive this transparently from the already-unique deployment id # TODO: implement support to derive this transparently from the already-unique deployment id
@ -109,7 +109,7 @@ def process_app_deployment_request(
if not os.path.exists(deployment_dir): if not os.path.exists(deployment_dir):
if deployment_record: if deployment_record:
raise Exception("Deployment record %s exists, but not deployment dir %s. Please remove name." % raise Exception("Deployment record %s exists, but not deployment dir %s. Please remove name." %
(app_deployment_lrn, deployment_dir)) (app_deployment_crn, deployment_dir))
logger.log(f"Creating webapp deployment in: {deployment_dir} with container id: {deployment_container_tag}") logger.log(f"Creating webapp deployment in: {deployment_dir} with container id: {deployment_container_tag}")
deploy_webapp.create_deployment(ctx, deployment_dir, deployment_container_tag, deploy_webapp.create_deployment(ctx, deployment_dir, deployment_container_tag,
f"https://{fqdn}", kube_config, image_registry, env_filename) f"https://{fqdn}", kube_config, image_registry, env_filename)
@ -173,9 +173,9 @@ def process_app_deployment_request(
laconic, laconic,
app, app,
deployment_record, deployment_record,
app_deployment_lrn, app_deployment_crn,
dns_record, dns_record,
dns_lrn, dns_crn,
deployment_dir, deployment_dir,
app_deployment_request, app_deployment_request,
logger logger
@ -214,8 +214,8 @@ def dump_known_requests(filename, requests, status="SEEN"):
@click.option("--only-update-state", help="Only update the state file, don't process any requests anything.", is_flag=True) @click.option("--only-update-state", help="Only update the state file, don't process any requests anything.", is_flag=True)
@click.option("--dns-suffix", help="DNS domain to use eg, laconic.servesthe.world") @click.option("--dns-suffix", help="DNS domain to use eg, laconic.servesthe.world")
@click.option("--fqdn-policy", help="How to handle requests with an FQDN: prohibit, allow, preexisting", default="prohibit") @click.option("--fqdn-policy", help="How to handle requests with an FQDN: prohibit, allow, preexisting", default="prohibit")
@click.option("--record-namespace-dns", help="eg, lrn://laconic/dns") @click.option("--record-namespace-dns", help="eg, crn://laconic/dns")
@click.option("--record-namespace-deployments", help="eg, lrn://laconic/deployments") @click.option("--record-namespace-deployments", help="eg, crn://laconic/deployments")
@click.option("--dry-run", help="Don't do anything, just report what would be done.", is_flag=True) @click.option("--dry-run", help="Don't do anything, just report what would be done.", is_flag=True)
@click.option("--include-tags", help="Only include requests with matching tags (comma-separated).", default="") @click.option("--include-tags", help="Only include requests with matching tags (comma-separated).", default="")
@click.option("--exclude-tags", help="Exclude requests with matching tags (comma-separated).", default="") @click.option("--exclude-tags", help="Exclude requests with matching tags (comma-separated).", default="")

View File

@ -94,7 +94,7 @@ class LaconicRegistryClient:
) )
def list_records(self, criteria={}, all=False): def list_records(self, criteria={}, all=False):
args = ["laconic", "-c", self.config_file, "registry", "record", "list"] args = ["laconic", "-c", self.config_file, "cns", "record", "list"]
if all: if all:
args.append("--all") args.append("--all")
@ -112,13 +112,13 @@ class LaconicRegistryClient:
return results return results
def is_lrn(self, name_or_id: str): def is_crn(self, name_or_id: str):
if name_or_id: if name_or_id:
return str(name_or_id).startswith("lrn://") return str(name_or_id).startswith("crn://")
return False return False
def is_id(self, name_or_id: str): def is_id(self, name_or_id: str):
return not self.is_lrn(name_or_id) return not self.is_crn(name_or_id)
def _add_to_cache(self, records): def _add_to_cache(self, records):
if not records: if not records:
@ -127,8 +127,8 @@ class LaconicRegistryClient:
for p in records: for p in records:
self.cache["name_or_id"][p.id] = p self.cache["name_or_id"][p.id] = p
if p.names: if p.names:
for lrn in p.names: for crn in p.names:
self.cache["name_or_id"][lrn] = p self.cache["name_or_id"][crn] = p
if p.attributes.type not in self.cache: if p.attributes.type not in self.cache:
self.cache[p.attributes.type] = [] self.cache[p.attributes.type] = []
self.cache[p.attributes.type].append(p) self.cache[p.attributes.type].append(p)
@ -140,7 +140,7 @@ class LaconicRegistryClient:
if name in self.cache.name_or_id: if name in self.cache.name_or_id:
return self.cache.name_or_id[name] return self.cache.name_or_id[name]
args = ["laconic", "-c", self.config_file, "registry", "name", "resolve", name] args = ["laconic", "-c", self.config_file, "cns", "name", "resolve", name]
parsed = [AttrDict(r) for r in json.loads(logged_cmd(self.log_file, *args))] parsed = [AttrDict(r) for r in json.loads(logged_cmd(self.log_file, *args))]
if parsed: if parsed:
@ -158,14 +158,14 @@ class LaconicRegistryClient:
if name_or_id in self.cache.name_or_id: if name_or_id in self.cache.name_or_id:
return self.cache.name_or_id[name_or_id] return self.cache.name_or_id[name_or_id]
if self.is_lrn(name_or_id): if self.is_crn(name_or_id):
return self.resolve(name_or_id) return self.resolve(name_or_id)
args = [ args = [
"laconic", "laconic",
"-c", "-c",
self.config_file, self.config_file,
"registry", "cns",
"record", "record",
"get", "get",
"--id", "--id",
@ -203,16 +203,7 @@ class LaconicRegistryClient:
print(open(record_fname, 'r').read(), file=self.log_file) print(open(record_fname, 'r').read(), file=self.log_file)
new_record_id = json.loads( new_record_id = json.loads(
logged_cmd( logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "record", "publish", "--filename", record_fname)
self.log_file,
"laconic", "-c",
self.config_file,
"registry",
"record",
"publish",
"--filename",
record_fname
)
)["id"] )["id"]
for name in names: for name in names:
self.set_name(name, new_record_id) self.set_name(name, new_record_id)
@ -221,10 +212,10 @@ class LaconicRegistryClient:
logged_cmd(self.log_file, "rm", "-rf", tmpdir) logged_cmd(self.log_file, "rm", "-rf", tmpdir)
def set_name(self, name, record_id): def set_name(self, name, record_id):
logged_cmd(self.log_file, "laconic", "-c", self.config_file, "registry", "name", "set", name, record_id) logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "name", "set", name, record_id)
def delete_name(self, name): def delete_name(self, name):
logged_cmd(self.log_file, "laconic", "-c", self.config_file, "registry", "name", "delete", name) logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "name", "delete", name)
def file_hash(filename): def file_hash(filename):
@ -335,9 +326,9 @@ def deploy_to_k8s(deploy_record, deployment_dir, logger):
def publish_deployment(laconic: LaconicRegistryClient, def publish_deployment(laconic: LaconicRegistryClient,
app_record, app_record,
deploy_record, deploy_record,
deployment_lrn, deployment_crn,
dns_record, dns_record,
dns_lrn, dns_crn,
deployment_dir, deployment_dir,
app_deployment_request=None, app_deployment_request=None,
logger=None): logger=None):
@ -372,7 +363,7 @@ def publish_deployment(laconic: LaconicRegistryClient,
if logger: if logger:
logger.log("Publishing DnsRecord.") logger.log("Publishing DnsRecord.")
dns_id = laconic.publish(new_dns_record, [dns_lrn]) dns_id = laconic.publish(new_dns_record, [dns_crn])
new_deployment_record = { new_deployment_record = {
"record": { "record": {
@ -393,7 +384,7 @@ def publish_deployment(laconic: LaconicRegistryClient,
if logger: if logger:
logger.log("Publishing ApplicationDeploymentRecord.") logger.log("Publishing ApplicationDeploymentRecord.")
deployment_id = laconic.publish(new_deployment_record, [deployment_lrn]) deployment_id = laconic.publish(new_deployment_record, [deployment_crn])
return {"dns": dns_id, "deployment": deployment_id} return {"dns": dns_id, "deployment": deployment_id}
@ -402,7 +393,7 @@ def hostname_for_deployment_request(app_deployment_request, laconic):
if not dns_name: if not dns_name:
app = laconic.get_record(app_deployment_request.attributes.application, require=True) app = laconic.get_record(app_deployment_request.attributes.application, require=True)
dns_name = generate_hostname_for_app(app) dns_name = generate_hostname_for_app(app)
elif dns_name.startswith("lrn://"): elif dns_name.startswith("crn://"):
record = laconic.get_record(dns_name, require=True) record = laconic.get_record(dns_name, require=True)
dns_name = record.attributes.name dns_name = record.attributes.name
return dns_name return dns_name