Exemple #1
0
def test_client_is_independent_of_pykube_incluster(login_mocks, no_pykube,
                                                   kubernetes):
    with pytest.deprecated_call(match=r"cease using kopf.login\(\)"):
        login()

    assert login_mocks.client_in_cluster.called
    assert not login_mocks.client_from_file.called
Exemple #2
0
def test_pykube_login_works_viaconfig(login_mocks, pykube):
    login_mocks.pykube_in_cluster.side_effect = FileNotFoundError

    login()

    assert login_mocks.pykube_in_cluster.called
    assert login_mocks.pykube_from_file.called
Exemple #3
0
def test_monkeypatched_get_pykube_cfg_overrides_pykube(mocker, login_mocks):
    get_pykube_cfg = mocker.patch('kopf.clients.auth.get_pykube_cfg')
    get_pykube_cfg.return_value = pykube.KubeConfig({
        'current-context':
        'self',
        'contexts': [{
            'name': 'self',
            'context': {
                'cluster': 'self'
            }
        }],
        'clusters': [{
            'name': 'self',
            'cluster': {
                'server': 'https://localhost'
            }
        }],
    })

    with pytest.deprecated_call(match=r"cease using kopf.login\(\)"):
        login()

    assert get_pykube_cfg.called
    assert not login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called
Exemple #4
0
def test_client_login_works_viaconfig(login_mocks, kubernetes):
    login_mocks.client_in_cluster.side_effect = kubernetes.config.ConfigException

    login()

    assert login_mocks.client_in_cluster.called
    assert login_mocks.client_from_file.called
Exemple #5
0
def main(steps=3):
    kopf.login()

    # Start the operator and let it initialise.
    print(f"Starting the main app.")
    ready_flag = threading.Event()
    stop_flag = threading.Event()
    thread = threading.Thread(target=kopf_thread,
                              kwargs=dict(
                                  stop_flag=stop_flag,
                                  ready_flag=ready_flag,
                              ))
    thread.start()
    ready_flag.wait()

    # The operator is active: run the app's activity.
    for step in range(steps):
        print(f"Do the main app activity here. Step {step+1}/{steps}.")
        _create_object(step)
        time.sleep(1.0)
        _delete_object(step)
        time.sleep(1.0)

    # Ask the operator to terminate gracefully (can take a couple of seconds).
    print(f"Exiting the main app.")
    stop_flag.set()
    thread.join()
Exemple #6
0
def test_pykube_login_works_viaconfig(login_mocks, pykube):
    login_mocks.pykube_in_cluster.side_effect = FileNotFoundError

    with pytest.deprecated_call(match=r"cease using kopf.login\(\)"):
        login()

    assert login_mocks.pykube_in_cluster.called
    assert login_mocks.pykube_from_file.called
Exemple #7
0
def test_client_login_works_viaconfig(login_mocks, kubernetes):
    login_mocks.client_in_cluster.side_effect = kubernetes.config.ConfigException

    with pytest.deprecated_call(match=r"cease using kopf.login\(\)"):
        login()

    assert login_mocks.client_in_cluster.called
    assert login_mocks.client_from_file.called
Exemple #8
0
def test_client_is_independent_of_pykube_viaconfig(login_mocks, no_pykube,
                                                   kubernetes):
    login_mocks.client_in_cluster.side_effect = kubernetes.config.ConfigException

    login()

    assert login_mocks.client_in_cluster.called
    assert login_mocks.client_from_file.called
Exemple #9
0
def test_pykube_is_independent_of_client_viaconfig(login_mocks, no_kubernetes,
                                                   pykube):
    login_mocks.pykube_in_cluster.side_effect = FileNotFoundError

    login()

    assert login_mocks.pykube_in_cluster.called
    assert login_mocks.pykube_from_file.called
Exemple #10
0
def kopf_thread(
    ready_flag: threading.Event,
    stop_flag: threading.Event,
):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    kopf.configure(verbose=True)  # log formatting
    kopf.login()  # tokens & certs

    loop.run_until_complete(
        kopf.operator(
            ready_flag=ready_flag,
            stop_flag=stop_flag,
        ))
Exemple #11
0
def test_pykube_login_works_incluster(login_mocks, pykube):
    with pytest.deprecated_call(match=r"cease using kopf.login\(\)"):
        login()

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called
Exemple #12
0
def test_client_login_works_incluster(login_mocks, kubernetes):
    login()

    assert login_mocks.client_in_cluster.called
    assert not login_mocks.client_from_file.called
Exemple #13
0
def test_client_is_independent_of_pykube_incluster(login_mocks, no_pykube,
                                                   kubernetes):
    login()

    assert login_mocks.client_in_cluster.called
    assert not login_mocks.client_from_file.called
Exemple #14
0
def test_pykube_login_works_incluster(login_mocks, pykube):
    login()

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called