redhat-cop / openshift-applier

Used to apply OpenShift objects to an OpenShift Cluster
Apache License 2.0
102 stars 62 forks source link

Applier can't tell when to use template from cluster #105

Closed tylerauerbeck closed 5 years ago

tylerauerbeck commented 5 years ago

Due to the recent changes made in v2.0.7 -- it appears that we're no longer handling referring to templates already on the cluster appropriately.

Given an applier like the one below:

openshift_cluster_content:
- object: ci-cd-deployments
  content:
  - name: sonarqube-postgresql
    template: "openshift//postgresql-ephemeral"
    params_from_vars: "{{ sonarqube.postgresql }}"
    namespace: "{{ ci_cd_namespace }}"
    tags:
      - sonarqube
      - sonarqube-postgresql
      - sonarqube-postgresql-deploy

We get the following error:

TASK [openshift-applier/roles/openshift-applier : Determine location for the file] ***********************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IOError: [Errno 2] No such file or directory: 'openshift//postgresql-ephemeral'
fatal: [ci-cd-tooling]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}

I've confirmed that this works without any issues in v2.0.6

pabrahamsson commented 5 years ago

This seems to be another python2 vs. python3 issue here Python 2 throws IOError and Python 3 throws ValueError

Python 2

python2 -c 'from urllib import urlopen;urlopen("openshift//postgresql-ephemeral")'          
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.7/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/usr/lib64/python2.7/urllib.py", line 213, in open
    return getattr(self, name)(url)
  File "/usr/lib64/python2.7/urllib.py", line 469, in open_file
    return self.open_local_file(url)
  File "/usr/lib64/python2.7/urllib.py", line 483, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] No such file or directory: 'openshift//postgresql-ephemeral'

Python 3

python3 -c 'from urllib.request import urlopen;urlopen("openshift//postgresql-ephemeral")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.7/urllib/request.py", line 510, in open
    req = Request(fullurl, data)
  File "/usr/lib64/python3.7/urllib/request.py", line 328, in __init__
    self.full_url = url
  File "/usr/lib64/python3.7/urllib/request.py", line 354, in full_url
    self._parse()
  File "/usr/lib64/python3.7/urllib/request.py", line 383, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'openshift//postgresql-ephemeral'

Looks like the fix is something like:

try:
    urlopen("foo//bar")
except (ValueError,IOError):
    return return_vals

I'll submit a PR shortly