Skip to content

Commit

Permalink
Set blocked state if CA is missing (#78)
Browse files Browse the repository at this point in the history
* Set blocked status if CA is missing

LP: https://bugs.launchpad.net/charm-kubernetes-master/+bug/1868541

* Handle 'blocked' status only in 'charm_status()' function

* Remove unnecessary patching
  • Loading branch information
mkalcok authored and George Kraft committed Feb 19, 2021
1 parent 246c750 commit eda05df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion reactive/kubernetes_worker.py
Expand Up @@ -34,7 +34,7 @@
from charms.reactive import endpoint_from_flag
from charms.reactive import remove_state, clear_flag
from charms.reactive import set_state, set_flag
from charms.reactive import is_state
from charms.reactive import is_state, is_flag_set
from charms.reactive import when, when_any, when_not, when_none
from charms.reactive import data_changed, is_data_changed
from charms.templating.jinja2 import render
Expand Down Expand Up @@ -418,6 +418,9 @@ def charm_status():
hookenv.status_set('blocked',
'Series upgrade in progress')
return
if not is_flag_set('certificates.available'):
hookenv.status_set('blocked', 'Missing relation to certificate authority.')
return
if not container_runtime_connected:
hookenv.status_set('blocked',
'Connect a container runtime.')
Expand Down
17 changes: 16 additions & 1 deletion tests/test_kubernetes_worker.py
@@ -1,7 +1,8 @@
import pytest
from unittest.mock import patch
from reactive import kubernetes_worker
from charms.reactive import endpoint_from_flag
from charms.reactive import endpoint_from_flag, set_flag, clear_flag
from charmhelpers.core import hookenv


def patch_fixture(patch_target):
Expand Down Expand Up @@ -47,3 +48,17 @@ def test_series_upgrade(kubectl):
assert kubectl.call_count == 2
assert kubernetes_worker.service_pause.call_count == 2
assert kubernetes_worker.service_resume.call_count == 2


def test_status_set_on_missing_ca():
"""Test that set_final_status() will set blocked state if CA is missing"""

set_flag("certificates.available")
kubernetes_worker.charm_status()
hookenv.status_set.assert_called_with('blocked',
'Connect a container runtime.')
clear_flag("certificates.available")
kubernetes_worker.charm_status()
hookenv.status_set.assert_called_with('blocked',
'Missing relation to certificate '
'authority.')

0 comments on commit eda05df

Please sign in to comment.