ADD: added function to podcontroller to get number of childpods

This commit is contained in:
Henry Winkel
2023-12-21 09:15:33 +01:00
parent 05ca44efe7
commit d1024de907
2 changed files with 14 additions and 1 deletions

View File

@@ -1,7 +1,9 @@
#pragma once
#include "kubecontrol/PodInfo.hpp"
#include <cstddef>
#include <kubecontrol/KubePod.hpp>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
@@ -21,6 +23,7 @@ namespace kubecontrol
std::string getPodsInfo();
std::string getInfoForOwnPod();
std::string getInfoForPod(std::string Label);
size_t getListOfChildPods();
void checkPodsHierarchy();
@@ -43,6 +46,7 @@ namespace kubecontrol
std::shared_ptr<PodInfo> getPodInfo(std::string uuid);
std::vector<std::shared_ptr<PodInfo>> podsInfoList_;
mutable std::mutex mx_;
};
} // namespace ku

View File

@@ -75,8 +75,10 @@ namespace kubecontrol
void PodController::stopAllPods()
{
checkPodsHierarchy();
for (auto item : PodList_)
{
LOG_S(INFO)<<item.InfoPod.Uuid;
item.InfoPod = *getPodInfo(item.getUUID()).get();
item.stop(ServerAddress_+ApiCall_, BearerToken_);
LOG_S(INFO)<< "stopping pod: "<<item.getUUID();
@@ -181,10 +183,12 @@ namespace kubecontrol
j = nlohmann::json::parse(response);
if (j.contains("items"))
{
LOG_S(INFO)<<j["items"].size();
int i = j["items"].size();
for (int a = 0; a<i; a++)
{
auto item = std::make_shared<PodInfo>(j["items"][a].dump());
auto item = std::make_unique<PodInfo>(j["items"][a].dump());
// LOG_S(INFO)<<item->ToString();
// item->Uuid = j["items"][a]["metadata"]["labels"]["app.kubernetes.io/name"].get<std::string>();
// item->Component = j["items"][a]["metadata"]["labels"]["app.kubernetes.io/component"].get<std::string>();
// item->Image = j["items"][a]["spec"]["containers"][0]["image"].get<std::string>();
@@ -281,6 +285,11 @@ namespace kubecontrol
return nullptr;
}
size_t PodController::getListOfChildPods()
{
return PodList_.size();
}
std::string PodController::performRequest(std::string curlURL)