saltstack / saltstack/salt

[BUG] 3000.2 kubernetes.service_present fails on Kubernetes python client version 11.0

Open
#59,758 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug k8s-modules severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description

Every time I run state.apply with kubernetes.service_present it gives me error:
ValueError: Invalid value for `port`, must not be `None`

Setup

tomcat-test.sls

Create tomcat internal service for namespace tomcat:
  kubernetes.service_present:
    - name: tai-tomcat-service-internal
    - kubeconfig: /root/kubeconfig_salt
    - context: default
    - namespace: tomcat
      metadata:
        name: tai-tomcat-service-internal
        labels:
          run: tai-app-service
      spec:
        selector:
          run: tai-app-service
        type: ClusterIP
        ports:
        - name: tai-tomcat-service
          protocol: TCP
          port: 8080
          targetPort: 8080

Steps to Reproduce the behavior

root@dev:/srv/salt/kubernetes# salt mytest state.apply kubernetes.tomcat-test
mytest:
----------
          ID: Create tai-tomcat internal service tai for namespace tomcat
    Function: kubernetes.service_present
        Name: tai-tomcat-service-internal
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3.6/site-packages/salt/state.py", line 1981, in call
                  **cdata['kwargs'])
                File "/usr/lib/python3.6/site-packages/salt/loader.py", line 1977, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/states/kubernetes.py", line 312, in service_present
                  **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/modules/kubernetesmod.py", line 1072, in create_service
                  saltenv=saltenv)
                File "/usr/lib/python3.6/site-packages/salt/modules/kubernetesmod.py", line 1466, in __create_object_body
                  spec=spec_creator(spec))
                File "/usr/lib/python3.6/site-packages/salt/modules/kubernetesmod.py", line 1574, in __dict_to_service_spec
                  kube_port = kubernetes.client.V1ServicePort()
                File "/usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1_service_port.py", line 63, in __init__
                  self.port = port
                File "/usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1_service_port.py", line 136, in port
                  raise ValueError("Invalid value for `port`, must not be `None`")  # noqa: E501
              ValueError: Invalid value for `port`, must not be `None`
     Started: 16:53:16.407060
    Duration: 23.525 ms
     Changes:
----------

I suspect the method __dict_to_service_spec(spec) on kubernetesmod.py would need to pass the port number into the constructor kube_port = kubernetes.client.V1ServicePort()

https://github.com/kubernetes-client/python/blame/master/kubernetes/client/models/v1_service_port.py

Expected behavior

From the issue seen on https://github.com/kubernetes-client/python/issues/1199 the codes might need to be refactored as kube_port = kubernetes.client.V1ServicePort(port=port)

Versions Report

Salt Version:
           Salt: 3000.2

Dependency Versions:
           cffi: 1.14.0
       cherrypy: Not Installed
       dateutil: 2.8.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
       M2Crypto: 0.33.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: 2.20
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug  7 2019, 17:28:10)
   python-gnupg: Not Installed
         PyYAML: 5.3.1
          PyZMQ: 15.3.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.4.1708 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-1062.18.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.4.1708 Core

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in salt/modules/kubernetesmod.py at __dict_to_service_spec and follow the service_present path shown in the traceback. Reproduce the provided state.apply example with Kubernetes Python client 11.0, then verify that the service definition's port is accepted and the service is created successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
kubernetes, python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.