Skip to content

Commit

Permalink
keep all repotags and use it icp environment (#356)
Browse files Browse the repository at this point in the history
Signed-off-by: Tatsuhiro Chiba <[email protected]>
  • Loading branch information
tatsuhirochiba authored and sahilsuneja1 committed Feb 6, 2018
1 parent 6467ff2 commit a0ec321
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
14 changes: 11 additions & 3 deletions crawler/plugins/environments/icp_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
META_LABELS = 'Labels'
META_UUID = 'Id'
META_HOSTNAME = 'Hostname'
META_REPO = 'RepoTag'
META_REPOS = 'RepoTags'

K8S_NS_LABEL = "io.kubernetes.pod.namespace"
K8S_POD_LABEL = "io.kubernetes.pod.name"
Expand Down Expand Up @@ -43,8 +43,16 @@ def get_container_namespace(self, long_id, options):
podname = labels.get(K8S_POD_LABEL)
# for reg crawler
if regpod_pattern.search(podname):
# repotag format == "repository/k8s-ns/imagename:tag"
repotag = container_meta.get(META_REPO)
# expected repotag is "repository/k8s-ns/imagename:tag"
repotags = container_meta.get(META_REPOS)
repotag_format = ""
for repotag in repotags:
if len(repotag.split("/")) == 3:
repotag_format = repotag.split("/")
break
# check format
e_msg = "can not find proper repotag in this image"
assert repotag_format != "", e_msg
peaces = repotag.split("/")
ns_image_tag = peaces[1] + "/" + peaces[2]
crawler_k8s_ns = CRAWLER_IMAGE_NAMESPACE_FORMAT.format(
Expand Down
7 changes: 5 additions & 2 deletions crawler/utils/dockerutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ def exec_dockerinspect(long_id):
raise DockerutilsException('Failed to exec dockerinspect')

try:
repotags = client.inspect_image(inspect['Image'])['RepoTags']
# get the first RepoTag
inspect['RepoTag'] = client.inspect_image(
inspect['Image'])['RepoTags'][0]
inspect['RepoTag'] = repotags[0]
# keep multiple RepoTags
inspect['RepoTags'] = repotags
except (docker.errors.DockerException, KeyError, IndexError):
inspect['RepoTag'] = ''
inspect['RepoTags'] = ''

return inspect

Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test_dockerutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def inspect_container(self, id):
}

def inspect_image(self, image_id):
return {'RepoTags': 'registry/abc/def:latest'}
return {'RepoTags': ['registry/abc/def:latest', 'debian:latest']}

def history(self, image_id):
return [{'History': 'xxx'}]
Expand Down Expand Up @@ -100,7 +100,8 @@ def test_exec_dockerps(self, *args):

assert c == {'Name': '/pensive_rosalind',
'Created': epoch_seconds,
'RepoTag': 'r',
'RepoTag': 'registry/abc/def:latest',
'RepoTags': ['registry/abc/def:latest', 'debian:latest'],
'State': {'Status': 'running',
'Running': True,
'Pid': '11186'},
Expand Down Expand Up @@ -147,7 +148,8 @@ def test_exec_docker_inspect(self, *args):

assert i == {'Name': '/pensive_rosalind',
'Created': epoch_seconds,
'RepoTag': 'r',
'RepoTag': 'registry/abc/def:latest',
'RepoTags': ['registry/abc/def:latest', 'debian:latest'],
'State': {'Status': 'running',
'Running': True,
'Pid': '11186'},
Expand Down

0 comments on commit a0ec321

Please sign in to comment.