Files
KubeControl/include/kubecontrol/PodController.hpp

91 lines
2.6 KiB
C++

#pragma once
#include "kubecontrol/KubernetesAPI.hpp"
#include <cstddef>
#include <kubecontrol/KubePod.hpp>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace kubecontrol
{
class PodController
{
public:
/**
* @brief constructs the podcontroller
* @param pathToKubectlConfig - string path to the kubectl config file
*/
explicit PodController(std::string pathToKubectlConfig);
/**
* @brief returns the Server Address of the given kubernetes api
* @return string
*/
std::string getServerAddress();
/**
* @brief starts a pod
* @param Pod - pod objet
* @param WaitTillRunning - bool (default: true) indicates if the controller should wait till the pod is startet
*/
void startPod(KubePod Pod,bool WaitTillRunning = true );
/**
* @brief starts a pod
* @param Pod - std::shared_ptr<KubePod> objet
* @param WaitTillRunning - bool (default: true) indicates if the controller should wait till the pod is startet
*/
void startPod(std::shared_ptr<KubePod> Pod,bool WaitTillRunning = true );
/**
* @brief stops a pod referenced by its uuid
* @param uuid - string
*/
void stopPod(std::string uuid);
/**
* @brief stops all pods the controller knows
*/
void stopAllPods();
/**
* @brief returns a vector of PodInfos of all pod
* @return std::vector<PodInfos>
*/
std::vector<PodInfos> getInfoForAllPods();
/**
* @brief returns a PodInfo object of a specific pod
* @param uuid - string
* @return PodInfo
*/
PodInfos getInfoForPod(std::string uuid);
/**
* @brief retursn a copy of ne current used kubernetes API
*/
KubernetesAPI getKubernetesAPI();
private:
/// @brief object of the kubernetes api object
KubernetesAPI APIInterface_;
/// @brief vector of unique poitners of owned KubePod objects
std::vector<std::unique_ptr<KubePod>> PodList_;
/// @brief current namespace
std::string Namespace_;
/// @brief base apiCall (default: "/api/v1/namespaces/Simulator/pods/")
std::string ApiCall_;
/**
* @brief gets infos for specific pod
*/
PodInfos extractInfosFromKubePod(KubePod *pod);
/// @brief mutex
mutable std::mutex mx_;
};
} // namespace ku