ADD: added a podcontroller and test for the first basic usage

This commit is contained in:
Henry Winkel
2023-08-08 15:09:18 +02:00
parent 1c4c883648
commit 5f043ca88e
13 changed files with 196 additions and 192 deletions

View File

@@ -63,11 +63,12 @@ namespace kubecontrol
node["spec"]["containers"][0]["name"] = this->Label_+"-container";
node["spec"]["containers"][0]["image"] = this->ContainerRegistry_ + "/" + this->ContainerImage_;
node["spec"]["containers"][0]["imagePullPolicy"] = "Always";
int i = 0;
for (auto item :EnvirmonentVars_) {
node["spec"]["containers"][0]["env"][i]["name"] = item.first;
node["spec"]["containers"][0]["env"][i]["value"] = R"(item.second)";
node["spec"]["containers"][0]["env"][i]["value"] = item.second;
}
@@ -82,7 +83,7 @@ namespace kubecontrol
}
nlohmann::json KubePod::start(std::string apiAddress,std::string token)
std::string KubePod::start(std::string apiAddress,std::string token)
{
std::string curlURL = apiAddress;
std::string AuthString = "Authorization: Bearer " + token;
@@ -109,28 +110,30 @@ namespace kubecontrol
request.setOpt(new curlpp::options::Post(true));
if(std::filesystem::exists(this->PathToYaml_) != true)
{
this->createYAML();
}
std::ifstream is;
is.open (this->PathToYaml_, std::ios::binary );
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);
this->createYAML();
LOG_S(ERROR)<< this->PathToYaml_;
std::ifstream is;
is.open (this->PathToYaml_, std::ios::binary );
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();
request.setOpt(new curlpp::options::PostFields(buffer));
request.perform();
request.reset();
auto response = mWriterChunk.getResponse();
return nlohmann::json::parse(response);
return nlohmann::json::parse(response).dump();
}
nlohmann::json KubePod::stop(std::string apiAddress,std::string token)
std::string KubePod::stop(std::string apiAddress,std::string token)
{
std::string curlURL = apiAddress+ this->Uuid_;
std::string AuthString = "Authorization: Bearer " + token;
@@ -160,12 +163,12 @@ namespace kubecontrol
request.perform();
auto response = mWriterChunk.getResponse();
return nlohmann::json::parse(response);
return nlohmann::json::parse(response).dump();
}
nlohmann::json KubePod::getInfo(std::string apiAddress,std::string token)
std::string KubePod::getInfo(std::string apiAddress,std::string token)
{
std::string curlURL = apiAddress;
std::string curlURL = apiAddress+"/"+Uuid_;
std::string AuthString = "Authorization: Bearer " + token;
std::list<std::string> headers;
@@ -191,7 +194,7 @@ namespace kubecontrol
request.perform();
auto response = mWriterChunk.getResponse();
return nlohmann::json::parse(response);
return nlohmann::json::parse(response).dump();
}
}