ADD: added updated drone.yml and changed some function calls

This commit is contained in:
Henry Winkel
2024-03-13 16:41:56 +01:00
parent 48101a673a
commit 0e05106d1e
13 changed files with 264 additions and 231 deletions

View File

@@ -6,6 +6,7 @@ steps:
- name: build
image: kmaster.ti.unibw-hamburg.de:30808/debianbullseye
commands:
- git submodule update --init --recursive --jobs=4
- mkdir -p build && cd build
- CC=clang-11 CXX=clang++-11 cmake -DCMAKE_BUILD_TYPE=DEBUG ..
- make -j

11
.gitattributes vendored Normal file
View File

@@ -0,0 +1,11 @@
# Set the default behavior for all files.
* text=auto eol=lf
# Normalized and converts to native line endings on checkout.
*.c text
*.cc text
*.cxx
*.cpp text
*.h text
*.hxx text
*.hpp text

5
.gitignore vendored
View File

@@ -4,3 +4,8 @@ compile_commands.json
.cache
.vscode
config/pods
.github
.clang*
.cmake-format*
.pre-commit*
.editorconfig

View File

@@ -1,6 +1,6 @@
#pragma once
#include "kubecontrol/KubernetesAPI.hpp"
#include <kubecontrol/KubernetesAPI.hpp>
#include "nlohmann/json_fwd.hpp"
#include "yaml-cpp/node/node.h"
#include <map>
@@ -17,9 +17,6 @@
#include <curlpp/cURLpp.hpp>
#include <filesystem>
#include <map>
#include <vector>
namespace kubecontrol
@@ -55,7 +52,6 @@ namespace kubecontrol
std::string Status;
};
struct PodInfos
{
std::string UUID;
@@ -68,11 +64,12 @@ 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(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");
/**
* @brief returns the uuid of the pod
@@ -130,7 +127,7 @@ namespace kubecontrol
*
* @param args
*/
void setArgs(std::string args);
void setArgs(std::string &args);
/**
* @brief Get the Args
@@ -144,7 +141,7 @@ namespace kubecontrol
*
* @param command
*/
void setCommand(std::string command);
void setCommand(std::string &command);
/**
* @brief Get the Command
@@ -158,7 +155,7 @@ namespace kubecontrol
*
* @param component
*/
void setComponent(std::string component);
void setComponent(std::string &component);
/**
* @brief Get the Component var
@@ -181,7 +178,7 @@ namespace kubecontrol
* @brief sets the name of the pod
* @param string - term to be displayed
*/
void setName(std::string name);
void setName(std::string &name);
/**
* @brief return the name of the pod

View File

@@ -10,7 +10,7 @@ class KubernetesAPI
{
public:
KubernetesAPI();
KubernetesAPI(YAML::Node config);
explicit KubernetesAPI(YAML::Node config);
KubernetesAPI(std::string APIAddress, std::string Token);

View File

@@ -14,7 +14,7 @@ namespace kubecontrol
class PodController
{
public:
PodController(std::string pathToKubectlConfig);
explicit PodController(std::string pathToKubectlConfig);
std::string getServerAddress();

View File

@@ -8,7 +8,7 @@ namespace kubecontrol
{
public:
kubecontrol(std::string pathToKubectlConfig);
explicit kubecontrol(std::string &pathToKubectlConfig);
void getPods();
void startPod();
void deletePod(std::string uid);

View File

@@ -1,5 +1,6 @@
#include <kubecontrol/PodController.hpp>
#include "curlpp/Options.hpp"
#include "kubecontrol/PodController.hpp"
#include "kubecontrol/Utils.hpp"
#include "nlohmann/json_fwd.hpp"
#include "yaml-cpp/binary.h"
@@ -22,24 +23,27 @@
namespace kubecontrol
{
KubePod::KubePod(std::string Owner, std::string Uuid, std::string ContainerImage,std::string Namespace)
KubePod::KubePod(std::string &Owner, std::string &Uuid, std::string &ContainerImage,std::string Namespace)
:Owner_(Utils::to_lower(Owner)),
Uuid_(Utils::to_lower(Uuid)),
Namespace_(Namespace),
EnvirmonentVars_()
ContainerRegistry_("kmaster.ti.unibw-hamburg.de:30808"),
Namespace_(Namespace)
{
ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808";
EnvirmonentVars_ = std::map<std::string, std::string>();
this->PathToYaml_ = "config/pods/" + this->Uuid_ + ".yaml";
if( std::filesystem::directory_entry("config").exists() != true)
if( !std::filesystem::directory_entry("config").exists())
{
std::filesystem::create_directory("config");
}
std::filesystem::directory_entry entry("config/pods");
if(entry.exists() != true)
if(!entry.exists())
{
std::filesystem::create_directory("config/pods");
}
@@ -48,25 +52,25 @@ namespace kubecontrol
}
KubePod::KubePod(std::string Owner, std::string Uuid, std::string Component, std::string ContainerImage,std::string Namespace):
KubePod::KubePod(std::string &Owner, std::string &Uuid, std::string &Component, std::string &ContainerImage,std::string Namespace):
Owner_(Utils::to_lower(Owner)),
Uuid_(Utils::to_lower(Uuid)),
Component_(Utils::to_lower(Component)),
Namespace_(Namespace),
EnvirmonentVars_()
ContainerRegistry_("kmaster.ti.unibw-hamburg.de:30808"),
Namespace_(Namespace)
{
ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808";
EnvirmonentVars_ = std::map<std::string, std::string>();
this->PathToYaml_ = "config/pods/" + this->Uuid_ + ".yaml";
if( std::filesystem::directory_entry("config").exists() != true)
if( !std::filesystem::directory_entry("config").exists())
{
std::filesystem::create_directory("config");
}
std::filesystem::directory_entry entry("config/pods");
if(entry.exists() != true)
if(!entry.exists())
{
std::filesystem::create_directory("config/pods");
}
@@ -89,12 +93,12 @@ namespace kubecontrol
if (envs != nullptr)
{
int i = 0;
int lauf = 0;
for(auto [key,value] : *envs)
{
container["env"][i]["name"] = key;
container["env"][i]["value"] = value;
i++;
container["env"][lauf]["name"] = key;
container["env"][lauf]["value"] = value;
lauf++;
}
}
@@ -138,12 +142,12 @@ namespace kubecontrol
{
if(EnvirmonentVars_.contains(key)) {
return EnvirmonentVars_[key];
} else {
return nullptr;
}
return "";
}
void KubePod::setArgs(std::string args)
void KubePod::setArgs(std::string &args)
{
Args_.emplace_back(Utils::to_lower(args));
}
@@ -153,7 +157,7 @@ namespace kubecontrol
return Args_;
}
void KubePod::setCommand(std::string command)
void KubePod::setCommand(std::string &command)
{
PodCommand_ = Utils::to_lower(command);
}
@@ -163,7 +167,7 @@ namespace kubecontrol
return PodCommand_;
}
void KubePod::setComponent(std::string component)
void KubePod::setComponent(std::string &component)
{
this->Component_ = Utils::to_lower(component);
}
@@ -173,7 +177,7 @@ namespace kubecontrol
return this->Component_;
}
void KubePod::setName(std::string name)
void KubePod::setName(std::string &name)
{
this->Name_ = name;
}
@@ -218,17 +222,17 @@ namespace kubecontrol
int i = 0;
for (auto item :EnvirmonentVars_) {
for (const auto& item :EnvirmonentVars_) {
node["spec"]["containers"][0]["env"][i]["name"] = item.first;
node["spec"]["containers"][0]["env"][i]["value"] = item.second;
i++;
}
if (Args_.size() > 0)
if (!Args_.empty())
{
node["spec"]["containers"][0]["args"].SetStyle(YAML::EmitterStyle::Flow);
for (auto item : Args_) {
for (const auto& item : Args_) {
node["spec"]["containers"][0]["args"].push_back(item);
}
}
@@ -271,7 +275,7 @@ namespace kubecontrol
auto timeoutTime = std::chrono::system_clock::now() + std::chrono::seconds(10);
if (WaitTillRunning == true ) {
if (WaitTillRunning ) {
while ((this->Status_ != "Running" && this->Status_ != "Succeeded") || std::chrono::system_clock::now() >= timeoutTime) {
// LOG_S(INFO)<<"wainting till running " << this->Status_;
@@ -305,13 +309,13 @@ namespace kubecontrol
int KubePod::stopChilds(KubernetesAPI APIInterface)
{
auto uuids = this->getPodsChilds(APIInterface);
if (uuids.size() == 0)
if (uuids.empty())
{
return 1;
}
for(auto i: uuids)
for(const auto& uuid: uuids)
{
std::string request = "/api/v1/namespaces/simulator/pods/"+i.UUID;
std::string request = "/api/v1/namespaces/simulator/pods/"+uuid.UUID;
std::string result = APIInterface.performRequest(request,"DELETE");
}
@@ -326,7 +330,7 @@ namespace kubecontrol
{
std::string request = "/api/v1/namespaces/simulator/pods/"+Uuid_+"/status";
std::string result = APIInterface.performRequest(request,"GET");
if (result == "")
if (result.empty())
{
return 1;
}
@@ -344,9 +348,9 @@ namespace kubecontrol
std::string request = "/api/v1/namespaces/simulator/pods?labelSelector=app.kubernetes.io/part-of="+Uuid_;
std::string result = APIInterface.performRequest(request,"GET");
if (result == "")
if (result.empty())
{
return std::vector<PodChild>();
return {};
}
extractInformationFromResopnse(result);
@@ -357,7 +361,7 @@ namespace kubecontrol
int KubePod::extractInformationFromResopnse(std::string response)
{
if (response == "")
if (response.empty())
{
return 1 ;
}
@@ -389,7 +393,7 @@ namespace kubecontrol
}else{
return 1;
}
} catch (const std::exception e) {
} catch (const std::exception &e) {
LOG_S(ERROR)<< "Exeption in extractInformationFromResopnse() :" << e.what();
std::exception_ptr p = std::current_exception();
LOG_S(ERROR)<< "Exeption :" << p.__cxa_exception_type()->name();
@@ -411,4 +415,3 @@ namespace kubecontrol
}

View File

@@ -1,4 +1,4 @@
#include "nlohmann/json_fwd.hpp"
#include <nlohmann/json.hpp>
#include "yaml-cpp/binary.h"
#include "yaml-cpp/emitter.h"
#include "yaml-cpp/emitterdef.h"
@@ -22,7 +22,6 @@
#include <loguru.hpp>
#include <nlohmann/json.hpp>
#include <iostream>
@@ -32,7 +31,7 @@
namespace kubecontrol
{
kubecontrol::kubecontrol(std::string pathToKubectlConfig)
kubecontrol::kubecontrol(std::string &pathToKubectlConfig)
{
YAML::Node config = YAML::LoadFile(pathToKubectlConfig);
@@ -57,12 +56,12 @@ namespace kubecontrol
std::stringstream result;
request.setOpt(cURLpp::Options::WriteStream(&result));
request.setOpt(new curlpp::options::HttpHeader(headers));
request.setOpt(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( curlpp::options::Url(curlURL));
request.setOpt( curlpp::options::SslEngineDefault());
request.setOpt( curlpp::options::CaPath("config/ca.crt"));
request.setOpt( curlpp::options::SslVerifyPeer(false));
// request.setOpt(new curlpp::options::Verbose(true));
@@ -86,7 +85,7 @@ namespace kubecontrol
std::list<std::string> headers;
headers.push_back(AuthString);
headers.push_back("Content-Type: application/yaml");
headers.emplace_back("Content-Type: application/yaml");
curlpp::Cleanup cleaner;
@@ -99,17 +98,17 @@ namespace kubecontrol
std::stringstream result;
request.setOpt(cURLpp::Options::WriteStream(&result));
request.setOpt(new curlpp::options::HttpHeader(headers));
request.setOpt( curlpp::options::HttpHeader(headers));
request.setOpt(new curlpp::options::Url(curlURL));
request.setOpt( 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( curlpp::options::SslEngineDefault());
request.setOpt( curlpp::options::CaPath("config/ca.crt"));
request.setOpt( curlpp::options::SslVerifyPeer(false));
request.setOpt(new curlpp::options::Post(true));
request.setOpt( curlpp::options::Post(true));
auto yaml = createYAML();
@@ -140,7 +139,7 @@ namespace kubecontrol
request.setOpt(new curlpp::options::PostFields(buffer));
request.setOpt( curlpp::options::PostFields(buffer));
// request.setOpt(new curlpp::options::Verbose(true));
@@ -168,20 +167,20 @@ namespace kubecontrol
request.setOpt(cURLpp::Options::WriteStream(&result));
request.setOpt(new curlpp::options::HttpHeader(headers));
request.setOpt( curlpp::options::HttpHeader(headers));
request.setOpt(new curlpp::options::Url(curlURL));
request.setOpt( 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( curlpp::options::SslEngineDefault());
request.setOpt( curlpp::options::CaPath("config/ca.crt"));
request.setOpt( 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( curlpp::options::CustomRequest("DELETE"));
// request.setOpt(new curlpp::options::Verbose(true));
@@ -226,10 +225,10 @@ namespace kubecontrol
std::ofstream fout("config/pods_deployment.yaml");
std::stringstream ss;
ss <<node;
std::stringstream sstream;
sstream <<node;
LOG_S(INFO)<< node;
fout << ss.str();
fout << sstream.str();
fout.close();
return "config/pods_deployment.yaml";

View File

@@ -22,7 +22,10 @@ SCENARIO("Testing the SimCore Sensor")
std::string uuid = name;
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
std::string controller = "controller";
std::string type = "ship";
std::string image = "ship:latest";
kubecontrol::KubePod ShipPod1(controller,uuid,type,image,"simulator");
ShipPod1.setName(name);
nlohmann::json vars;
@@ -49,7 +52,10 @@ ShipPod1.start(api);
LOG_S(INFO)<<"started";
std::string name2 = "componenttest2";
kubecontrol::KubePod ShipPod2("controller",name2,"CMS","ship:latest","simulator");
std::string controller2 = "controller";
std::string type2 = "ship";
std::string image2 = "ship:latest";
kubecontrol::KubePod ShipPod2(controller2,name2,type2,image2,"simulator");
nlohmann::json vars1;
vars1["ENTITY_ID"] = name2;
@@ -96,7 +102,7 @@ std::this_thread::sleep_for(std::chrono::milliseconds(5000));
REQUIRE(ShipPod1.getComponent() == "ship");
REQUIRE(ShipPod1.getOwner() == "controller");
REQUIRE(ShipPod1.getStatus() == "Running");
REQUIRE(ShipPod1.getIp() != "");
REQUIRE(!ShipPod1.getIp().empty());
REQUIRE(ShipPod1.getPodsChilds(api).size() == 2);
// REQUIRE(info1 != "");

View File

@@ -14,15 +14,16 @@
SCENARIO("Testing the SimCore Sensor")
{
kubecontrol::kubecontrol kc("../docs/config");
std::string file= "../docs/config";
kubecontrol::kubecontrol kubecontroler(file);
GIVEN("different Attributes for a Track in different forms")
{
kc.createYAML();
kc.startPod();
kubecontroler.createYAML();
kubecontroler.startPod();
// kc.getPods();
// kc.deletePod("debug-debian");
kc.getPods();
kubecontroler.getPods();
WHEN("constructing Track Object with data")
{

View File

@@ -3,6 +3,8 @@
#include "kubecontrol/KubePod.hpp"
#include "nlohmann/json_fwd.hpp"
#include <math.h>
#include <string>
#include <thread>
#include <vector>
@@ -19,7 +21,10 @@ const int podGrid = 2;
void startShip(kubecontrol::PodController* podc,std::string uuid,std::string Name, std::string lat, std::string lon)
{
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
std::string owner = "controller";
std::string type = "ship";
std::string image = "ship:latest";
kubecontrol::KubePod ShipPod1(owner,uuid,type,image,"simulator");
nlohmann::json vars;
vars["ENTITY_ID"] = uuid;
@@ -58,7 +63,8 @@ void createScenario(kubecontrol::PodController* podc,std::vector<std::string> *u
std::string name = "test";
name += std::to_string(counter);
double lat2, lon2;
double lat2 = 0;
double lon2 = 0;
// geod.Direct(lat, lonTmp, 90, distance, lat2, lon2);
lat2= lat+10;
// SimCore::Identifier id;

View File

@@ -3,6 +3,7 @@
#include "kubecontrol/KubePod.hpp"
#include "nlohmann/json_fwd.hpp"
#include <string>
#include <thread>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
@@ -19,7 +20,10 @@ kubecontrol::PodController podc("docs/config");
std::string name = "test1";
std::string uuid = name;
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
std::string owner = "controller";
std::string type = "ship";
std::string image = "ship:latest";
kubecontrol::KubePod ShipPod1(owner,uuid,type,image,"simulator");
nlohmann::json vars;
vars["ENTITY_ID"] = uuid;