ADD: added podinfo with building a tree hierarchy for a pod

This commit is contained in:
Henry Winkel
2023-08-16 14:42:00 +02:00
parent 6c2f8f1eb6
commit 89465f06a5
8 changed files with 474 additions and 48 deletions

View File

@@ -6,6 +6,7 @@
#include <kubecontrol/KubePod.hpp>
#include <sstream>
#include <string>
#include <thread>
namespace kubecontrol
@@ -166,7 +167,7 @@ namespace kubecontrol
node["spec"]["containers"][0]["command"].push_back(PodCommand_);
}
node["spec"]["terminationGracePeriodSeconds"] = 3;
node["spec"]["restartPolicy"] = "Never";
@@ -209,23 +210,10 @@ namespace kubecontrol
request.setOpt(new curlpp::options::CustomRequest("POST"));
// request.setOpt(new curlpp::options::Verbose("POST"));
this->createYAML();
LOG_S(ERROR)<< this->PathToYaml_;
std::ifstream is;
is.open (this->PathToYaml_, std::ios::binary | std::ios::ate);
is.seekg (0, std::ios::end);
long length = is.tellg();
is.seekg (0, std::ios::beg);
char *buffer = new char [length];
is.read(buffer,length);
is.close();
std::stringstream stream;
stream << YAMLNode_;
// request.setOpt(new curlpp::options::PostFields(buffer));
@@ -236,7 +224,16 @@ namespace kubecontrol
request.reset();
auto response = mWriterChunk.getResponse();
return nlohmann::json::parse(response).dump();
PodInfo.update(response);
while (PodInfo.Status != "Running") {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
response = this->getInfo(curlURL, token);
PodInfo.update(response);
}
return response;
}
std::string KubePod::stop(std::string apiAddress,std::string token)
@@ -269,12 +266,61 @@ namespace kubecontrol
request.perform();
auto response = mWriterChunk.getResponse();
return nlohmann::json::parse(response).dump();
LOG_S(INFO)<<PodInfo.getRelatedPods().size();
if (PodInfo.getRelatedPods().size() > 0)
{
for(int i = 0; i<PodInfo.getRelatedPods().size(); i++)
{
StopChilds(apiAddress, token, PodInfo.getRelatedPods()[i]);
}
}
return response;
}
std::string KubePod::StopChilds(std::string apiAddress,std::string token,std::string uuid)
{
std::string curlURL = apiAddress+ uuid;
std::string AuthString = "Authorization: Bearer " + token;
std::list<std::string> headers;
headers.push_back(AuthString);
curlpp::Cleanup cleaner;
curlpp::Easy request;
WriterMemoryClass mWriterChunk;
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
curlpp::options::WriteFunction *writefunction = new curlpp::options::WriteFunction(functor);
request.setOpt(writefunction);
request.setOpt(new curlpp::options::HttpHeader(headers));
request.setOpt(new curlpp::options::Url(curlURL));
request.setOpt(new curlpp::options::SslVerifyPeer(false));
request.setOpt(new curlpp::options::CustomRequest("DELETE"));
// request.setOpt(new curlpp::options::Verbose(true));
request.perform();
auto response = mWriterChunk.getResponse();
return response;
}
std::string KubePod::getInfo(std::string apiAddress,std::string token)
{
std::string curlURL = apiAddress+"/"+Uuid_;
std::string curlURL = apiAddress+Uuid_+"/"+"status";
std::string AuthString = "Authorization: Bearer " + token;
std::list<std::string> headers;
@@ -296,11 +342,11 @@ namespace kubecontrol
request.setOpt(new curlpp::options::Url(curlURL));
request.setOpt(new curlpp::options::SslVerifyPeer(false));
request.perform();
auto response = mWriterChunk.getResponse();
return nlohmann::json::parse(response).dump();
return response;
}