From bc6617e10025774f9fc4467265aabfea0e432e4e Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Mon, 7 Aug 2023 17:31:23 +0200 Subject: [PATCH] ADD: add a simple working version of a pod controler class --- .gitignore | 1 + .gitmodules | 3 + CMakeLists.txt | 26 ++- config/ca.crt | 27 +++ config/config.yaml | 1 + config/pods_default.yaml | 14 ++ docs/test.json | 99 +++++++++++ include/kubecontrol/KubePod.hpp | 45 +++++ include/kubecontrol/WriterMemoryClass.hpp | 70 ++++++++ include/kubecontrol/kubecontrol.hpp | 15 +- libs/nlohmann_json | 1 + src/kubecontrol/KubePod.cpp | 185 +++++++++++++++++++ src/kubecontrol/kubecontrol.cpp | 206 +++++++++++++++++++++- tests/test_KubePod.cpp | 44 +++++ tests/test_kubecontrol.cpp | 7 +- 15 files changed, 731 insertions(+), 13 deletions(-) create mode 100644 config/ca.crt create mode 100644 config/config.yaml create mode 100644 config/pods_default.yaml create mode 100644 docs/test.json create mode 100644 include/kubecontrol/KubePod.hpp create mode 100644 include/kubecontrol/WriterMemoryClass.hpp create mode 160000 libs/nlohmann_json create mode 100644 src/kubecontrol/KubePod.cpp create mode 100644 tests/test_KubePod.cpp diff --git a/.gitignore b/.gitignore index c3f2257..d2aeed3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build .clangd compile_commands.json +.cache diff --git a/.gitmodules b/.gitmodules index 21c4e3f..e81c02d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "libs/curlcpp"] path = libs/curlcpp url = https://github.com/JosephP91/curlcpp.git +[submodule "libs/nlohmann_json"] + path = libs/nlohmann_json + url = https://github.com/nlohmann/json.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c07ef5f..9b3f5c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 3.1 FATAL_ERROR) -project (Ship VERSION 0.1.0 LANGUAGES CXX C) +project (kubecontrol VERSION 0.1.0 LANGUAGES CXX C) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) include(defaultOptions) @@ -19,6 +19,11 @@ IF(NOT TARGET Catch2) set(CLI11_TESTING OFF CACHE BOOL "disable testing") add_subdirectory(libs/CLI11 EXCLUDE_FROM_ALL) ENDIF() + + IF(NOT TARGET nlohmann_json) +set(JSON_BuildTests_INIT OFF CACHE INTERNAL "") + add_subdirectory(libs/nlohmann_json EXCLUDE_FROM_ALL) +ENDIF() IF (NOT TARGET yaml-cpp) set(YAML_CPP_BUILD_TESTS OFF CACHE INTERNAL "") @@ -45,16 +50,24 @@ ENDIF() add_library(kubecontrol STATIC + include/kubecontrol/kubecontrol.hpp src/kubecontrol/kubecontrol.cpp - ) + include/kubecontrol/KubePod.hpp + src/kubecontrol/KubePod.cpp + + include/kubecontrol/WriterMemoryClass.hpp + + ) target_link_libraries(kubecontrol yaml-cpp -curlcpp +curl +curlpp loguru +nlohmann_json pthread ) target_include_directories(kubecontrol PUBLIC @@ -64,7 +77,9 @@ target_include_directories(kubecontrol PUBLIC - + add_custom_command(TARGET kubecontrol POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/config $/config) # # Everything TEST related # @@ -78,6 +93,9 @@ IF (${TEST_KUBECONTROL_LIBRARY}) target_link_libraries(test_kubecontrol Catch2::Catch2 kubecontrol loguru) catch_discover_tests(test_kubecontrol) + add_executable(test_KubePod tests/test_KubePod.cpp) + target_link_libraries(test_KubePod Catch2::Catch2 kubecontrol loguru) + catch_discover_tests(test_KubePod) diff --git a/config/ca.crt b/config/ca.crt new file mode 100644 index 0000000..3e79282 --- /dev/null +++ b/config/ca.crt @@ -0,0 +1,27 @@ +-----BEGIN CERTIFICATE----- +MIIEozCCAwugAwIBAgIBATANBgkqhkiG9w0BAQsFADA+MRwwGgYDVQQKDBNUSS5V +TklCVy1IQU1CVVJHLkRFMR4wHAYDVQQDDBVDZXJ0aWZpY2F0ZSBBdXRob3JpdHkw +HhcNMjIwOTA4MTMyNTE2WhcNNDIwOTA4MTMyNTE2WjA+MRwwGgYDVQQKDBNUSS5V +TklCVy1IQU1CVVJHLkRFMR4wHAYDVQQDDBVDZXJ0aWZpY2F0ZSBBdXRob3JpdHkw +ggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDY1Q3atDj9YtgC1ktcGD7Y +7frSmtspbP1W+rjJr/E5/Jm83tc0nSnE9BqnzGaEF/tuAq2yJRxf+vJlgcyUkd19 +XY6+Ow8d1XJuUKuuN0P3Lq9RtdTAhhQuYU5RmuQGQ5cy+PCm6Xy4BY3j+/T4z/Tf +extD4DHsm63bNK9fRgrFIy4KtwXRlCOYSzT60jPjDArNBzYHLkFpN+U1h1cdBgYk +ynA2hiPv86X96l5aMqXCNjMR2RuksGD+tkwOamSL+YwdK0wh7Szy7B+hMX3EPMBj +6+c6VM/N84K/RoGks7eXR3I/nGPk0BBPmDlx1n86segQOFFgLC1e+ZZMHS7FRt7E +3Pa7YL/l2rocoyxq3Y1ScVue7ffCJ11kjW+kVf7XpAl23cF6yxtfn7yY9CSXIaMH +UcUeAF9hplYE9yluygWnHGJ8jQ62OB6Z6J2R8FuE9jxWtZcdpPec6TvwLbH3z4xz +nJBUvcalKC7rpagvMkiK3HR/ReQo2L6cnYTJmAyXWm8CAwEAAaOBqzCBqDAfBgNV +HSMEGDAWgBTAhqAZ30RPD9W8Dkk/fAAGWRH56zAPBgNVHRMBAf8EBTADAQH/MA4G +A1UdDwEB/wQEAwIBxjAdBgNVHQ4EFgQUwIagGd9ETw/VvA5JP3wABlkR+eswRQYI +KwYBBQUHAQEEOTA3MDUGCCsGAQUFBzABhilodHRwOi8vaXBhLWNhLnRpLnVuaWJ3 +LWhhbWJ1cmcuZGUvY2Evb2NzcDANBgkqhkiG9w0BAQsFAAOCAYEAdb89O6+MmSHM +gF2YBBQRXpuZzeWFvcDOai+mhBW5yT2a7ycQt6vL1jiGbdP8HDi0p++ELqNYoGM+ +0sCjFFM4Su6I0qUSeXAWgGip/b0Yba1zGm+fQSMqVRtlFZduAVb+sIvWciYjXY7h +VQrCkjAa8khj9dqPV1Yndx9dUR7qv4KluUNLc6SMEZ4WdGL4xGIvSc/Mp49UwP3f +p7kio88qGTygpvO6rMcfwtkvhz1rb5s1tg+c9OkPBkTSyWIzg/6sNVB2n2I3mSJz +F7fruyS6SfmgK+FWtKBvyD6htFPuBJrS9HFVHSHIgvE36xIOCWC50L1k4ZVOykoq +dhu/v4HRrGZp9AkQjMzm3bqoua62YitF5LOAQb9idz7w2b7KwwqINHti186cxsv3 +9dpMlJVPIrf9Y97YAK2aV4OdEaDjWXVjfuJ2jrqOAV9gWqUCx6AxN4kCaaZ70NIp +PtsUQZvheUOcmH/XWA+3R5iv6bFUfUYKBCagc5f7N9I+0p/OovwH +-----END CERTIFICATE----- diff --git a/config/config.yaml b/config/config.yaml new file mode 100644 index 0000000..c9f8c79 --- /dev/null +++ b/config/config.yaml @@ -0,0 +1 @@ +docker-registry: kmaster.ti.unibw-hamburg.de:30808 \ No newline at end of file diff --git a/config/pods_default.yaml b/config/pods_default.yaml new file mode 100644 index 0000000..3b50b26 --- /dev/null +++ b/config/pods_default.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Pod +metadata: + name: debug-debian + labels: + app.kubernetes.io/name: plaindebian +spec: + containers: + - name: debug-debian-container + image: kmaster.ti.unibw-hamburg.de:30808/debugdebianhenry:0.1.2 + env: + - name: OWN_SHIP_SERVER + value: "127.0.0.1" + restartPolicy: Never diff --git a/docs/test.json b/docs/test.json new file mode 100644 index 0000000..0428e5b --- /dev/null +++ b/docs/test.json @@ -0,0 +1,99 @@ +{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Pod\",\"metadata\":{\"annotations\":{},\"labels\":{\"app.kubernetes.io/name\":\"plaindebian\"},\"name\":\"debug-debian\",\"namespace\":\"hwinkel\"},\"spec\":{\"containers\":[{\"args\":[\"-c\",\"while true; do echo hello; sleep 5;done\"],\"command\":[\"/bin/sh\"],\"env\":[{\"name\":\"OWN_SHIP_SERVER\",\"value\":\"127.0.0.1\"}],\"image\":\"kmaster.ti.unibw-hamburg.de:30808/debugdebianhenry:0.1.2\",\"name\":\"debug-debian-container\"}],\"restartPolicy\":\"Never\"}}\n"}, + "creationTimestamp":"2023-08-07T09:01:18Z", + "labels":{"app.kubernetes.io/name":"plaindebian"}, + "managedFields":[ + {"apiVersion":"v1", + "fieldsType":"FieldsV1", + "fieldsV1":{ + "f:metadata":{ + "f:annotations":{ + ".":{}, + "f:kubectl.kubernetes.io/last-applied-configuration":{} + }, + "f:labels":{ + ".":{}, + "f:app.kubernetes.io/name":{} + } + }, + "f:spec":{ + "f:containers":{ + "k:{\"name\":\"debug-debian-container\"}":{ + ".":{}, + "f:args":{}, + "f:command":{}, + "f:env":{ + ".":{}, + "k:{\"name\":\"OWN_SHIP_SERVER\"}":{ + ".":{},"f:name":{},"f:value":{} + } + }, + "f:image":{}, + "f:imagePullPolicy":{}, + "f:name":{}, + "f:resources":{}, + "f:terminationMessagePath":{}, + "f:terminationMessagePolicy":{} + } + }, + "f:dnsPolicy":{}, + "f:enableServiceLinks":{}, + "f:restartPolicy":{}, + "f:schedulerName":{}, + "f:securityContext":{}, + "f:terminationGracePeriodSeconds":{} + } + }, + "manager":"kubectl-client-side-apply", + "operation":"Update", + "time":"2023-08-07T09:01:18Z" + }, + {"apiVersion":"v1", + "fieldsType":"FieldsV1", + "fieldsV1":{ + "f:status":{ + "f:conditions":{ + "k:{\"type\":\"ContainersReady\"}":{ + ".":{}, + "f:lastProbeTime":{}, + "f:lastTransitionTime":{}, + "f:status":{}, + "f:type":{} + }, + "k:{\"type\":\"Initialized\"}":{ + ".":{}, + "f:lastProbeTime":{}, + "f:lastTransitionTime":{}, + "f:status":{}, + "f:type":{} + }, + "k:{\"type\":\"Ready\"}":{ + ".":{}, + "f:lastProbeTime":{}, + "f:lastTransitionTime":{}, + "f:status":{}, + "f:type":{} + } + }, + "f:containerStatuses":{}, + "f:hostIP":{}, + "f:phase":{}, + "f:podIP":{}, + "f:podIPs":{ + ".":{}, + "k:{\"ip\":\"10.0.3.70\"}":{ + ".":{}, + "f:ip":{} + } + }, + "f:startTime":{} + } + }, + "manager":"kubelet", + "operation":"Update", + "subresource":"status", + "time":"2023-08-07T09:01:20Z"} +], +"name":"debug-debian", +"namespace":"hwinkel", +"resourceVersion":"170886884", +"uid":"f9df752e-2404-433f-b377-6e03721a5044"} \ No newline at end of file diff --git a/include/kubecontrol/KubePod.hpp b/include/kubecontrol/KubePod.hpp new file mode 100644 index 0000000..026c77a --- /dev/null +++ b/include/kubecontrol/KubePod.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace kubecontrol +{ + class KubePod + { + public: + KubePod(std::string Label, std::string Uuid, std::string ContainerImage); + + void setEnvironmentVar(std::string key, std::string val); + std::map GetEnvironmentVars(); + std::string* GetEnvironmentVar(std::string key); + + std::string createYAML(); + nlohmann::json start(std::string apiAddress,std::string token); + nlohmann::json stop(std::string apiAddress,std::string token); + nlohmann::json getInfo(std::string apiAddress,std::string token); + + + + private: + std::string Label_; + std::string Uuid_; + std::string ContainerImage_; + std::string ContainerRegistry_; + std::string PathToYaml_; + + std::map EnvirmonentVars_; + + }; +} \ No newline at end of file diff --git a/include/kubecontrol/WriterMemoryClass.hpp b/include/kubecontrol/WriterMemoryClass.hpp new file mode 100644 index 0000000..9fdbff3 --- /dev/null +++ b/include/kubecontrol/WriterMemoryClass.hpp @@ -0,0 +1,70 @@ +#pragma once +#include +#include +#include +#include + +#define MAX_FILE_LENGTH 20000 + +class WriterMemoryClass +{ +public: + // Helper Class for reading result from remote host + WriterMemoryClass() + { + this->m_pBuffer = NULL; + this->m_pBuffer = (char*) malloc(MAX_FILE_LENGTH * sizeof(char)); + this->m_Size = 0; + }; + + ~WriterMemoryClass() + { + if (this->m_pBuffer) + free(this->m_pBuffer); + }; + + void* Realloc(void* ptr, size_t size) + { + if(ptr) + return realloc(ptr, size); + else + return malloc(size); + }; + + // Callback must be declared static, otherwise it won't link... + size_t WriteMemoryCallback(char* ptr, size_t size, size_t nmemb) + { + // Calculate the real size of the incoming buffer + size_t realsize = size * nmemb; + + // (Re)Allocate memory for the buffer + m_pBuffer = (char*) Realloc(m_pBuffer, m_Size + realsize); + + // Test if Buffer is initialized correctly & copy memory + if (m_pBuffer == NULL) { + realsize = 0; + } + + memcpy(&(m_pBuffer[m_Size]), ptr, realsize); + m_Size += realsize; + + + // return the real size of the buffer... + return realsize; + }; + + std::string getResponse() + { + return m_pBuffer; + } + + void print() + { + std::cout << "Size: " << m_Size << std::endl; + std::cout << "Content: " << std::endl << m_pBuffer << std::endl; + } + + // Public member vars + char* m_pBuffer; + size_t m_Size; +}; \ No newline at end of file diff --git a/include/kubecontrol/kubecontrol.hpp b/include/kubecontrol/kubecontrol.hpp index 2b37e7c..e7a0251 100644 --- a/include/kubecontrol/kubecontrol.hpp +++ b/include/kubecontrol/kubecontrol.hpp @@ -1,14 +1,25 @@ +#pragma once #include -#include +#include namespace kubecontrol { class kubecontrol { + public: 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_; + }; } \ No newline at end of file diff --git a/libs/nlohmann_json b/libs/nlohmann_json new file mode 160000 index 0000000..5d27543 --- /dev/null +++ b/libs/nlohmann_json @@ -0,0 +1 @@ +Subproject commit 5d2754306d67d1e654a1a34e1d2e74439a9d53b3 diff --git a/src/kubecontrol/KubePod.cpp b/src/kubecontrol/KubePod.cpp new file mode 100644 index 0000000..0788382 --- /dev/null +++ b/src/kubecontrol/KubePod.cpp @@ -0,0 +1,185 @@ +#include +#include +#include +#include + +namespace kubecontrol +{ + + KubePod::KubePod(std::string Label, std::string Uuid, std::string ContainerImage):Label_(Label),Uuid_(Uuid), + ContainerImage_(ContainerImage),EnvirmonentVars_() + { + ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808"; + EnvirmonentVars_ = std::map(); + + this->PathToYaml_ = "config/pods/" + this->Label_ + ".yaml"; + + std::filesystem::directory_entry entry("config/pods"); + if(entry.exists() != true) + { + std::filesystem::create_directory("config/pods"); + } + + + } + + void KubePod::setEnvironmentVar(std::string key, std::string val) + { + EnvirmonentVars_.emplace(key,val); + } + + std::map KubePod::GetEnvironmentVars() + { + return EnvirmonentVars_; + } + + std::string* KubePod::GetEnvironmentVar(std::string key) + { + if(EnvirmonentVars_.contains(key)) { + return &EnvirmonentVars_[key]; + } else { + return nullptr; + } + } + + std::string KubePod::createYAML() + { + YAML::Node node; + + node["apiVersion"] = "v1"; + node["kind"] = "Pod"; + node["metadata"]["name"] = this->Uuid_; + node["metadata"]["labels"]["app.kubernetes.io/name"] = this->Label_; + + node["spec"]["containers"][0]["name"] = this->Label_+"-container"; + node["spec"]["containers"][0]["image"] = this->ContainerRegistry_ + "/" + this->ContainerImage_; + + int i = 0; + for (auto item :EnvirmonentVars_) { + node["spec"]["containers"][0]["env"][i]["name"] = item.first; + node["spec"]["containers"][0]["env"][i]["value"] = R"(item.second)"; + + } + + + node["spec"]["restartPolicy"] = "Never"; + + std::ofstream fout(this->PathToYaml_); + fout << node; + fout.close(); + + return this->PathToYaml_; + + } + + nlohmann::json KubePod::start(std::string apiAddress,std::string token) + { + std::string curlURL = apiAddress; + std::string AuthString = "Authorization: Bearer " + token; + + std::list headers; + headers.push_back(AuthString); + headers.push_back("Content-Type: application/yaml"); + + + curlpp::Cleanup cleaner; + curlpp::Easy request; + + WriterMemoryClass mWriterChunk; + curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); + request.setOpt(test); + + request.setOpt(new curlpp::options::HttpHeader(headers)); + + request.setOpt(new curlpp::options::Url(curlURL)); + + request.setOpt(new curlpp::options::SslVerifyPeer(false)); + + 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); + + + + request.setOpt(new curlpp::options::PostFields(buffer)); + + request.perform(); + auto response = mWriterChunk.getResponse(); + return nlohmann::json::parse(response); + } + + nlohmann::json KubePod::stop(std::string apiAddress,std::string token) + { + std::string curlURL = apiAddress+ this->Uuid_; + std::string AuthString = "Authorization: Bearer " + token; + + std::list headers; + headers.push_back(AuthString); + + + curlpp::Cleanup cleaner; + curlpp::Easy request; + + WriterMemoryClass mWriterChunk; + curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + curlpp::options::WriteFunction *writefunction = new curlpp::options::WriteFunction(functor); + request.setOpt(writefunction); + + request.setOpt(new curlpp::options::HttpHeader(headers)); + request.setOpt(new curlpp::options::Url(curlURL)); + + + request.setOpt(new curlpp::options::SslVerifyPeer(false)); + + + request.setOpt(new curlpp::options::CustomRequest("DELETE")); + // request.setOpt(new curlpp::options::Verbose(true)); + + + request.perform(); + auto response = mWriterChunk.getResponse(); + return nlohmann::json::parse(response); + } + + nlohmann::json KubePod::getInfo(std::string apiAddress,std::string token) + { + std::string curlURL = apiAddress; + std::string AuthString = "Authorization: Bearer " + token; + + std::list headers; + headers.push_back(AuthString); + + + curlpp::Cleanup cleaner; + curlpp::Easy request; + + WriterMemoryClass mWriterChunk; + + curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + + curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); + request.setOpt(test); + + request.setOpt(new curlpp::options::HttpHeader(headers)); + + request.setOpt(new curlpp::options::Url(curlURL)); + + request.setOpt(new curlpp::options::SslVerifyPeer(false)); + + + request.perform(); + auto response = mWriterChunk.getResponse(); + + return nlohmann::json::parse(response); + } + +} \ No newline at end of file diff --git a/src/kubecontrol/kubecontrol.cpp b/src/kubecontrol/kubecontrol.cpp index e25d4c7..73af23d 100644 --- a/src/kubecontrol/kubecontrol.cpp +++ b/src/kubecontrol/kubecontrol.cpp @@ -1,27 +1,221 @@ +#include "nlohmann/json_fwd.hpp" +#include "yaml-cpp/emitter.h" +#include "yaml-cpp/emitterstyle.h" +#include "yaml-cpp/node/node.h" #include -#include + +#include +#include +#include +#include + +#include + #include #include +#include + +#include + +#include +#include + namespace kubecontrol { + kubecontrol::kubecontrol(std::string pathToKubectlConfig) { - YAML::Node config = YAML::LoadFile(pathToKubectlConfig); - LOG_S(INFO)<< "test"; - curl::curl_easy easy; - easy.add("http://"); - easy.add(1L); + + BearerToken_ = config["users"][0]["user"]["token"].as(); + ServerAddress_ = config["clusters"][0]["cluster"]["server"].as(); + } void kubecontrol::getPods() { + std::string curlURL = ServerAddress_+"/api/v1/namespaces/hwinkel/pods/"; + std::string AuthString = "Authorization: Bearer " + BearerToken_; + std::list headers; + headers.push_back(AuthString); + + + curlpp::Cleanup cleaner; + curlpp::Easy request; + + WriterMemoryClass mWriterChunk; + + curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + + curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); + request.setOpt(test); + + request.setOpt(new curlpp::options::HttpHeader(headers)); + + request.setOpt(new curlpp::options::Url(curlURL)); + request.setOpt(new curlpp::options::SslEngineDefault()); + request.setOpt(new curlpp::options::CaPath("config/ca.crt")); + request.setOpt(new curlpp::options::SslVerifyPeer(false)); + + + // request.setOpt(new curlpp::options::Verbose(true)); + + + request.perform(); + auto response = mWriterChunk.getResponse(); + + + + auto j = nlohmann::json::parse(response); + LOG_S(INFO)< headers; + headers.push_back(AuthString); + headers.push_back("Content-Type: application/yaml"); + + + curlpp::Cleanup cleaner; + curlpp::Easy request; + + WriterMemoryClass mWriterChunk; + curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); + request.setOpt(test); + + request.setOpt(new curlpp::options::HttpHeader(headers)); + + request.setOpt(new curlpp::options::Url(curlURL)); + + + + request.setOpt(new curlpp::options::SslEngineDefault()); + request.setOpt(new curlpp::options::CaPath("config/ca.crt")); + request.setOpt(new curlpp::options::SslVerifyPeer(false)); + + request.setOpt(new curlpp::options::Post(true)); + + + auto yaml = createYAML(); + std::ifstream is; + is.open ("config/pods_deployment.yaml", std::ios::binary ); + + // get length of file: + is.seekg (0, std::ios::end); + long length = is.tellg(); + is.seekg (0, std::ios::beg); + + // allocate memory: + char *buffer = new char [length]; + + // read data as a block: + is.read (buffer,length); + + + std::istringstream myStream((std::string( buffer ))); + int size = myStream.str().size(); + is.close(); + + + + request.setOpt(new curlpp::options::PostFields(buffer)); + + // request.setOpt(new curlpp::options::Verbose(true)); + + + request.perform(); + auto response = mWriterChunk.getResponse(); + // LOG_S(INFO)< headers; + headers.push_back(AuthString); + // headers.push_back("Content-Type: application/yaml"); + + + curlpp::Cleanup cleaner; + curlpp::Easy request; + + WriterMemoryClass mWriterChunk; + curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); + request.setOpt(test); + + request.setOpt(new curlpp::options::HttpHeader(headers)); + + request.setOpt(new curlpp::options::Url(curlURL)); + + + + request.setOpt(new curlpp::options::SslEngineDefault()); + request.setOpt(new curlpp::options::CaPath("config/ca.crt")); + request.setOpt(new curlpp::options::SslVerifyPeer(false)); + + // request.setOpt(new curlpp::options::Post(true)); + + // request.setOpt(new curlpp::options::PostFields("DELETE")); + request.setOpt(new curlpp::options::CustomRequest("DELETE")); + // request.setOpt(new curlpp::options::Verbose(true)); + + + request.perform(); + auto response = mWriterChunk.getResponse(); + // LOG_S(INFO)< +#include + +#include +#include + + +SCENARIO("Testing the SimCore Sensor") +{ + + GIVEN("different Attributes for a Track in different forms") + { + + 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; + + std::string uuid = "random" + std::to_string(random); + + kubecontrol::KubePod pod1("debug-debian","debug-debian","debugdebianhenry:0.1.2"); + pod1.setEnvironmentVar("OWN_SHIP_SERVER", "127.0.0.1"); + LOG_S(INFO)<