ADD: added setting of namespace in to KubePod class

This commit is contained in:
Henry Winkel
2023-09-27 09:20:04 +02:00
parent 5d3dcb25db
commit f95542b893
2 changed files with 10 additions and 6 deletions

View File

@@ -26,8 +26,8 @@ namespace kubecontrol
class KubePod class KubePod
{ {
public: public:
KubePod(std::string Owner, std::string Uuid, std::string ContainerImage); KubePod(std::string Owner, std::string Uuid, std::string ContainerImage,std::string Namespace = "simulator");
KubePod(std::string Owner, std::string Uuid, std::string Component, std::string ContainerImage); KubePod(std::string Owner, std::string Uuid, std::string Component, std::string ContainerImage,std::string Namespace = "simulator");
std::string getUUID(); std::string getUUID();
std::string getOwner(); std::string getOwner();
@@ -62,6 +62,7 @@ namespace kubecontrol
std::string ContainerImage_; std::string ContainerImage_;
std::string ContainerRegistry_; std::string ContainerRegistry_;
std::string PathToYaml_; std::string PathToYaml_;
std::string Namespace_;
std::string PodCommand_; std::string PodCommand_;

View File

@@ -22,8 +22,8 @@ namespace kubecontrol
KubePod::KubePod(std::string Owner, std::string Uuid, std::string ContainerImage):Owner_(Utils::to_lower(Owner)),Uuid_(Utils::to_lower(Uuid)), KubePod::KubePod(std::string Owner, std::string Uuid, std::string ContainerImage,std::string Namespace):Owner_(Utils::to_lower(Owner)),Uuid_(Utils::to_lower(Uuid)),
ContainerImage_(ContainerImage),EnvirmonentVars_() ContainerImage_(ContainerImage),Namespace_(Namespace),EnvirmonentVars_()
{ {
ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808"; ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808";
EnvirmonentVars_ = std::map<std::string, std::string>(); EnvirmonentVars_ = std::map<std::string, std::string>();
@@ -42,8 +42,8 @@ namespace kubecontrol
} }
KubePod::KubePod(std::string Owner, std::string Uuid, std::string Component, std::string ContainerImage):Owner_(Utils::to_lower(Owner)), KubePod::KubePod(std::string Owner, std::string Uuid, std::string Component, std::string ContainerImage,std::string Namespace):Owner_(Utils::to_lower(Owner)),
Uuid_(Utils::to_lower(Uuid)),Component_(Utils::to_lower(Component)), ContainerImage_(ContainerImage),EnvirmonentVars_() Uuid_(Utils::to_lower(Uuid)),Component_(Utils::to_lower(Component)), ContainerImage_(ContainerImage),Namespace_(Namespace),EnvirmonentVars_()
{ {
ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808"; ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808";
EnvirmonentVars_ = std::map<std::string, std::string>(); EnvirmonentVars_ = std::map<std::string, std::string>();
@@ -133,6 +133,7 @@ namespace kubecontrol
node["apiVersion"] = "v1"; node["apiVersion"] = "v1";
node["kind"] = "Pod"; node["kind"] = "Pod";
node["metadata"]["name"] = this->Uuid_; node["metadata"]["name"] = this->Uuid_;
node["metadata"]["namespace"] = this->Namespace_;
node["metadata"]["labels"]["app.kubernetes.io/name"] = this->Uuid_; node["metadata"]["labels"]["app.kubernetes.io/name"] = this->Uuid_;
node["metadata"]["labels"]["app.kubernetes.io/part-of"] = this->Owner_; node["metadata"]["labels"]["app.kubernetes.io/part-of"] = this->Owner_;
@@ -143,6 +144,8 @@ namespace kubecontrol
node["spec"]["containers"][0]["name"] = this->Uuid_+"-container"; node["spec"]["containers"][0]["name"] = this->Uuid_+"-container";
node["spec"]["containers"][0]["image"] = this->ContainerRegistry_ + "/" + this->ContainerImage_; node["spec"]["containers"][0]["image"] = this->ContainerRegistry_ + "/" + this->ContainerImage_;
node["spec"]["containers"][0]["imagePullPolicy"] = "Always"; node["spec"]["containers"][0]["imagePullPolicy"] = "Always";
node["spec"]["containers"][0]["ports"][0]["containerPort"] = 10000;
node["spec"]["containers"][0]["ports"][0]["protocol"] = "UDP";
int i = 0; int i = 0;
for (auto item :EnvirmonentVars_) { for (auto item :EnvirmonentVars_) {