Skip to content

Fixes a bug when running fix_serialization on Kubernetes ExternalName…#161

Merged
fabianvf merged 2 commits intoopenshift:masterfrom
zpetterd:fix-svc-externalname
Mar 5, 2018
Merged

Fixes a bug when running fix_serialization on Kubernetes ExternalName…#161
fabianvf merged 2 commits intoopenshift:masterfrom
zpetterd:fix-svc-externalname

Conversation

@zpetterd
Copy link
Copy Markdown
Contributor

@zpetterd zpetterd commented Mar 2, 2018

This bug popped up when specifically using the k8s_raw module with ansible.

When the fix_serialization function is with a service definition like below it runs into the following error message because no ports need to be specified
Example service definition:

---
apiVersion: v1
kind: Service
metadata:
  name: mysql-server
  namespace: default
spec:
  externalName: <some dns address>
  type: ExternalName

Error

Traceback (most recent call last):
  File \"/tmp/ansible_beh9U6/ansible_module_k8s_raw.py\", line 163, in <module>
    main()
  File \"/tmp/ansible_beh9U6/ansible_module_k8s_raw.py\", line 159, in main
    KubernetesRawModule().execute_module()
  File \"/tmp/ansible_beh9U6/ansible_modlib.zip/ansible/module_utils/k8s/raw.py\", line 145, in execute_module
  File \"/usr/lib/python2.7/site-packages/openshift/helper/base.py\", line 179, in fix_serialization
    for port in obj.spec.ports:
TypeError: 'NoneType' object is not iterable

@fabianvf
Copy link
Copy Markdown
Member

fabianvf commented Mar 2, 2018

good catch, I wonder if it might be better to add a check for the ports variable instead though, so it would look like

if obj and obj.kind == "Service" and obj.spec.ports:
    ...

That way it will prevent iteration if ports isn't provided in every case.

@fabianvf
Copy link
Copy Markdown
Member

fabianvf commented Mar 5, 2018

LGTM

@fabianvf fabianvf merged commit 2a798cd into openshift:master Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants