Add deployment status command and fix k8s output for deployment ps #679

Merged
telackey merged 6 commits from telackey/k8s_status into main 2023-12-06 16:27:48 +00:00
5 changed files with 50 additions and 22 deletions
Showing only changes of commit 7715e34262 - Show all commits

View File

@ -40,6 +40,13 @@ class DockerDeployer(Deployer):
except DockerException as e:
raise DeployerException(e)
def status(self):
try:
for p in self.docker.compose.ps():
print(f"{p.name}\t{p.state.status}")
except DockerException as e:
raise DeployerException(e)
def ps(self):
try:
return self.docker.compose.ps()

View File

@ -107,6 +107,14 @@ def down_operation(ctx, delete_volumes, extra_args_list):
ctx.obj.deployer.down(timeout=timeout_arg, volumes=delete_volumes)
def status_operation(ctx):
global_context = ctx.parent.parent.obj
if not global_context.dry_run:
if global_context.verbose:
print("Running compose status")
ctx.obj.deployer.status()
def ps_operation(ctx):
global_context = ctx.parent.parent.obj
if not global_context.dry_run:

View File

@ -31,6 +31,10 @@ class Deployer(ABC):
def ps(self):
pass
@abstractmethod
def status(self):
pass
@abstractmethod
def port(self, service, private_port):
pass

View File

@ -18,7 +18,7 @@ from pathlib import Path
import sys
from stack_orchestrator import constants
from stack_orchestrator.deploy.images import push_images_operation
from stack_orchestrator.deploy.deploy import up_operation, down_operation, ps_operation, port_operation
from stack_orchestrator.deploy.deploy import up_operation, down_operation, ps_operation, port_operation, status_operation
from stack_orchestrator.deploy.deploy import exec_operation, logs_operation, create_deploy_context
from stack_orchestrator.deploy.deploy_types import DeployCommandContext
from stack_orchestrator.deploy.deployment_context import DeploymentContext
@ -147,4 +147,5 @@ def logs(ctx, tail, follow, extra_args):
@command.command()
@click.pass_context
def status(ctx):
print(f"Context: {ctx.parent.obj}")
ctx.obj = make_deploy_context(ctx)
status_operation(ctx)

View File

@ -209,7 +209,7 @@ class K8sDeployer(Deployer):
# Destroy the kind cluster
destroy_cluster(self.kind_cluster_name)
def ps(self):
def status(self):
self.connect_api()
# Call whatever API we need to get the running container list
all_pods = self.core_api.list_pod_for_all_namespaces(watch=False)
@ -221,9 +221,8 @@ class K8sDeployer(Deployer):
pods.append(p)
if not pods:
return []
return
ret = []
hostname = "?"
ip = "?"
tls = "?"
@ -250,32 +249,41 @@ class K8sDeployer(Deployer):
print("\tIP:", ip)
print("\tTLS:", tls)
print("")
print("Pod Status:")
print("Pods:")
for i in pods:
if self.cluster_info.app_name in i.metadata.name:
if i.metadata.deletion_timestamp:
print(f"\t{i.metadata.name}: Terminating ({i.metadata.deletion_timestamp})")
else:
print(f"\t{i.metadata.name}: Running ({i.metadata.creation_timestamp})")
pod_ip = i.status.pod_ip
if i.metadata.deletion_timestamp:
print(f"\t{i.metadata.name}: Terminating ({i.metadata.deletion_timestamp})")
else:
print(f"\t{i.metadata.name}: Running ({i.metadata.creation_timestamp})")
print("")
def ps(self):
self.connect_api()
pods = self.core_api.list_pod_for_all_namespaces(watch=False)
ret = []
for p in pods.items:
if self.cluster_info.app_name in p.metadata.name:
pod_ip = p.status.pod_ip
ports = AttrDict()
for c in i.spec.containers:
for p in c.ports:
ports[str(p.container_port)] = [AttrDict({
"HostIp": pod_ip,
"HostPort": p.container_port
})]
for c in p.spec.containers:
if c.ports:
for prt in c.ports:
ports[str(prt.container_port)] = [AttrDict({
"HostIp": pod_ip,
"HostPort": prt.container_port
})]
ret.append(AttrDict({
"id": i.metadata.name,
"name": i.metadata.name,
"namespace": i.metadata.namespace,
"id": p.metadata.name,
"name": p.metadata.name,
"namespace": p.metadata.namespace,
"network_settings": AttrDict({
"ports": ports
})
}))
print("")
return ret