ADD: added Util class with the function to lowercase the vals for yaml and added support of setting args and command

This commit is contained in:
Henry Winkel
2023-08-09 10:23:50 +02:00
parent 39f0f2b4eb
commit bda06c285b
6 changed files with 96 additions and 8 deletions

View File

@@ -1,10 +1,11 @@
#include "kubecontrol/Utils.hpp"
#include <kubecontrol/KubePod.hpp>
namespace kubecontrol
{
KubePod::KubePod(std::string Label, std::string Uuid, std::string ContainerImage):Label_(Label),Uuid_(Uuid),
KubePod::KubePod(std::string Label, std::string Uuid, std::string ContainerImage):Label_(Utils::to_lower(Label)),Uuid_(Uuid),
ContainerImage_(ContainerImage),EnvirmonentVars_()
{
ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808";
@@ -45,15 +46,37 @@ namespace kubecontrol
return EnvirmonentVars_;
}
std::string* KubePod::GetEnvironmentVar(std::string key)
std::string KubePod::GetEnvironmentVar(std::string key)
{
if(EnvirmonentVars_.contains(key)) {
return &EnvirmonentVars_[key];
return EnvirmonentVars_[key];
} else {
return nullptr;
}
}
void KubePod::setArgs(std::string args)
{
Args_.emplace_back(Utils::to_lower(args));
}
std::vector<std::string> KubePod::GetArgs()
{
return Args_;
}
void KubePod::setCommand(std::string command)
{
PodCommand_ = Utils::to_lower(command);
}
std::string KubePod::getCommand()
{
return PodCommand_;
}
std::string KubePod::createYAML()
{
YAML::Node node;
@@ -71,9 +94,18 @@ namespace kubecontrol
for (auto item :EnvirmonentVars_) {
node["spec"]["containers"][0]["env"][i]["name"] = item.first;
node["spec"]["containers"][0]["env"][i]["value"] = item.second;
}
node["spec"]["containers"][0]["args"].SetStyle(YAML::EmitterStyle::Flow);
for (auto item : Args_) {
node["spec"]["containers"][0]["args"].push_back(item);
}
node["spec"]["containers"][0]["command"].SetStyle(YAML::EmitterStyle::Flow);
node["spec"]["containers"][0]["command"].push_back(PodCommand_);
node["spec"]["restartPolicy"] = "Never";

21
src/kubecontrol/Utils.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <kubecontrol/Utils.hpp>
namespace kubecontrol
{
std::string Utils::to_lower(std::string str)
{
std::string data = str;
std::for_each(
data.begin(),
data.end(),
[](char & c) {
c = ::tolower(c);
});
return data;
}
}