Skip to content

Commit

Permalink
deal with cases where container name has more than one middle name
Browse files Browse the repository at this point in the history
there are times where the container name consists of multiple names or
a name and then a number; for example, composename-container-name-1-1.
We want to keep only `container-name-1`. Ensure this is possible
  • Loading branch information
fmcwalters-edited committed Feb 15, 2024
1 parent 03fee73 commit 1591eec
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kubetools/dev/backends/docker_compose/docker_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ def get_containers_status(
if not env:
env = compose_project.replace(docker_name, '')

# if the container was made in v1, it will be compose_name_container_N
# if the container was made in v1, it will be composename_container_N
converted_name = container.name.replace('_', '-')
# if the container is called compose-name-container-N, get `container`
name = converted_name.split('-')[1]

# we need to keep the middle part of the name
# for example if we have a container called `composename-container-1-N`
# we want to keep `container-1`
converted_name_length = len(converted_name.split('-'))
middle_names = converted_name.split('-')[1:converted_name_length-1]
name = '-'.join(middle_name for middle_name in middle_names)

status = container.status == 'running'
ports = []
Expand Down

0 comments on commit 1591eec

Please sign in to comment.