ADD: added guid usage to identify a pod
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ build
|
|||||||
.clangd
|
.clangd
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.cache
|
.cache
|
||||||
|
.vscode
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -10,3 +10,6 @@
|
|||||||
[submodule "libs/nlohmann_json"]
|
[submodule "libs/nlohmann_json"]
|
||||||
path = libs/nlohmann_json
|
path = libs/nlohmann_json
|
||||||
url = https://github.com/nlohmann/json.git
|
url = https://github.com/nlohmann/json.git
|
||||||
|
[submodule "libs/crossguid"]
|
||||||
|
path = libs/crossguid
|
||||||
|
url = https://github.com/graeme-hill/crossguid.git
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ IF(NOT TARGET Catch2)
|
|||||||
|
|
||||||
add_compile_definitions(LOGURU_WITH_STREAMS SQLITE_THREADSAFE=2)
|
add_compile_definitions(LOGURU_WITH_STREAMS SQLITE_THREADSAFE=2)
|
||||||
IF(NOT TARGET loguru)
|
IF(NOT TARGET loguru)
|
||||||
|
set(LOGURU_STACKTRACES 0 CACHE BOOL "disable testing")
|
||||||
add_subdirectory(libs/loguru EXCLUDE_FROM_ALL)
|
add_subdirectory(libs/loguru EXCLUDE_FROM_ALL)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
@@ -40,6 +41,10 @@ ENDIF()
|
|||||||
add_subdirectory(libs/curlcpp EXCLUDE_FROM_ALL)
|
add_subdirectory(libs/curlcpp EXCLUDE_FROM_ALL)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
IF(NOT TARGET crossguid)
|
||||||
|
set(CROSSGUID_TESTS OFF CACHE INTERNAL "")
|
||||||
|
add_subdirectory(libs/crossguid EXCLUDE_FROM_ALL)
|
||||||
|
ENDIF()
|
||||||
# IF (NOT TARGET rest-client)
|
# IF (NOT TARGET rest-client)
|
||||||
# set(BUILD_SHARED_LIBS OFF CACHE BOOL "disable testing")
|
# set(BUILD_SHARED_LIBS OFF CACHE BOOL "disable testing")
|
||||||
# add_subdirectory(libs/rest-client EXCLUDE_FROM_ALL)
|
# add_subdirectory(libs/rest-client EXCLUDE_FROM_ALL)
|
||||||
@@ -57,12 +62,16 @@ ENDIF()
|
|||||||
include/kubecontrol/KubePod.hpp
|
include/kubecontrol/KubePod.hpp
|
||||||
src/kubecontrol/KubePod.cpp
|
src/kubecontrol/KubePod.cpp
|
||||||
|
|
||||||
|
include/kubecontrol/PodController.hpp
|
||||||
|
src/kubecontrol/PodController.cpp
|
||||||
|
|
||||||
include/kubecontrol/WriterMemoryClass.hpp
|
include/kubecontrol/WriterMemoryClass.hpp
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(kubecontrol
|
target_link_libraries(kubecontrol
|
||||||
|
crossguid
|
||||||
yaml-cpp
|
yaml-cpp
|
||||||
curl
|
curl
|
||||||
curlpp
|
curlpp
|
||||||
@@ -90,13 +99,16 @@ IF (${TEST_KUBECONTROL_LIBRARY})
|
|||||||
|
|
||||||
|
|
||||||
add_executable(test_kubecontrol tests/test_kubecontrol.cpp)
|
add_executable(test_kubecontrol tests/test_kubecontrol.cpp)
|
||||||
target_link_libraries(test_kubecontrol Catch2::Catch2 kubecontrol loguru)
|
target_link_libraries(test_kubecontrol Catch2::Catch2 kubecontrol )
|
||||||
catch_discover_tests(test_kubecontrol)
|
catch_discover_tests(test_kubecontrol)
|
||||||
|
|
||||||
add_executable(test_KubePod tests/test_KubePod.cpp)
|
add_executable(test_KubePod tests/test_KubePod.cpp)
|
||||||
target_link_libraries(test_KubePod Catch2::Catch2 kubecontrol loguru)
|
target_link_libraries(test_KubePod Catch2::Catch2 kubecontrol )
|
||||||
catch_discover_tests(test_KubePod)
|
catch_discover_tests(test_KubePod)
|
||||||
|
|
||||||
|
add_executable(test_podcontroller tests/test_podcontroller.cpp)
|
||||||
|
target_link_libraries(test_podcontroller Catch2::Catch2 kubecontrol )
|
||||||
|
catch_discover_tests(test_podcontroller)
|
||||||
|
|
||||||
|
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ namespace kubecontrol
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KubePod(std::string Label, std::string Uuid, std::string ContainerImage);
|
KubePod(std::string Label, std::string Uuid, std::string ContainerImage);
|
||||||
|
std::string getUUID();
|
||||||
|
std::string getLabel();
|
||||||
|
|
||||||
void setEnvironmentVar(std::string key, std::string val);
|
void setEnvironmentVar(std::string key, std::string val);
|
||||||
std::map<std::string, std::string> GetEnvironmentVars();
|
std::map<std::string, std::string> GetEnvironmentVars();
|
||||||
|
|||||||
24
include/kubecontrol/PodController.hpp
Normal file
24
include/kubecontrol/PodController.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <kubecontrol/KubePod.hpp>
|
||||||
|
|
||||||
|
namespace kubecontrol
|
||||||
|
{
|
||||||
|
class PodController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PodController(std::string pathToKubectlConfig);
|
||||||
|
|
||||||
|
std::string getServerAddress();
|
||||||
|
|
||||||
|
void startPod(KubePod Pod);
|
||||||
|
void stopAllPods();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<KubePod> PodList;
|
||||||
|
|
||||||
|
std::string BearerToken_;
|
||||||
|
std::string ServerAddress_;
|
||||||
|
std::string ApiCall_;
|
||||||
|
|
||||||
|
};
|
||||||
|
} // namespace ku
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define MAX_FILE_LENGTH 20000
|
#define MAX_FILE_LENGTH 200000
|
||||||
|
|
||||||
class WriterMemoryClass
|
class WriterMemoryClass
|
||||||
{
|
{
|
||||||
|
|||||||
1
libs/crossguid
Submodule
1
libs/crossguid
Submodule
Submodule libs/crossguid added at ca1bf4b810
@@ -23,6 +23,16 @@ namespace kubecontrol
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string KubePod::getUUID()
|
||||||
|
{
|
||||||
|
return this->Uuid_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string KubePod::getLabel()
|
||||||
|
{
|
||||||
|
return this->Label_;
|
||||||
|
}
|
||||||
|
|
||||||
void KubePod::setEnvironmentVar(std::string key, std::string val)
|
void KubePod::setEnvironmentVar(std::string key, std::string val)
|
||||||
{
|
{
|
||||||
EnvirmonentVars_.emplace(key,val);
|
EnvirmonentVars_.emplace(key,val);
|
||||||
@@ -99,14 +109,17 @@ namespace kubecontrol
|
|||||||
request.setOpt(new curlpp::options::Post(true));
|
request.setOpt(new curlpp::options::Post(true));
|
||||||
|
|
||||||
|
|
||||||
|
if(std::filesystem::exists(this->PathToYaml_) != true)
|
||||||
std::ifstream is;
|
{
|
||||||
is.open (this->PathToYaml_, std::ios::binary );
|
this->createYAML();
|
||||||
is.seekg (0, std::ios::end);
|
}
|
||||||
long length = is.tellg();
|
std::ifstream is;
|
||||||
is.seekg (0, std::ios::beg);
|
is.open (this->PathToYaml_, std::ios::binary );
|
||||||
char *buffer = new char [length];
|
is.seekg (0, std::ios::end);
|
||||||
is.read (buffer,length);
|
long length = is.tellg();
|
||||||
|
is.seekg (0, std::ios::beg);
|
||||||
|
char *buffer = new char [length];
|
||||||
|
is.read (buffer,length);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -178,7 +191,6 @@ namespace kubecontrol
|
|||||||
|
|
||||||
request.perform();
|
request.perform();
|
||||||
auto response = mWriterChunk.getResponse();
|
auto response = mWriterChunk.getResponse();
|
||||||
|
|
||||||
return nlohmann::json::parse(response);
|
return nlohmann::json::parse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
src/kubecontrol/PodController.cpp
Normal file
22
src/kubecontrol/PodController.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#include <kubecontrol/PodController.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace kubecontrol
|
||||||
|
{
|
||||||
|
PodController::PodController(std::string pathToKubectlConfig)
|
||||||
|
{
|
||||||
|
YAML::Node config = YAML::LoadFile(pathToKubectlConfig);
|
||||||
|
|
||||||
|
BearerToken_ = config["users"][0]["user"]["token"].as<std::string>();
|
||||||
|
ServerAddress_ = config["clusters"][0]["cluster"]["server"].as<std::string>();
|
||||||
|
ApiCall_ = "/api/v1/namespaces/hwinkel/pods/";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PodController::getServerAddress()
|
||||||
|
{
|
||||||
|
return this->ServerAddress_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
#include <kubecontrol/KubePod.hpp>
|
#include <kubecontrol/KubePod.hpp>
|
||||||
|
#include <crossguid/guid.hpp>
|
||||||
|
|
||||||
SCENARIO("Testing the SimCore Sensor")
|
SCENARIO("Testing the SimCore Sensor")
|
||||||
{
|
{
|
||||||
@@ -14,12 +14,13 @@ SCENARIO("Testing the SimCore Sensor")
|
|||||||
|
|
||||||
std::string api = "https://192.168.252.5:6443/api/v1/namespaces/hwinkel/pods/";
|
std::string api = "https://192.168.252.5:6443/api/v1/namespaces/hwinkel/pods/";
|
||||||
std::string token = "eyJhbGciOiJSUzI1NiIsImtpZCI6InJwN2R3a2NEWHJva0ptLVNFUnAxMnUxNEF3VUdmdURRTmw5VWZuM0NCZ3MifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJod2lua2VsIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Imh3aW5rZWwtc2VjcmV0Iiwia3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lNDFhLTQxOTYtODVkMS01YmNkZGIxNzFkYjkiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6aHdpbmtlbDpod2lua2VsIn0.TQCBkEIY0sEQjpy-3BP1SdXl94Ct-oAeD4VGNEOJEzDYBuU4Cn1fG32k2wAIgZemh6P-DcBhPk0VtCWCLYhWWwIe6FNo3FpqOxcDbu8QHlyD-Y3VnfSzKRHg9OKgUSWnc_Z5P9iBtilNQxnZp_wLOBW6TL8ZeECxeVtBBxUpYfoywSWS7mNpwxHcecP_U__LUU1tP7pYZ8OgDiSIH04CaTrQisTL-FGdcqOEYQhx4zoOyVQFWWYkfjG9oD-5zjtS29O0gckfvKLOu2y_K6RVR51szsquiJiHP1s_AcS-qq1-rXRqEpYRsLxRxr-dflL3aAjnLlPSYCwheQhjCa0fjQ";
|
||||||
|
auto guid = xg::newGuid();
|
||||||
|
std::string uuid = guid.str();
|
||||||
|
// int random = rand() % 100 + 1;
|
||||||
|
|
||||||
int random = rand() % 100 + 1;
|
// std::string uuid = "random" + std::to_string(random);
|
||||||
|
|
||||||
std::string uuid = "random" + std::to_string(random);
|
kubecontrol::KubePod pod1("debug-debian",uuid,"debugdebianhenry:0.1.2");
|
||||||
|
|
||||||
kubecontrol::KubePod pod1("debug-debian","debug-debian","debugdebianhenry:0.1.2");
|
|
||||||
pod1.setEnvironmentVar("OWN_SHIP_SERVER", "127.0.0.1");
|
pod1.setEnvironmentVar("OWN_SHIP_SERVER", "127.0.0.1");
|
||||||
LOG_S(INFO)<<pod1.createYAML();
|
LOG_S(INFO)<<pod1.createYAML();
|
||||||
|
|
||||||
|
|||||||
31
tests/test_podcontroller.cpp
Normal file
31
tests/test_podcontroller.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
#include <kubecontrol/PodController.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
SCENARIO("Testing the SimCore Sensor")
|
||||||
|
{
|
||||||
|
kubecontrol::PodController podc("../docs/config");
|
||||||
|
|
||||||
|
GIVEN("different Attributes for a Track in different forms")
|
||||||
|
{
|
||||||
|
LOG_S(INFO)<< podc.getServerAddress();
|
||||||
|
WHEN("constructing Track Object with data")
|
||||||
|
{
|
||||||
|
|
||||||
|
THEN("check if Track attributes are correct")
|
||||||
|
{
|
||||||
|
REQUIRE(true == true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} //THEN
|
||||||
|
} // WHEN
|
||||||
|
} // GIVEN
|
||||||
|
} //SCENARIO
|
||||||
Reference in New Issue
Block a user