k8s spec must expose ports or fails with no error

Bug #1861245 reported by Hamish
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Invalid
High
Yang Kelvin Liu

Bug Description

Developing charms with the operator framework, and juju v2.7.1

Issue:

If you don't expose ports on the container in a k8s spec then there is no error and the pod doesn't get created.

Expected:

Error if the pod won't get created.

Ideal:

Allow for containers to be created with no exposed ports

Test steps:

Without ports:

 - Charm sets spec like below.

self.framework.model.pod.set_spec({
    'containers': [{
        'name': 'no-ports-test',
        'imageDetails': {
            'imagePath': 'busybox'
        },
        'command': ['sh', '-c'],
        'args': ['while(sleep 2); do date; done'],
        'imagePullPolicy': 'IfNotPresent',
    }]
})

 - I see logs like

$ kubectl -n test-k8s logs --tail=100 -f no-ports-test-operator-0
2020-01-29 02:01:38 INFO juju-log handle_event: StartEvent
2020-01-29 02:01:39 DEBUG start Pod.set_spec {"containers": [{"name": "no-ports-test", "imageDetails": {"imagePath": "busybox"}, "command": ["sh", "-c"], "args": ["while(sleep 2); do date; done"], "imagePullPolicy": "IfNotPresent"}]}
2020-01-29 02:01:40 INFO juju-log handle_event: LeaderElectedEvent
2020-01-29 02:01:40 DEBUG leader-elected Pod.set_spec {"containers": [{"name": "no-ports-test", "imageDetails": {"imagePath": "busybox"}, "command": ["sh", "-c"], "args": ["while(sleep 2); do date; done"], "imagePullPolicy": "IfNotPresent"}]}
2020-01-29 02:01:41 INFO juju-log handle_event: ConfigChangedEvent
2020-01-29 02:01:42 DEBUG config-changed Pod.set_spec {"containers": [{"name": "no-ports-test", "imageDetails": {"imagePath": "busybox"}, "command": ["sh", "-c"], "args": ["while(sleep 2); do date; done"], "imagePullPolicy": "IfNotPresent"}]}

No more logs and the pod doesn't get created.

With ports:

 - Charm sets spec like below.

self.framework.model.pod.set_spec({
    'containers': [{
        'name': 'no-ports-test',
        'imageDetails': {
            'imagePath': 'busybox'
        },
        'command': ['sh', '-c'],
        'args': ['while(sleep 2); do date; done'],
        'imagePullPolicy': 'IfNotPresent',
        'ports': [{
            'containerPort': 80,
            'protocol': 'TCP',
        }],
    }]
})

 - I see logs like

$ kubectl -n test-k8s logs --tail=100 -f no-ports-test-operator-0
2020-01-29 02:08:10 INFO juju-log handle_event: StartEvent
2020-01-29 02:08:10 DEBUG start Pod.set_spec {"containers": [{"name": "no-ports-test", "imageDetails": {"imagePath": "busybox"}, "command": ["sh", "-c"], "args": ["while(sleep 2); do date; done"], "imagePullPolicy": "IfNotPresent", "ports": [{"containerPort": 80, "protocol": "TCP"}]}]}
2020-01-29 02:08:11 INFO juju-log handle_event: LeaderElectedEvent
2020-01-29 02:08:11 DEBUG leader-elected Pod.set_spec {"containers": [{"name": "no-ports-test", "imageDetails": {"imagePath": "busybox"}, "command": ["sh", "-c"], "args": ["while(sleep 2); do date; done"], "imagePullPolicy": "IfNotPresent", "ports": [{"containerPort": 80, "protocol": "TCP"}]}]}
2020-01-29 02:08:12 INFO juju-log handle_event: ConfigChangedEvent
2020-01-29 02:08:12 DEBUG config-changed Pod.set_spec {"containers": [{"name": "no-ports-test", "imageDetails": {"imagePath": "busybox"}, "command": ["sh", "-c"], "args": ["while(sleep 2); do date; done"], "imagePullPolicy": "IfNotPresent", "ports": [{"containerPort": 80, "protocol": "TCP"}]}]}

No more logs and the pod *DOES* get created.

Tags: k8s
Hamish (lucidone)
tags: added: k8s
Ian Booth (wallyworld)
Changed in juju:
milestone: none → 2.8-beta1
importance: Undecided → High
status: New → Triaged
Changed in juju:
status: Triaged → In Progress
assignee: nobody → Yang Kelvin Liu (kelvin.liu)
Revision history for this message
Yang Kelvin Liu (kelvin.liu) wrote :

In this case, `juju status` shows the errors.

Revision history for this message
Yang Kelvin Liu (kelvin.liu) wrote :

mariadb-k8s error 1 mariadb-k8s local 1 kubernetes ports are required for kubernetes service "mariadb-k8s"

Revision history for this message
Ian Booth (wallyworld) wrote :

If the charm requests a service be created, at least one container port is needed.
If no service is required, use serviceType "omit" in the charm metadata.

Revision history for this message
Ian Booth (wallyworld) wrote :

Marking as Invalid. Feel free to reopen if we've missed something.

Changed in juju:
status: In Progress → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.