Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify status() and stop() function in kind command #75

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading