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

Multiple fixes to container name detection #206

Closed
Closed
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
10 changes: 7 additions & 3 deletions providers/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def container_matches?(ps)
return false unless container_image_matches?(ps['image'])
return false unless container_command_matches_if_exists?(ps['command'])
return false unless container_name_matches_if_exists?(ps['names'])
true
false
end

def container_command_matches_if_exists?(command)
Expand All @@ -151,11 +151,11 @@ def container_image_matches?(image)

def container_name_matches?(names)
return false unless names
new_resource.container_name && new_resource.container_name == names
new_resource.container_name && names.split(',').include?(new_resource.container_name)
end

def container_name_matches_if_exists?(names)
return false if new_resource.container_name && new_resource.container_name != names
return container_name_matches?(names) if new_resource.container_name
true
end

Expand Down Expand Up @@ -225,6 +225,10 @@ def docker_containers
end
ps[name.to_s] = line[start..finish - 1].strip
end
# Filter out technical names (eg. 'my-app/db'), which appear in ps['names']
# when a container has at least another container linking to it. If these
# names are not filtered they will pollute current_resource.container_name.
ps['names'] = ps['names'].split(',').grep( /\A[^\/]+\Z/ ).join(',') # technical names always contain a '/'
ps
end
end
Expand Down