Skip to content

Commit

Permalink
Modify status() and stop() function in kind command
Browse files Browse the repository at this point in the history
  • Loading branch information
taleksovska committed Mar 29, 2024
1 parent 74c4c0f commit a2ba24a
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions enabler/commands/cmd_kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,19 @@ def delete(ctx, kube_context_cli, kube_context):
help='The kubernetes context to use',
required=False)
@click.pass_context
@pass_environment
def status(ctx, kube_context):
"""Check the status of the kind cluster"""
# Check if the cluster exists
if ctx.kube_context is not None:
kube_context = ctx.kube_context
if kind.kind_get(kube_context):
if kube.kubectl_info(kube_context):
logger.info('Kind cluster \'' + kube_context + '\' is running')
if kube_context is not None:
if kind.kind_get(kube_context):
if kube.kubectl_info(kube_context):
logger.info('Kind cluster \'' + kube_context + '\' is running')
else:
logger.error('Cluster not running. Please start the cluster')
raise click.Abort()
else:
logger.error('Cluster not running. Please start the cluster')
raise click.Abort()
logger.error('Kind cluster \'' + kube_context + '\' does not exist.') # noqa
else:
logger.error('Kind cluster \'' + kube_context + '\' does not exist.')
logger.error('No kube-context provided.')


@cli.command('start', short_help='Start cluster')
Expand Down Expand Up @@ -211,18 +210,17 @@ def stop(ctx, kube_context_cli, kube_context):
if kind.kind_get(kube_context):
# Check and stop kind cluster docker containers
client = docker.from_env()
kind_containers = client.containers.list(
all, filters={'label': 'io.x-k8s.kind.cluster'})
kind_containers = client.containers()
with click_spinner.spinner():
for container in kind_containers:
if kind_cp in container.name or kind_workers in container.name:
if container.status == 'running':
container.stop()
logger.debug('Container ' + container.name
+ ' stopped')
for container_info in kind_containers:
container_name = container_info['Names'][0]
if container_name and (kind_cp in container_name or kind_workers in container_name): # noqa
container_state = container_info['State'][0]
if container_state == 'running':
container_info.stop()
logger.debug('Container ' + container_name + ' stopped') # noqa
else:
logger.debug('Container ' + container.name +
' is already stopped')
logger.debug('Container ' + container_name + ' is already stopped') # noqa
logger.info('Kind cluster ' + kube_context + ' was stopped.')
else:
logger.error('Kind cluster \'' + kube_context + '\' does not exist.')
Expand Down

0 comments on commit a2ba24a

Please sign in to comment.