ADD: beautified the class and removed unnecessary class
This commit is contained in:
@@ -63,11 +63,17 @@ namespace kubecontrol
|
||||
|
||||
YAML::Node toYAML();
|
||||
private:
|
||||
/// @brief uuid of the container owner
|
||||
std::string owner_;
|
||||
/// @brief uuid of the container
|
||||
std::string uuid_;
|
||||
/// @brief image of the container
|
||||
std::string image_;
|
||||
/// @brief registry of the container
|
||||
std::string registry_;
|
||||
/// @brief pull Policy is a enum
|
||||
PullPolicy pullPolicy_;
|
||||
/// @brief environment variables
|
||||
std::map<std::string, std::string> envs_;
|
||||
|
||||
};
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <fstream>
|
||||
#include <curlpp/Easy.hpp>
|
||||
#include <curlpp/Options.hpp>
|
||||
#define LOGURU_WITH_STREAMS 1
|
||||
#include <loguru.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <filesystem>
|
||||
#include <kubecontrol/Container.hpp>
|
||||
@@ -198,32 +198,45 @@ namespace kubecontrol
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/// @brief maximum time to wait of the response when creating a pod
|
||||
static const int MaxWaitTimeInSeconds;
|
||||
|
||||
|
||||
/// @brief uuid of the owner
|
||||
std::string Owner_;
|
||||
/// @brief uuid of the pod
|
||||
std::string Uuid_;
|
||||
/// @brief name of the pod
|
||||
std::string Name_;
|
||||
/// @brief component the pod represents
|
||||
std::string Component_;
|
||||
/// @brief vector of images the pod contains
|
||||
std::vector<Container> ContainerImages_;
|
||||
// std::string ContainerImage_;
|
||||
/// @brief url of the container registry
|
||||
std::string ContainerRegistry_;
|
||||
/// @brief path to kube yaml
|
||||
std::string PathToYaml_;
|
||||
/// @brief namespace the pod is designated
|
||||
std::string Namespace_;
|
||||
|
||||
/// @brief IP of the pod
|
||||
std::string Ip_;
|
||||
/// @brief status of the pod
|
||||
std::string Status_;
|
||||
/// @brief uuid of pod this pod is part of
|
||||
std::string PartOf_;
|
||||
/// @brief vector of child pods
|
||||
std::vector<PodChild> ChildPods;
|
||||
|
||||
/// @brief command the pod schould execute when created
|
||||
std::string PodCommand_;
|
||||
|
||||
/// @brief yaml node of the pod which is used for creation
|
||||
YAML::Node YAMLNode_;
|
||||
|
||||
/// @brief environment vars of the pod
|
||||
std::map<std::string, std::string> EnvirmonentVars_;
|
||||
/// @brief arguments for the pod
|
||||
std::vector<std::string> Args_;
|
||||
|
||||
/**
|
||||
* @brief function to create the yaml string for the pod creation
|
||||
* @return std::string - returns a serialized yaml
|
||||
*/
|
||||
std::string createYAML();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include <yaml-cpp/node/node.h>
|
||||
#include <string>
|
||||
#define LOGURU_WITH_STREAMS 1
|
||||
#include <loguru.hpp>
|
||||
|
||||
|
||||
namespace kubecontrol
|
||||
@@ -10,23 +12,69 @@ class KubernetesAPI
|
||||
{
|
||||
public:
|
||||
KubernetesAPI();
|
||||
/**
|
||||
* constructor of the Kubernetes API
|
||||
* @param config - yaml node of the designated users kubectl yaml
|
||||
*/
|
||||
explicit KubernetesAPI(YAML::Node config);
|
||||
|
||||
/**
|
||||
* @brief costructor of Kuernetes API object
|
||||
*/
|
||||
KubernetesAPI(std::string APIAddress, std::string Token);
|
||||
|
||||
/**
|
||||
* @brief performs a request to the kubernetes API
|
||||
* @param request - string of the request
|
||||
* @param Methode - string (eg. GET, POST)
|
||||
* @result string - respone of the requestS
|
||||
*/
|
||||
std::string performRequest(std::string request,std::string Methode = "GET");
|
||||
|
||||
/**
|
||||
* @brief performs a request to the kubernetes API
|
||||
* @param request - string of the request
|
||||
* @param Methode - string (eg. GET, POST)
|
||||
* @param PostFields - string of the post fields which are sended in the request
|
||||
* @return string - respone of the requestS
|
||||
*/
|
||||
std::string performRequest(std::string request,std::string Methode,std::string PostFields);
|
||||
|
||||
/**
|
||||
* @brief adds address of the kubernetes api
|
||||
* @param address - string
|
||||
*/
|
||||
void addAddress(std::string address);
|
||||
|
||||
/**
|
||||
* @brief returns the address of the kubrnetes api stored in the object
|
||||
* @return std::string returns the address
|
||||
*/
|
||||
std::string getAddress();
|
||||
|
||||
/**
|
||||
* @brief add the bearer token which is necessary to access the api
|
||||
* @param Token - string
|
||||
*/
|
||||
void addToken(std::string Token);
|
||||
|
||||
/**
|
||||
* @brief adds the yaml node which is required to hold all necessary data to access the api
|
||||
* @param conifg - YAML::Node object of the parsed file
|
||||
*/
|
||||
void addYaml(YAML::Node config);
|
||||
|
||||
/**
|
||||
* @brief returns the namespace the object uses
|
||||
* @return string
|
||||
*/
|
||||
std::string getNamespace();
|
||||
private:
|
||||
/// @brief api adress
|
||||
std::string APIAddress_;
|
||||
/// @brief bearer token
|
||||
std::string Token_;
|
||||
/// @brief namespace
|
||||
std::string Namespace_;
|
||||
|
||||
};
|
||||
|
||||
@@ -14,32 +14,77 @@ namespace kubecontrol
|
||||
class PodController
|
||||
{
|
||||
public:
|
||||
explicit PodController(std::string pathToKubectlConfig);
|
||||
/**
|
||||
* @brief constructs the podcontroller
|
||||
* @param pathToKubectlConfig - string path to the kubectl config file
|
||||
*/
|
||||
explicit PodController(std::string pathToKubectlConfig);
|
||||
|
||||
/**
|
||||
* @brief returns the Server Address of the given kubernetes api
|
||||
* @return string
|
||||
*/
|
||||
std::string getServerAddress();
|
||||
|
||||
std::string getServerAddress();
|
||||
/**
|
||||
* @brief starts a pod
|
||||
* @param Pod - pod objet
|
||||
* @param WaitTillRunning - bool (default: true) indicates if the controller should wait till the pod is startet
|
||||
*/
|
||||
void startPod(KubePod Pod,bool WaitTillRunning = true );
|
||||
|
||||
/**
|
||||
* @brief starts a pod
|
||||
* @param Pod - std::shared_ptr<KubePod> objet
|
||||
* @param WaitTillRunning - bool (default: true) indicates if the controller should wait till the pod is startet
|
||||
*/
|
||||
void startPod(std::shared_ptr<KubePod> Pod,bool WaitTillRunning = true );
|
||||
|
||||
void startPod(KubePod Pod,bool WaitTillRunning = true );
|
||||
void startPod(std::shared_ptr<KubePod> Pod,bool WaitTillRunning = true );
|
||||
/**
|
||||
* @brief stops a pod referenced by its uuid
|
||||
* @param uuid - string
|
||||
*/
|
||||
void stopPod(std::string uuid);
|
||||
|
||||
void stopPod(std::string uuid);
|
||||
void stopAllPods();
|
||||
/**
|
||||
* @brief stops all pods the controller knows
|
||||
*/
|
||||
void stopAllPods();
|
||||
|
||||
std::vector<PodInfos> getInfoForAllPods();
|
||||
PodInfos getInfoForPod(std::string uuid);
|
||||
/**
|
||||
* @brief returns a vector of PodInfos of all pod
|
||||
* @return std::vector<PodInfos>
|
||||
*/
|
||||
std::vector<PodInfos> getInfoForAllPods();
|
||||
|
||||
KubernetesAPI getKubernetesAPI();
|
||||
/**
|
||||
* @brief returns a PodInfo object of a specific pod
|
||||
* @param uuid - string
|
||||
* @return PodInfo
|
||||
*/
|
||||
PodInfos getInfoForPod(std::string uuid);
|
||||
|
||||
/**
|
||||
* @brief retursn a copy of ne current used kubernetes API
|
||||
*/
|
||||
KubernetesAPI getKubernetesAPI();
|
||||
|
||||
private:
|
||||
KubernetesAPI APIInterface_;
|
||||
std::vector<std::unique_ptr<KubePod>> PodList_;
|
||||
/// @brief object of the kubernetes api object
|
||||
KubernetesAPI APIInterface_;
|
||||
/// @brief vector of unique poitners of owned KubePod objects
|
||||
std::vector<std::unique_ptr<KubePod>> PodList_;
|
||||
/// @brief current namespace
|
||||
std::string Namespace_;
|
||||
/// @brief base apiCall (default: "/api/v1/namespaces/Simulator/pods/")
|
||||
std::string ApiCall_;
|
||||
/**
|
||||
* @brief gets infos for specific pod
|
||||
*/
|
||||
PodInfos extractInfosFromKubePod(KubePod *pod);
|
||||
|
||||
std::string Namespace_;
|
||||
std::string ApiCall_;
|
||||
|
||||
PodInfos extractInfosFromKubePod(KubePod *pod);
|
||||
|
||||
|
||||
mutable std::mutex mx_;
|
||||
/// @brief mutex
|
||||
mutable std::mutex mx_;
|
||||
|
||||
};
|
||||
} // namespace ku
|
||||
|
||||
@@ -8,15 +8,17 @@ namespace kubecontrol
|
||||
{
|
||||
|
||||
|
||||
enum PullPolicy: uint32_t
|
||||
enum PullPolicy: uint32_t
|
||||
{
|
||||
ALWAYS,
|
||||
IFNOTPRESENT,
|
||||
NEVER
|
||||
};
|
||||
|
||||
|
||||
inline std::string toString(const PullPolicy &kind)
|
||||
/**
|
||||
* @brief translate PullPolicy enum to string
|
||||
*/
|
||||
inline std::string toString(const PullPolicy &kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
@@ -29,7 +31,10 @@ namespace kubecontrol
|
||||
|
||||
class Utils
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* @brief lowercase a string
|
||||
*/
|
||||
static std::string to_lower(std::string);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
namespace kubecontrol
|
||||
{
|
||||
class kubecontrol
|
||||
{
|
||||
|
||||
public:
|
||||
explicit kubecontrol(std::string &pathToKubectlConfig);
|
||||
void getPods();
|
||||
void startPod();
|
||||
void deletePod(std::string uid);
|
||||
std::string createYAML();
|
||||
|
||||
|
||||
private:
|
||||
std::string BearerToken_;
|
||||
std::string ServerAddress_;
|
||||
std::string NameSpace_;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user