Exemple #1
0
    def cleanup(self):
        if self.active is False:
            return
        self.active = False
        # TODO: run cmk uninstallation here, when it's ready.
        # https://github.com/intelsdi-x/CPU-Manager-for-Kubernetes/pull/81
        for node in self.nodes:
            k8s.unset_node_label(self.configuration, node, "namespace")

        self.nodes = []
        k8s.delete_namespace(self.configuration, self.ns_name)

        timeout_destination = int(time.time()) + self.timeout
        while True:
            if int(time.time()) >= timeout_destination:
                raise Exception("Timeout after {} ".format(self.timeout) +
                                "seconds on waiting removing namespace.")

            namespaces = k8s.get_namespaces(self.configuration)["items"]
            namespaces_list = list(
                map(lambda ns: ns["metadata"]["name"], namespaces))

            if self.ns_name not in namespaces_list:
                break
            time.sleep(1)
Exemple #2
0
def test_k8s_unset_label():
    mock = MagicMock()

    with patch('intel.k8s.client_from_config', MagicMock(return_value=mock)):
        k8s.unset_node_label(None, "fakenode1", "foo")
        called_methods = mock.method_calls
        assert len(called_methods) == 1
        assert called_methods[0][0] == "patch_node"
        params = called_methods[0][1]
        assert params[0] == "fakenode1"
        assert params[1][0]["op"] == "remove"
        assert params[1][0]["path"] == "/metadata/labels/foo"