ADD: added name to KubePod and added the possibility to pass a shared pointer to start a pod

This commit is contained in:
Henry Winkel
2024-02-12 18:05:32 +01:00
parent 4045f21786
commit 2377948049
6 changed files with 48 additions and 1 deletions

View File

@@ -46,11 +46,29 @@ namespace kubecontrol
void setComponent(std::string component); void setComponent(std::string component);
std::string getComponent(); std::string getComponent();
/**
* @brief sets the name of the pod
* @param string - term to be displayed
*/
void setName(std::string name);
/**
* @brief return the name of the pod
* @return std::string
*/
std::string getName();
int start(KubernetesAPI APIInterface,bool WaitTillRunning = true); int start(KubernetesAPI APIInterface,bool WaitTillRunning = true);
int stop(KubernetesAPI APIInterface); int stop(KubernetesAPI APIInterface);
int stopChilds(KubernetesAPI APIInterface); int stopChilds(KubernetesAPI APIInterface);
/**
*@brief updates the infos for a pod from the give Kubernetes API
*@param KubernetesAPI - object of KubernetesAPI wich holds all necessary to perfom requests
*@return returns 1 on failure
*/
int updateInfoForThisPod(KubernetesAPI APIInterface); int updateInfoForThisPod(KubernetesAPI APIInterface);
std::vector<std::string> getUUIDsForChildPods(KubernetesAPI APIInterface); std::vector<std::string> getUUIDsForChildPods(KubernetesAPI APIInterface);
@@ -62,6 +80,7 @@ namespace kubecontrol
std::string Owner_; std::string Owner_;
std::string Uuid_; std::string Uuid_;
std::string Name_;
std::string Component_; std::string Component_;
std::string ContainerImage_; std::string ContainerImage_;
std::string ContainerRegistry_; std::string ContainerRegistry_;

View File

@@ -27,6 +27,8 @@ namespace kubecontrol
std::string getServerAddress(); std::string getServerAddress();
void startPod(KubePod Pod,bool WaitTillRunning = true ); void startPod(KubePod Pod,bool WaitTillRunning = true );
void startPod(std::shared_ptr<KubePod> Pod,bool WaitTillRunning = true );
void stopPod(std::string uuid); void stopPod(std::string uuid);
void stopAllPods(); void stopAllPods();

View File

@@ -136,9 +136,19 @@ namespace kubecontrol
return this->Component_; return this->Component_;
} }
void KubePod::setName(std::string name)
{
this->Name_ = name;
}
std::string KubePod::getName()
{
return this->Name_;
}
std::string KubePod::createYAML() std::string KubePod::createYAML()
{ {
YAML::Node node; YAML::Node node;

View File

@@ -5,6 +5,7 @@
#include <list> #include <list>
#include <curlpp/Options.hpp> #include <curlpp/Options.hpp>
#include <sstream> #include <sstream>
#include <yaml-cpp/yaml.h>
#include <loguru.hpp> #include <loguru.hpp>

View File

@@ -50,6 +50,18 @@ namespace kubecontrol
// LOG_S(INFO)<<response; // LOG_S(INFO)<<response;
} }
void PodController::startPod(std::shared_ptr<KubePod> Pod,bool WaitTillRunning )
{
LOG_S(INFO)<< "starting pod: "<<Pod->getUUID();
// auto response = Pod.start(ServerAddress_+ApiCall_, BearerToken_,WaitTillRunning);
auto response = Pod->start(APIInterface_,WaitTillRunning);
std::lock_guard<std::mutex>lock(mx_);
PodList_.emplace_back(std::make_unique<KubePod>(std::move(*Pod)));
}
void PodController::stopPod(std::string uuid) void PodController::stopPod(std::string uuid)
{ {
std::lock_guard<std::mutex>lock(mx_); std::lock_guard<std::mutex>lock(mx_);

View File

@@ -20,6 +20,7 @@ SCENARIO("Testing the SimCore Sensor")
std::string uuid = name; std::string uuid = name;
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator"); kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
ShipPod1.setName(name);
nlohmann::json vars; nlohmann::json vars;
vars["ENTITY_ID"] = uuid; vars["ENTITY_ID"] = uuid;
@@ -55,6 +56,8 @@ std::this_thread::sleep_for(std::chrono::milliseconds(5000));
THEN("check if Track attributes are correct") THEN("check if Track attributes are correct")
{ {
REQUIRE(ShipPod1.getUUID() == "hamburg"); REQUIRE(ShipPod1.getUUID() == "hamburg");
REQUIRE(ShipPod1.getName() == name);
REQUIRE(ShipPod1.getComponent() == "ship"); REQUIRE(ShipPod1.getComponent() == "ship");
REQUIRE(ShipPod1.getOwner() == "controller"); REQUIRE(ShipPod1.getOwner() == "controller");
REQUIRE(ShipPod1.getStatus() == "Running"); REQUIRE(ShipPod1.getStatus() == "Running");