ADD: added more extracted details for a child pod and changed the data type for the child information

This commit is contained in:
Henry Winkel
2024-03-12 18:08:55 +01:00
parent 263aaa6a71
commit 48101a673a
7 changed files with 161 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
#include "curlpp/Options.hpp"
#include "kubecontrol/PodController.hpp"
#include "kubecontrol/Utils.hpp"
#include "nlohmann/json_fwd.hpp"
#include "yaml-cpp/binary.h"
@@ -76,7 +77,7 @@ namespace kubecontrol
void KubePod::addContainer(std::string name,std::string image, std::shared_ptr<std::map<std::string, std::string>> envs, std::string PullPolicy )
void KubePod::addContainer(std::string name,std::string image, std::shared_ptr<std::map<std::string, std::string>> envs, PullPolicy pullPolicy )
{
YAML::Node container;
transform(image.begin(), image.end(), image.begin(), ::tolower);
@@ -84,7 +85,7 @@ namespace kubecontrol
container["name"] = name+"-container";
container["image"] = this->ContainerRegistry_ + "/" + image;
container["imagePullPolicy"] = PullPolicy;
container["imagePullPolicy"] = toString(pullPolicy);
if (envs != nullptr)
{
@@ -303,14 +304,14 @@ namespace kubecontrol
int KubePod::stopChilds(KubernetesAPI APIInterface)
{
auto uuids = this->getUUIDsForChildPods(APIInterface);
auto uuids = this->getPodsChilds(APIInterface);
if (uuids.size() == 0)
{
return 1;
}
for(auto i: uuids)
{
std::string request = "/api/v1/namespaces/simulator/pods/"+i;
std::string request = "/api/v1/namespaces/simulator/pods/"+i.UUID;
std::string result = APIInterface.performRequest(request,"DELETE");
}
@@ -338,18 +339,18 @@ namespace kubecontrol
}
std::vector<std::string> KubePod::getUUIDsForChildPods( KubernetesAPI APIInterface)
std::vector<PodChild> KubePod::getPodsChilds( KubernetesAPI APIInterface)
{
std::string request = "/api/v1/namespaces/simulator/pods?labelSelector=app.kubernetes.io/part-of="+Uuid_;
std::string result = APIInterface.performRequest(request,"GET");
if (result == "")
{
return std::vector<std::string>();
return std::vector<PodChild>();
}
extractInformationFromResopnse(result);
return this->uuidsOfShildContainers;
return this->ChildPods;
}
@@ -372,10 +373,17 @@ namespace kubecontrol
}else if(j.contains("items") && j["items"].is_array())
{
{
for (auto i : j["items"])
{
this->uuidsOfShildContainers.push_back(i["metadata"]["name"].get<std::string>());
// LOG_S(INFO)<<i;
PodChild child;
child.UUID =i["metadata"]["name"].get<std::string>();
child.IP = i["status"]["podIP"].get<std::string>();
child.Status = i["status"]["phase"].get<std::string>();
child.Component = i["metadata"]["labels"]["app.kubernetes.io/component"].get<std::string>();
this->ChildPods.push_back(child);
}
}else{