ADD: added more extracted details for a child pod and changed the data type for the child information

This commit is contained in:
Henry Winkel
2024-03-12 18:08:55 +01:00
parent 263aaa6a71
commit 48101a673a
7 changed files with 161 additions and 26 deletions

View File

@@ -4,6 +4,7 @@
#include "nlohmann/json_fwd.hpp"
#include "yaml-cpp/node/node.h"
#include <map>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
@@ -24,33 +25,157 @@
namespace kubecontrol
{
enum PullPolicy: uint32_t
{
ALWAYS,
IFNOTPRESENT,
NEVER
};
inline std::string toString(const PullPolicy &kind)
{
switch (kind)
{
case PullPolicy::ALWAYS: return "Always";
case PullPolicy::IFNOTPRESENT: return "IfNotPresent";
case PullPolicy::NEVER: return "Never";
default: return "Always";
}
}
struct PodChild
{
std::string UUID;
std::string IP;
std::string Component;
std::string Status;
};
struct PodInfos
{
std::string UUID;
std::string IP;
std::string Status;
std::string Component;
std::string Owner;
std::vector<PodChild> Childs;
};
class KubePod
{
public:
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,std::string Namespace = "simulator");
/**
* @brief returns the uuid of the pod
*
* @return std::string
*/
std::string getUUID();
/**
* @brief Get the Owner of the pods
*
* @return std::string
*/
std::string getOwner();
/**
* @brief Get the Ip of the pod
*
* @return std::string
*/
std::string getIp();
/**
* @brief Get the Status
*
* @return std::string
*/
std::string getStatus();
/**
* @brief Set the Environment Vars for pod
*
* @param key
* @param val
*/
void setEnvironmentVar(std::string key, std::string val);
/**
* @brief Get the Environment Vars
*
* @return std::map<std::string, std::string>
*/
std::map<std::string, std::string> GetEnvironmentVars();
/**
* @brief Get the Environment Var for a specific key
*
* @param key std::string
* @return std::string
*/
std::string GetEnvironmentVar(std::string key);
/**
* @brief Set CMD args
*
* @param args
*/
void setArgs(std::string args);
std::vector<std::string> GetArgs();
/**
* @brief Get the Args
*
* @return std::vector<std::string>
*/
std::vector<std::string> GetArgs();
/**
* @brief Set the Command for a pod
*
* @param command
*/
void setCommand(std::string command);
/**
* @brief Get the Command
*
* @return std::string
*/
std::string getCommand();
/**
* @brief Set the Component var for the pod
*
* @param component
*/
void setComponent(std::string component);
/**
* @brief Get the Component var
*
* @return std::string
*/
std::string getComponent();
void addContainer(std::string name,std::string image, std::shared_ptr<std::map<std::string, std::string>> envs = nullptr, std::string PullPolicy = "Always");
/**
* @brief add a Container to a pod
*
* @param name std::string
* @param image std::string
* @param envs std::map<std::string,std:.string>
* @param PullPolicy std::string (defualt: Always) possible:( IfNotPresent, Never)
*/
void addContainer(std::string name,std::string image, std::shared_ptr<std::map<std::string, std::string>> envs = nullptr, PullPolicy pullPolicy = ALWAYS);
/**
* @brief sets the name of the pod
@@ -77,7 +202,7 @@ namespace kubecontrol
*/
int updateInfoForThisPod(KubernetesAPI APIInterface);
std::vector<std::string> getUUIDsForChildPods(KubernetesAPI APIInterface);
std::vector<PodChild> getPodsChilds(KubernetesAPI APIInterface);
private:
@@ -98,7 +223,7 @@ namespace kubecontrol
std::string Ip_;
std::string Status_;
std::string PartOf_;
std::vector<std::string> uuidsOfShildContainers;
std::vector<PodChild> ChildPods;
std::string PodCommand_;

View File

@@ -10,15 +10,7 @@
namespace kubecontrol
{
struct PodInfos
{
std::string UUID;
std::string IP;
std::string Status;
std::string Component;
std::string Owner;
std::vector<std::string> UUIDOfChilds;
};
class PodController
{
public: