diff --git a/.gitignore b/.gitignore index d2aeed3..9a846af 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build .clangd compile_commands.json .cache +.vscode diff --git a/.gitmodules b/.gitmodules index e81c02d..60d7618 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "libs/nlohmann_json"] path = libs/nlohmann_json url = https://github.com/nlohmann/json.git +[submodule "libs/crossguid"] + path = libs/crossguid + url = https://github.com/graeme-hill/crossguid.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b3f5c5..bc4d392 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ IF(NOT TARGET Catch2) add_compile_definitions(LOGURU_WITH_STREAMS SQLITE_THREADSAFE=2) IF(NOT TARGET loguru) + set(LOGURU_STACKTRACES 0 CACHE BOOL "disable testing") add_subdirectory(libs/loguru EXCLUDE_FROM_ALL) ENDIF() @@ -40,6 +41,10 @@ ENDIF() add_subdirectory(libs/curlcpp EXCLUDE_FROM_ALL) ENDIF() + IF(NOT TARGET crossguid) + set(CROSSGUID_TESTS OFF CACHE INTERNAL "") + add_subdirectory(libs/crossguid EXCLUDE_FROM_ALL) + ENDIF() # IF (NOT TARGET rest-client) # set(BUILD_SHARED_LIBS OFF CACHE BOOL "disable testing") # add_subdirectory(libs/rest-client EXCLUDE_FROM_ALL) @@ -57,12 +62,16 @@ ENDIF() include/kubecontrol/KubePod.hpp src/kubecontrol/KubePod.cpp + include/kubecontrol/PodController.hpp + src/kubecontrol/PodController.cpp + include/kubecontrol/WriterMemoryClass.hpp ) target_link_libraries(kubecontrol +crossguid yaml-cpp curl curlpp @@ -90,13 +99,16 @@ IF (${TEST_KUBECONTROL_LIBRARY}) 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) 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) + add_executable(test_podcontroller tests/test_podcontroller.cpp) + target_link_libraries(test_podcontroller Catch2::Catch2 kubecontrol ) + catch_discover_tests(test_podcontroller) ENDIF() diff --git a/include/kubecontrol/KubePod.hpp b/include/kubecontrol/KubePod.hpp index 026c77a..7acbc57 100644 --- a/include/kubecontrol/KubePod.hpp +++ b/include/kubecontrol/KubePod.hpp @@ -20,6 +20,8 @@ namespace kubecontrol { public: KubePod(std::string Label, std::string Uuid, std::string ContainerImage); + std::string getUUID(); + std::string getLabel(); void setEnvironmentVar(std::string key, std::string val); std::map GetEnvironmentVars(); diff --git a/include/kubecontrol/PodController.hpp b/include/kubecontrol/PodController.hpp new file mode 100644 index 0000000..dccd467 --- /dev/null +++ b/include/kubecontrol/PodController.hpp @@ -0,0 +1,24 @@ +#pragma once +#include + +namespace kubecontrol +{ + class PodController + { + public: + PodController(std::string pathToKubectlConfig); + + std::string getServerAddress(); + + void startPod(KubePod Pod); + void stopAllPods(); + + private: + std::vector PodList; + + std::string BearerToken_; + std::string ServerAddress_; + std::string ApiCall_; + + }; +} // namespace ku diff --git a/include/kubecontrol/WriterMemoryClass.hpp b/include/kubecontrol/WriterMemoryClass.hpp index 9fdbff3..629082d 100644 --- a/include/kubecontrol/WriterMemoryClass.hpp +++ b/include/kubecontrol/WriterMemoryClass.hpp @@ -4,7 +4,7 @@ #include #include -#define MAX_FILE_LENGTH 20000 +#define MAX_FILE_LENGTH 200000 class WriterMemoryClass { diff --git a/libs/crossguid b/libs/crossguid new file mode 160000 index 0000000..ca1bf4b --- /dev/null +++ b/libs/crossguid @@ -0,0 +1 @@ +Subproject commit ca1bf4b810e2d188d04cb6286f957008ee1b7681 diff --git a/src/kubecontrol/KubePod.cpp b/src/kubecontrol/KubePod.cpp index 0788382..c6c64bd 100644 --- a/src/kubecontrol/KubePod.cpp +++ b/src/kubecontrol/KubePod.cpp @@ -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) { EnvirmonentVars_.emplace(key,val); @@ -99,14 +109,17 @@ namespace kubecontrol request.setOpt(new curlpp::options::Post(true)); - - std::ifstream is; - is.open (this->PathToYaml_, std::ios::binary ); - is.seekg (0, std::ios::end); - long length = is.tellg(); - is.seekg (0, std::ios::beg); - char *buffer = new char [length]; - is.read (buffer,length); + if(std::filesystem::exists(this->PathToYaml_) != true) + { + this->createYAML(); + } + std::ifstream is; + is.open (this->PathToYaml_, std::ios::binary ); + is.seekg (0, std::ios::end); + 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(); auto response = mWriterChunk.getResponse(); - return nlohmann::json::parse(response); } diff --git a/src/kubecontrol/PodController.cpp b/src/kubecontrol/PodController.cpp new file mode 100644 index 0000000..0824628 --- /dev/null +++ b/src/kubecontrol/PodController.cpp @@ -0,0 +1,22 @@ + +#include + + +namespace kubecontrol +{ + PodController::PodController(std::string pathToKubectlConfig) + { + YAML::Node config = YAML::LoadFile(pathToKubectlConfig); + + BearerToken_ = config["users"][0]["user"]["token"].as(); + ServerAddress_ = config["clusters"][0]["cluster"]["server"].as(); + ApiCall_ = "/api/v1/namespaces/hwinkel/pods/"; + } + + std::string PodController::getServerAddress() + { + return this->ServerAddress_; + } + + +} \ No newline at end of file diff --git a/tests/test_KubePod.cpp b/tests/test_KubePod.cpp index d59eccb..4b56595 100644 --- a/tests/test_KubePod.cpp +++ b/tests/test_KubePod.cpp @@ -4,7 +4,7 @@ #include #include - +#include 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 token = "eyJhbGciOiJSUzI1NiIsImtpZCI6InJwN2R3a2NEWHJva0ptLVNFUnAxMnUxNEF3VUdmdURRTmw5VWZuM0NCZ3MifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJod2lua2VsIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Imh3aW5rZWwtc2VjcmV0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6Imh3aW5rZWwiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJmNDNkNTc5NS1lNDFhLTQxOTYtODVkMS01YmNkZGIxNzFkYjkiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6aHdpbmtlbDpod2lua2VsIn0.TQCBkEIY0sEQjpy-3BP1SdXl94Ct-oAeD4VGNEOJEzDYBuU4Cn1fG32k2wAIgZemh6P-DcBhPk0VtCWCLYhWWwIe6FNo3FpqOxcDbu8QHlyD-Y3VnfSzKRHg9OKgUSWnc_Z5P9iBtilNQxnZp_wLOBW6TL8ZeECxeVtBBxUpYfoywSWS7mNpwxHcecP_U__LUU1tP7pYZ8OgDiSIH04CaTrQisTL-FGdcqOEYQhx4zoOyVQFWWYkfjG9oD-5zjtS29O0gckfvKLOu2y_K6RVR51szsquiJiHP1s_AcS-qq1-rXRqEpYRsLxRxr-dflL3aAjnLlPSYCwheQhjCa0fjQ"; - - int random = rand() % 100 + 1; + auto guid = xg::newGuid(); + std::string uuid = guid.str(); + // 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","debug-debian","debugdebianhenry:0.1.2"); + kubecontrol::KubePod pod1("debug-debian",uuid,"debugdebianhenry:0.1.2"); pod1.setEnvironmentVar("OWN_SHIP_SERVER", "127.0.0.1"); LOG_S(INFO)< + +#include + + +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 \ No newline at end of file