ADD: added container class and adapted test
This commit is contained in:
75
include/kubecontrol/Container.hpp
Normal file
75
include/kubecontrol/Container.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <kubecontrol/Utils.hpp>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
|
||||
namespace kubecontrol
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Container
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Container object
|
||||
*
|
||||
* @param Owner
|
||||
* @param Uuid
|
||||
* @param ContainerImage
|
||||
*/
|
||||
Container(const std::string &Owner, const std::string &Uuid,const std::string &Image, const PullPolicy &policy, const std::string ®istry = "kmaster.ti.unibw-hamburg.de:30808");
|
||||
|
||||
/**
|
||||
* @brief adds env to container
|
||||
*
|
||||
* @param env
|
||||
*/
|
||||
void addEnv(const std::pair<std::string, std::string> &env);
|
||||
|
||||
/**
|
||||
* @brief add map of envs
|
||||
*
|
||||
* @param envs
|
||||
*/
|
||||
void addEnv(const std::map<std::string, std::string> &envs);
|
||||
|
||||
/**
|
||||
* @brief Get the Owner
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
std::string getOwner() { return owner_;};
|
||||
|
||||
/**
|
||||
* @brief get the uuid
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
std::string getUUID() { return uuid_;};
|
||||
|
||||
/**
|
||||
* @brief Get the Image
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
std::string getImage() { return image_;};
|
||||
|
||||
|
||||
YAML::Node toYAML();
|
||||
private:
|
||||
std::string owner_;
|
||||
std::string uuid_;
|
||||
std::string image_;
|
||||
std::string registry_;
|
||||
PullPolicy pullPolicy_;
|
||||
std::map<std::string, std::string> envs_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -17,33 +17,13 @@
|
||||
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <filesystem>
|
||||
#include <kubecontrol/Container.hpp>
|
||||
|
||||
|
||||
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;
|
||||
@@ -68,8 +48,8 @@ namespace kubecontrol
|
||||
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");
|
||||
KubePod(const std::string &Owner, const std::string &Uuid, const std::string &ContainerImage, const std::string &Namespace = "simulator") ;
|
||||
KubePod(const std::string &Owner, const std::string &Uuid, const std::string &Component, const std::string &ContainerImage, const std::string &Namespace = "simulator");
|
||||
|
||||
/**
|
||||
* @brief returns the uuid of the pod
|
||||
@@ -172,7 +152,22 @@ namespace kubecontrol
|
||||
* @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);
|
||||
void addContainer(std::string name,std::string image, std::map<std::string, std::string> &envs , kubecontrol::PullPolicy pullPolicy = ALWAYS);
|
||||
|
||||
/**
|
||||
* @brief add container object
|
||||
*
|
||||
* @param containter
|
||||
*/
|
||||
void addContainer(Container containter);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param containerUUID
|
||||
* @param envs
|
||||
*/
|
||||
void addEnvValuesToContainer(std::string containerUUID, std::map<std::string, std::string> envs);
|
||||
|
||||
/**
|
||||
* @brief sets the name of the pod
|
||||
@@ -211,7 +206,7 @@ namespace kubecontrol
|
||||
std::string Uuid_;
|
||||
std::string Name_;
|
||||
std::string Component_;
|
||||
std::vector<YAML::Node> ContainerImages_;
|
||||
std::vector<Container> ContainerImages_;
|
||||
// std::string ContainerImage_;
|
||||
std::string ContainerRegistry_;
|
||||
std::string PathToYaml_;
|
||||
|
||||
@@ -1,22 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <kubecontrol/KubePod.hpp>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace kubecontrol
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
class Utils
|
||||
{
|
||||
public:
|
||||
static std::string to_lower(std::string);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user