Ejemplo n.º 1
0
def test_k8s_create_ds():
    mock = MagicMock()
    with patch('intel.k8s.extensions_client_from_config',
               MagicMock(return_value=mock)):
        k8s.create_ds(None, "test_podspec", "test_namespace")
        called_methods = mock.method_calls
        assert len(called_methods) == 1
        assert called_methods[0][0] == "create_namespaced_daemon_set"
Ejemplo n.º 2
0
def test_k8s_create_ds_apps():
    mock = MagicMock()
    with patch('intel.k8s.apps_api_client_from_config',
               MagicMock(return_value=mock)):
        k8s.create_ds(None, "test_dsspec", "test_namespace",
                      util.parse_version("v1.9.0"))
        called_methods = mock.method_calls
        assert len(called_methods) == 1
        assert called_methods[0][0] == "create_namespaced_daemon_set"
def run_cmd_pods(cmd_list, cmd_init_list, cmk_img, cmk_img_pol, conf_dir,
                 install_dir, num_exclusive_cores, num_shared_cores,
                 cmk_node_list, pull_secret, serviceaccount, shared_mode,
                 exclusive_mode, namespace):
    pod = k8s.get_pod_template()
    if pull_secret:
        update_pod_with_pull_secret(pod, pull_secret)
    if cmd_list:
        update_pod(pod, "Always", conf_dir, install_dir, serviceaccount)
        version = util.parse_version(k8s.get_kubelet_version(None))
        if version >= util.parse_version("v1.7.0"):
            pod["spec"]["tolerations"] = [{
                "operator": "Exists"}]
        for cmd in cmd_list:
            args = ""
            if cmd == "reconcile":
                args = "/cmk/cmk.py isolate --pool=infra /cmk/cmk.py -- reconcile --interval=5 --publish"  # noqa: E501
            elif cmd == "nodereport":
                args = "/cmk/cmk.py isolate --pool=infra /cmk/cmk.py -- node-report --interval=5 --publish"  # noqa: E501

            update_pod_with_container(pod, cmd, cmk_img, cmk_img_pol, args)
    elif cmd_init_list:
        update_pod(pod, "Never", conf_dir, install_dir, serviceaccount)
        for cmd in cmd_init_list:
            args = ""
            if cmd == "init":
                args = ("/cmk/cmk.py init --num-exclusive-cores={} "
                        "--num-shared-cores={} --shared-mode={} "
                        "--exclusive-mode={}")\
                    .format(num_exclusive_cores, num_shared_cores, shared_mode,
                            exclusive_mode)
                # If init is the only cmd in cmd_init_list, it should be run
                # as regular container as spec.containers is a required field.
                # Otherwise, it should be run as init-container.
                if len(cmd_init_list) == 1:
                    update_pod_with_container(pod, cmd, cmk_img,
                                              cmk_img_pol, args)
                else:
                    update_pod_with_init_container(pod, cmd, cmk_img,
                                                   cmk_img_pol, args)
            else:
                if cmd == "discover":
                    args = "/cmk/cmk.py discover"
                elif cmd == "install":
                    args = "/cmk/cmk.py install"
                update_pod_with_container(pod, cmd, cmk_img, cmk_img_pol,
                                          args)

    for node_name in cmk_node_list:
        if cmd_list:
            update_pod_with_node_details(pod, node_name, cmd_list)
            daemon_set = k8s.ds_from(pod=pod)
        elif cmd_init_list:
            update_pod_with_node_details(pod, node_name, cmd_init_list)

        try:
            if cmd_list:
                cr_pod_resp = k8s.create_ds(None, daemon_set, namespace)
                logging.debug("Response while creating ds for {} command(s): "
                              "{}".format(cmd_list, cr_pod_resp))
            elif cmd_init_list:
                cr_pod_resp = k8s.create_pod(None, pod, namespace)
                logging.debug("Response while creating pod for {} command(s): "
                              "{}".format(cmd_init_list, cr_pod_resp))
        except K8sApiException as err:
            if cmd_list:
                logging.error("Exception when creating pod for {} command(s): "
                              "{}".format(cmd_list, err))
            elif cmd_init_list:
                logging.error("Exception when creating pod for {} command(s): "
                              "{}".format(cmd_init_list, err))
            logging.error("Aborting cluster-init ...")
            sys.exit(1)