flake8
This commit is contained in:
parent
5d9d5435e8
commit
a9b476c326
@ -33,6 +33,7 @@ from stack_orchestrator.base import get_npm_registry_url
|
|||||||
# TODO: find a place for this
|
# TODO: find a place for this
|
||||||
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
||||||
|
|
||||||
|
|
||||||
def make_container_build_env(dev_root_path: str,
|
def make_container_build_env(dev_root_path: str,
|
||||||
container_build_dir: str,
|
container_build_dir: str,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
@ -122,6 +123,7 @@ def process_container(stack: str,
|
|||||||
else:
|
else:
|
||||||
print("Skipped")
|
print("Skipped")
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only build these containers")
|
@click.option('--include', help="only build these containers")
|
||||||
@click.option('--exclude', help="don\'t build these containers")
|
@click.option('--exclude', help="don\'t build these containers")
|
||||||
|
@ -54,7 +54,7 @@ def _get_ports(stack):
|
|||||||
|
|
||||||
def _get_named_volumes(stack):
|
def _get_named_volumes(stack):
|
||||||
# Parse the compose files looking for named volumes
|
# Parse the compose files looking for named volumes
|
||||||
named_volumes = {
|
named_volumes = {
|
||||||
"rw": [],
|
"rw": [],
|
||||||
"ro": []
|
"ro": []
|
||||||
}
|
}
|
||||||
@ -123,9 +123,9 @@ def _fixup_pod_file(pod, spec, compose_dir):
|
|||||||
_create_bind_dir_if_relative(volume, volume_spec, compose_dir)
|
_create_bind_dir_if_relative(volume, volume_spec, compose_dir)
|
||||||
new_volume_spec = {"driver": "local",
|
new_volume_spec = {"driver": "local",
|
||||||
"driver_opts": {
|
"driver_opts": {
|
||||||
"type": "none",
|
"type": "none",
|
||||||
"device": volume_spec_fixedup,
|
"device": volume_spec_fixedup,
|
||||||
"o": "bind"
|
"o": "bind"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pod["volumes"][volume] = new_volume_spec
|
pod["volumes"][volume] = new_volume_spec
|
||||||
|
@ -34,10 +34,10 @@ def remote_tag_for_image(image: str, remote_repo_url: str):
|
|||||||
major_parts = image.split("/", 2)
|
major_parts = image.split("/", 2)
|
||||||
org = None
|
org = None
|
||||||
if 2 == len(major_parts):
|
if 2 == len(major_parts):
|
||||||
org = major_parts[0]
|
org = major_parts[0]
|
||||||
image_name_with_version = major_parts[1]
|
image_name_with_version = major_parts[1]
|
||||||
else:
|
else:
|
||||||
image_name_with_version = major_parts[0]
|
image_name_with_version = major_parts[0]
|
||||||
(image_name, image_version) = image_name_with_version.split(":")
|
(image_name, image_version) = image_name_with_version.split(":")
|
||||||
if image_version == "local":
|
if image_version == "local":
|
||||||
return f"{remote_repo_url}/{image_name}:deploy"
|
return f"{remote_repo_url}/{image_name}:deploy"
|
||||||
|
@ -115,9 +115,9 @@ class ClusterInfo:
|
|||||||
for service_name in services:
|
for service_name in services:
|
||||||
service_info = services[service_name]
|
service_info = services[service_name]
|
||||||
if "ports" in service_info:
|
if "ports" in service_info:
|
||||||
port = int(service_info["ports"][0])
|
port = int(service_info["ports"][0])
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"service port: {port}")
|
print(f"service port: {port}")
|
||||||
service = client.V1Service(
|
service = client.V1Service(
|
||||||
metadata=client.V1ObjectMeta(name=f"{self.app_name}-service"),
|
metadata=client.V1ObjectMeta(name=f"{self.app_name}-service"),
|
||||||
spec=client.V1ServiceSpec(
|
spec=client.V1ServiceSpec(
|
||||||
@ -133,21 +133,27 @@ class ClusterInfo:
|
|||||||
|
|
||||||
def get_pvcs(self):
|
def get_pvcs(self):
|
||||||
result = []
|
result = []
|
||||||
volumes = named_volumes_from_pod_files(self.parsed_pod_yaml_map)
|
spec_volumes = self.spec.get_volumes()
|
||||||
|
named_volumes = named_volumes_from_pod_files(self.parsed_pod_yaml_map)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Volumes: {volumes}")
|
print(f"Spec Volumes: {spec_volumes}")
|
||||||
for volume_name in volumes:
|
print(f"Named Volumes: {named_volumes}")
|
||||||
|
for volume_name in spec_volumes:
|
||||||
|
if volume_name not in named_volumes:
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"{volume_name} not in pod files")
|
||||||
|
continue
|
||||||
spec = client.V1PersistentVolumeClaimSpec(
|
spec = client.V1PersistentVolumeClaimSpec(
|
||||||
access_modes=["ReadWriteOnce"],
|
access_modes=["ReadWriteOnce"],
|
||||||
storage_class_name="manual",
|
storage_class_name="manual",
|
||||||
resources=client.V1ResourceRequirements(
|
resources=client.V1ResourceRequirements(
|
||||||
requests={"storage": "2Gi"}
|
requests={"storage": "2Gi"}
|
||||||
),
|
),
|
||||||
volume_name=volume_name
|
volume_name=f"{self.app_name}-{volume_name}"
|
||||||
)
|
)
|
||||||
pvc = client.V1PersistentVolumeClaim(
|
pvc = client.V1PersistentVolumeClaim(
|
||||||
metadata=client.V1ObjectMeta(name=volume_name,
|
metadata=client.V1ObjectMeta(name=f"{self.app_name}-{volume_name}",
|
||||||
labels={"volume-label": volume_name}),
|
labels={"volume-label": f"{self.app_name}-{volume_name}"}),
|
||||||
spec=spec,
|
spec=spec,
|
||||||
)
|
)
|
||||||
result.append(pvc)
|
result.append(pvc)
|
||||||
@ -172,7 +178,7 @@ class ClusterInfo:
|
|||||||
data[f] = open(full_path, 'rt').read()
|
data[f] = open(full_path, 'rt').read()
|
||||||
|
|
||||||
spec = client.V1ConfigMap(
|
spec = client.V1ConfigMap(
|
||||||
metadata=client.V1ObjectMeta(name=cfg_map_name,
|
metadata=client.V1ObjectMeta(name=f"{self.app_name}-{cfg_map_name}",
|
||||||
labels={"configmap-label": cfg_map_name}),
|
labels={"configmap-label": cfg_map_name}),
|
||||||
data=data
|
data=data
|
||||||
)
|
)
|
||||||
@ -195,8 +201,8 @@ class ClusterInfo:
|
|||||||
host_path=client.V1HostPathVolumeSource(path=get_node_pv_mount_path(volume_name))
|
host_path=client.V1HostPathVolumeSource(path=get_node_pv_mount_path(volume_name))
|
||||||
)
|
)
|
||||||
pv = client.V1PersistentVolume(
|
pv = client.V1PersistentVolume(
|
||||||
metadata=client.V1ObjectMeta(name=volume_name,
|
metadata=client.V1ObjectMeta(name=f"{self.app_name}-{volume_name}",
|
||||||
labels={"volume-label": volume_name}),
|
labels={"volume-label": f"{self.app_name}-{volume_name}"}),
|
||||||
spec=spec,
|
spec=spec,
|
||||||
)
|
)
|
||||||
result.append(pv)
|
result.append(pv)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# Copyright © 2023 Vulcanize
|
# Copyright © 2023 Vulcanize
|
||||||
import sys
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -13,6 +12,8 @@ import sys
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -163,7 +164,6 @@ class K8sDeployer(Deployer):
|
|||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"No ingress configured")
|
print(f"No ingress configured")
|
||||||
|
|
||||||
|
|
||||||
def down(self, timeout, volumes):
|
def down(self, timeout, volumes):
|
||||||
self.connect_api()
|
self.connect_api()
|
||||||
# Delete the k8s objects
|
# Delete the k8s objects
|
||||||
@ -234,14 +234,14 @@ class K8sDeployer(Deployer):
|
|||||||
if not self.is_kind():
|
if not self.is_kind():
|
||||||
ingress: client.V1Ingress = self.cluster_info.get_ingress()
|
ingress: client.V1Ingress = self.cluster_info.get_ingress()
|
||||||
if ingress:
|
if ingress:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Deleting this ingress: {ingress}")
|
print(f"Deleting this ingress: {ingress}")
|
||||||
try:
|
try:
|
||||||
self.networking_api.delete_namespaced_ingress(
|
self.networking_api.delete_namespaced_ingress(
|
||||||
name=ingress.metadata.name, namespace=self.k8s_namespace
|
name=ingress.metadata.name, namespace=self.k8s_namespace
|
||||||
)
|
)
|
||||||
except client.exceptions.ApiException as e:
|
except client.exceptions.ApiException as e:
|
||||||
_check_delete_exception(e)
|
_check_delete_exception(e)
|
||||||
else:
|
else:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"No ingress to delete")
|
print(f"No ingress to delete")
|
||||||
|
@ -102,7 +102,8 @@ def volume_mounts_for_service(parsed_pod_files, service):
|
|||||||
volume_name = parts[0]
|
volume_name = parts[0]
|
||||||
mount_path = parts[1]
|
mount_path = parts[1]
|
||||||
mount_options = parts[2] if len(parts) == 3 else None
|
mount_options = parts[2] if len(parts) == 3 else None
|
||||||
volume_device = client.V1VolumeMount(mount_path=mount_path, name=volume_name, read_only="ro" == mount_options)
|
volume_device = client.V1VolumeMount(
|
||||||
|
mount_path=mount_path, name=volume_name, read_only="ro" == mount_options)
|
||||||
result.append(volume_device)
|
result.append(volume_device)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -166,7 +167,7 @@ def _generate_kind_mounts(parsed_pod_files, deployment_dir):
|
|||||||
volume_definitions.append(
|
volume_definitions.append(
|
||||||
f" - hostPath: {_make_absolute_host_path(volume_host_path_map[volume_name], deployment_dir)}\n"
|
f" - hostPath: {_make_absolute_host_path(volume_host_path_map[volume_name], deployment_dir)}\n"
|
||||||
f" containerPath: {get_node_pv_mount_path(volume_name)}"
|
f" containerPath: {get_node_pv_mount_path(volume_name)}"
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
"" if len(volume_definitions) == 0 else (
|
"" if len(volume_definitions) == 0 else (
|
||||||
" extraMounts:\n"
|
" extraMounts:\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user