From 2377948049cf6a41ee74e5b03b33db96215fe476 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Mon, 12 Feb 2024 18:05:32 +0100 Subject: [PATCH] ADD: added name to KubePod and added the possibility to pass a shared pointer to start a pod --- include/kubecontrol/KubePod.hpp | 21 ++++++++++++++++++++- include/kubecontrol/PodController.hpp | 2 ++ src/kubecontrol/KubePod.cpp | 10 ++++++++++ src/kubecontrol/KubernetesAPI.cpp | 1 + src/kubecontrol/PodController.cpp | 12 ++++++++++++ tests/test_KubePod.cpp | 3 +++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/include/kubecontrol/KubePod.hpp b/include/kubecontrol/KubePod.hpp index d54df12..1513385 100644 --- a/include/kubecontrol/KubePod.hpp +++ b/include/kubecontrol/KubePod.hpp @@ -45,12 +45,30 @@ namespace kubecontrol void setComponent(std::string component); 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 stop(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); std::vector getUUIDsForChildPods(KubernetesAPI APIInterface); @@ -62,6 +80,7 @@ namespace kubecontrol std::string Owner_; std::string Uuid_; + std::string Name_; std::string Component_; std::string ContainerImage_; std::string ContainerRegistry_; diff --git a/include/kubecontrol/PodController.hpp b/include/kubecontrol/PodController.hpp index ce53db4..5578ca9 100644 --- a/include/kubecontrol/PodController.hpp +++ b/include/kubecontrol/PodController.hpp @@ -27,6 +27,8 @@ namespace kubecontrol std::string getServerAddress(); void startPod(KubePod Pod,bool WaitTillRunning = true ); + void startPod(std::shared_ptr Pod,bool WaitTillRunning = true ); + void stopPod(std::string uuid); void stopAllPods(); diff --git a/src/kubecontrol/KubePod.cpp b/src/kubecontrol/KubePod.cpp index 75c948d..992e527 100644 --- a/src/kubecontrol/KubePod.cpp +++ b/src/kubecontrol/KubePod.cpp @@ -136,9 +136,19 @@ namespace kubecontrol return this->Component_; } + void KubePod::setName(std::string name) + { + this->Name_ = name; + } + std::string KubePod::getName() + { + return this->Name_; + } + + std::string KubePod::createYAML() { YAML::Node node; diff --git a/src/kubecontrol/KubernetesAPI.cpp b/src/kubecontrol/KubernetesAPI.cpp index de22c75..7214ec9 100644 --- a/src/kubecontrol/KubernetesAPI.cpp +++ b/src/kubecontrol/KubernetesAPI.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include diff --git a/src/kubecontrol/PodController.cpp b/src/kubecontrol/PodController.cpp index 4b74c55..bbf6440 100644 --- a/src/kubecontrol/PodController.cpp +++ b/src/kubecontrol/PodController.cpp @@ -50,6 +50,18 @@ namespace kubecontrol // LOG_S(INFO)< Pod,bool WaitTillRunning ) + { + LOG_S(INFO)<< "starting pod: "<getUUID(); + // auto response = Pod.start(ServerAddress_+ApiCall_, BearerToken_,WaitTillRunning); + auto response = Pod->start(APIInterface_,WaitTillRunning); + + std::lock_guardlock(mx_); + PodList_.emplace_back(std::make_unique(std::move(*Pod))); + } + + void PodController::stopPod(std::string uuid) { std::lock_guardlock(mx_); diff --git a/tests/test_KubePod.cpp b/tests/test_KubePod.cpp index 0711206..771b8a6 100644 --- a/tests/test_KubePod.cpp +++ b/tests/test_KubePod.cpp @@ -20,6 +20,7 @@ SCENARIO("Testing the SimCore Sensor") std::string uuid = name; kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator"); + ShipPod1.setName(name); nlohmann::json vars; vars["ENTITY_ID"] = uuid; @@ -55,6 +56,8 @@ std::this_thread::sleep_for(std::chrono::milliseconds(5000)); THEN("check if Track attributes are correct") { REQUIRE(ShipPod1.getUUID() == "hamburg"); + REQUIRE(ShipPod1.getName() == name); + REQUIRE(ShipPod1.getComponent() == "ship"); REQUIRE(ShipPod1.getOwner() == "controller"); REQUIRE(ShipPod1.getStatus() == "Running");