ansible / ansible-kubernetes-modules

DEPRECATED Ansible role containing pre-release K8s modules
Apache License 2.0
73 stars 39 forks source link

target_port should accept integer from variable #19

Closed rahulinux closed 7 years ago

rahulinux commented 7 years ago

Error

"Failed to create object: Service \"hello\" is invalid: spec.ports[0].targetPort: Invalid value: \"8080\": must contain at least one letter or number (a-z, 0-9)"

Example

    ports:
      - port: "{{  env_vars.PORT | int }}"
        target_port: "{{  env_vars.PORT | int }}"
        name: "{{ name }}"

After removing target_port, as per doc, it will use port value, it works. but after re-run playbook, it throw msg Failed to patch object: unrecognized type: int32

Why target_port type is str and port type is int ?

fabianvf commented 7 years ago

Unfortunately this is an issue with the API spec [1]. In the spec for port, the type is integer (int32), while the type of targetPort is string. We could probably work around this by adding a special case or something like that.

  1. https://kubernetes-v1-4.github.io/docs/api-reference/v1/definitions/#_v1_serviceport (this link is for an old version of kubernetes, but the kubernetes.io is having certificate errors right now so I can't get to the updated doc)
fabianvf commented 7 years ago

If you want to propose adding a special case workaround, please file the issue against https://github.com/openshift/openshift-restclient-python, where the logic for this resides.