FIX: fixed issue where the response of the kube api was not written correct

This commit is contained in:
Henry Winkel
2023-10-26 15:57:37 +02:00
parent 26ff04067d
commit d0db414c16
4 changed files with 20 additions and 53 deletions

View File

@@ -10,62 +10,29 @@
class WriterMemoryClass class WriterMemoryClass
{ {
public: 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... // Callback must be declared static, otherwise it won't link...
size_t WriteMemoryCallback(char* ptr, size_t size, size_t nmemb) size_t WriteMemoryCallback(char* ptr, size_t size, size_t nmemb)
{ {
// Calculate the real size of the incoming buffer str_pBuffer.erase();
size_t realsize = size * nmemb; str_pBuffer = std::string(ptr);
// (Re)Allocate memory for the buffer return str_pBuffer.size();
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() std::string getResponse()
{ {
return std::string(m_pBuffer); // return std::string(m_pBuffer);
return str_pBuffer;
} }
void print() void print()
{ {
std::cout << "Size: " << m_Size << std::endl; std::cout << "Size: " << str_pBuffer.size() << std::endl;
std::cout << "Content: " << std::endl << m_pBuffer << std::endl; std::cout << "Content: " << std::endl << str_pBuffer << std::endl;
} }
// Public member vars // Public member vars
char* m_pBuffer; private:
size_t m_Size; std::string str_pBuffer;
}; };

View File

@@ -226,12 +226,13 @@ namespace kubecontrol
request.perform(); request.perform();
request.reset(); request.reset();
auto response = mWriterChunk.getResponse(); std::string response = mWriterChunk.getResponse();
InfoPod.update(response); InfoPod.update(response);
while (InfoPod.Status != "Running" && InfoPod.Status != "Succeeded") {
while (InfoPod.Status != "Running") {
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
response = this->getInfo(curlURL, token); response = this->getInfo(curlURL, token);
InfoPod.update(response); InfoPod.update(response);
} }
@@ -348,8 +349,7 @@ namespace kubecontrol
request.perform(); request.perform();
auto response = mWriterChunk.getResponse(); return mWriterChunk.getResponse();
return response;
} }

View File

@@ -47,7 +47,6 @@ namespace kubecontrol
Component = j["metadata"]["labels"]["app.kubernetes.io/component"].get<std::string>(); Component = j["metadata"]["labels"]["app.kubernetes.io/component"].get<std::string>();
PartOf = j["metadata"]["labels"]["app.kubernetes.io/part-of"].get<std::string>(); PartOf = j["metadata"]["labels"]["app.kubernetes.io/part-of"].get<std::string>();
Image = j["spec"]["containers"][0]["image"].get<std::string>(); Image = j["spec"]["containers"][0]["image"].get<std::string>();
if (j["status"].contains("podIP")) Ip = j["status"]["podIP"].get<std::string>(); if (j["status"].contains("podIP")) Ip = j["status"]["podIP"].get<std::string>();
Status = j["status"]["phase"].get<std::string>(); Status = j["status"]["phase"].get<std::string>();
@@ -57,7 +56,8 @@ namespace kubecontrol
} catch (std::exception& e) } catch (std::exception& e)
{ {
// LOG_S(WARNING)<< response;
LOG_S(ERROR)<<e.what(); LOG_S(ERROR)<<e.what();
} }

View File

@@ -26,7 +26,7 @@ SCENARIO("Testing the SimCore Sensor")
LOG_S(INFO)<<pod1.start(api,token); LOG_S(INFO)<<pod1.start(api,token);
LOG_S(INFO)<< pod1.getInfo(api, token); LOG_S(INFO)<< pod1.getInfo(api, token);
// pod1.stop(api,token); pod1.stop(api,token);
WHEN("constructing Track Object with data") WHEN("constructing Track Object with data")
{ {