Part of logs command

This commit is contained in:
David Boreham 2023-10-27 09:02:43 -06:00
parent a304bb16cb
commit 9c226944e8
3 changed files with 19 additions and 3 deletions

View File

@ -71,7 +71,7 @@ class ClusterInfo:
spec=client.V1PodSpec(containers=containers), spec=client.V1PodSpec(containers=containers),
) )
spec = client.V1DeploymentSpec( spec = client.V1DeploymentSpec(
replicas=3, template=template, selector={ replicas=1, template=template, selector={
"matchLabels": "matchLabels":
{"app": self.app_name}}) {"app": self.app_name}})

View File

@ -17,6 +17,7 @@ from kubernetes import client, config
from app.deploy.deployer import Deployer from app.deploy.deployer import Deployer
from app.deploy.k8s.helpers import create_cluster, destroy_cluster, load_images_into_kind from app.deploy.k8s.helpers import create_cluster, destroy_cluster, load_images_into_kind
from app.deploy.k8s.helpers import pods_in_deployment
from app.deploy.k8s.cluster_info import ClusterInfo from app.deploy.k8s.cluster_info import ClusterInfo
from app.opts import opts from app.opts import opts
@ -24,6 +25,7 @@ from app.opts import opts
class K8sDeployer(Deployer): class K8sDeployer(Deployer):
name: str = "k8s" name: str = "k8s"
k8s_client: client k8s_client: client
k8s_api: client.AppsV1Api
kind_cluster_name: str kind_cluster_name: str
cluster_info : ClusterInfo cluster_info : ClusterInfo
@ -84,8 +86,13 @@ class K8sDeployer(Deployer):
pass pass
def logs(self, services, tail, follow, stream): def logs(self, services, tail, follow, stream):
# Call the API to get logs self.connect_api()
pass pods = pods_in_deployment(self.k8s_api, "test-deployment")
if len(pods) > 1:
print("Warning: more than one pod in the deployment")
k8s_pod_name = pods[0]
log_data = self.k8s_api.read_namespaced_pod_log(k8s_pod_name, namespace="default", container="test")
print(log_data)
def run(self, image, command, user, volumes, entrypoint=None): def run(self, image, command, user, volumes, entrypoint=None):
# We need to figure out how to do this -- check why we're being called first # We need to figure out how to do this -- check why we're being called first

View File

@ -13,6 +13,7 @@
# 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/>.
from kubernetes import client
import subprocess import subprocess
from typing import Set from typing import Set
@ -38,3 +39,11 @@ def destroy_cluster(name: str):
def load_images_into_kind(kind_cluster_name: str, image_set: Set[str]): def load_images_into_kind(kind_cluster_name: str, image_set: Set[str]):
for image in image_set: for image in image_set:
_run_command(f"kind load docker-image {image} --name {kind_cluster_name}") _run_command(f"kind load docker-image {image} --name {kind_cluster_name}")
def pods_in_deployment(api: client.AppsV1Api, deployment_name: str):
# See: https://stackoverflow.com/a/73525759/1701505
deployment_info = api.read_namespaced_deployment(deployment_name, "default")
if opts.o.debug:
print(f"deployment: {deployment_info}")
return []