2021-09-14 21:52:06 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_scheduling.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_scheduling_t *v1_scheduling_create_internal(
|
2021-09-14 21:52:06 +08:00
|
|
|
list_t* node_selector,
|
|
|
|
|
list_t *tolerations
|
|
|
|
|
) {
|
|
|
|
|
v1_scheduling_t *v1_scheduling_local_var = malloc(sizeof(v1_scheduling_t));
|
|
|
|
|
if (!v1_scheduling_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_scheduling_local_var->node_selector = node_selector;
|
|
|
|
|
v1_scheduling_local_var->tolerations = tolerations;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_scheduling_local_var->_library_owned = 1;
|
2021-09-14 21:52:06 +08:00
|
|
|
return v1_scheduling_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_scheduling_t *v1_scheduling_create(
|
|
|
|
|
list_t* node_selector,
|
|
|
|
|
list_t *tolerations
|
|
|
|
|
) {
|
|
|
|
|
return v1_scheduling_create_internal (
|
|
|
|
|
node_selector,
|
|
|
|
|
tolerations
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
void v1_scheduling_free(v1_scheduling_t *v1_scheduling) {
|
|
|
|
|
if(NULL == v1_scheduling){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_scheduling->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_scheduling_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
listEntry_t *listEntry;
|
|
|
|
|
if (v1_scheduling->node_selector) {
|
|
|
|
|
list_ForEach(listEntry, v1_scheduling->node_selector) {
|
2025-02-11 19:36:46 +00:00
|
|
|
keyValuePair_t *localKeyValue = listEntry->data;
|
2021-09-14 21:52:06 +08:00
|
|
|
free (localKeyValue->key);
|
|
|
|
|
free (localKeyValue->value);
|
|
|
|
|
keyValuePair_free(localKeyValue);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_scheduling->node_selector);
|
2021-09-14 21:52:06 +08:00
|
|
|
v1_scheduling->node_selector = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_scheduling->tolerations) {
|
|
|
|
|
list_ForEach(listEntry, v1_scheduling->tolerations) {
|
|
|
|
|
v1_toleration_free(listEntry->data);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_scheduling->tolerations);
|
2021-09-14 21:52:06 +08:00
|
|
|
v1_scheduling->tolerations = NULL;
|
|
|
|
|
}
|
|
|
|
|
free(v1_scheduling);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_scheduling_convertToJSON(v1_scheduling_t *v1_scheduling) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_scheduling->node_selector
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_scheduling->node_selector) {
|
2021-09-14 21:52:06 +08:00
|
|
|
cJSON *node_selector = cJSON_AddObjectToObject(item, "nodeSelector");
|
|
|
|
|
if(node_selector == NULL) {
|
|
|
|
|
goto fail; //primitive map container
|
|
|
|
|
}
|
|
|
|
|
cJSON *localMapObject = node_selector;
|
|
|
|
|
listEntry_t *node_selectorListEntry;
|
|
|
|
|
if (v1_scheduling->node_selector) {
|
|
|
|
|
list_ForEach(node_selectorListEntry, v1_scheduling->node_selector) {
|
2025-02-11 19:36:46 +00:00
|
|
|
keyValuePair_t *localKeyValue = node_selectorListEntry->data;
|
|
|
|
|
if(cJSON_AddStringToObject(localMapObject, localKeyValue->key, localKeyValue->value) == NULL)
|
2021-09-14 21:52:06 +08:00
|
|
|
{
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_scheduling->tolerations
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_scheduling->tolerations) {
|
2021-09-14 21:52:06 +08:00
|
|
|
cJSON *tolerations = cJSON_AddArrayToObject(item, "tolerations");
|
|
|
|
|
if(tolerations == NULL) {
|
|
|
|
|
goto fail; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *tolerationsListEntry;
|
|
|
|
|
if (v1_scheduling->tolerations) {
|
|
|
|
|
list_ForEach(tolerationsListEntry, v1_scheduling->tolerations) {
|
|
|
|
|
cJSON *itemLocal = v1_toleration_convertToJSON(tolerationsListEntry->data);
|
|
|
|
|
if(itemLocal == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToArray(tolerations, itemLocal);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_scheduling_t *v1_scheduling_parseFromJSON(cJSON *v1_schedulingJSON){
|
|
|
|
|
|
|
|
|
|
v1_scheduling_t *v1_scheduling_local_var = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local map for v1_scheduling->node_selector
|
|
|
|
|
list_t *node_selectorList = NULL;
|
|
|
|
|
|
|
|
|
|
// define the local list for v1_scheduling->tolerations
|
|
|
|
|
list_t *tolerationsList = NULL;
|
|
|
|
|
|
2021-09-14 21:52:06 +08:00
|
|
|
// v1_scheduling->node_selector
|
|
|
|
|
cJSON *node_selector = cJSON_GetObjectItemCaseSensitive(v1_schedulingJSON, "nodeSelector");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(node_selector)) {
|
|
|
|
|
node_selector = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (node_selector) {
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *node_selector_local_map = NULL;
|
2022-09-09 10:18:51 +08:00
|
|
|
if(!cJSON_IsObject(node_selector) && !cJSON_IsNull(node_selector))
|
|
|
|
|
{
|
2021-09-14 21:52:06 +08:00
|
|
|
goto end;//primitive map container
|
|
|
|
|
}
|
2022-09-09 10:18:51 +08:00
|
|
|
if(cJSON_IsObject(node_selector))
|
2021-09-14 21:52:06 +08:00
|
|
|
{
|
2022-09-09 10:18:51 +08:00
|
|
|
node_selectorList = list_createList();
|
|
|
|
|
keyValuePair_t *localMapKeyPair;
|
|
|
|
|
cJSON_ArrayForEach(node_selector_local_map, node_selector)
|
2021-09-14 21:52:06 +08:00
|
|
|
{
|
2022-09-09 10:18:51 +08:00
|
|
|
cJSON *localMapObject = node_selector_local_map;
|
|
|
|
|
if(!cJSON_IsString(localMapObject))
|
|
|
|
|
{
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
localMapKeyPair = keyValuePair_create(strdup(localMapObject->string),strdup(localMapObject->valuestring));
|
|
|
|
|
list_addElement(node_selectorList , localMapKeyPair);
|
2021-09-14 21:52:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_scheduling->tolerations
|
|
|
|
|
cJSON *tolerations = cJSON_GetObjectItemCaseSensitive(v1_schedulingJSON, "tolerations");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(tolerations)) {
|
|
|
|
|
tolerations = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (tolerations) {
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *tolerations_local_nonprimitive = NULL;
|
2021-09-14 21:52:06 +08:00
|
|
|
if(!cJSON_IsArray(tolerations)){
|
|
|
|
|
goto end; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 10:56:53 +08:00
|
|
|
tolerationsList = list_createList();
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(tolerations_local_nonprimitive,tolerations )
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsObject(tolerations_local_nonprimitive)){
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
v1_toleration_t *tolerationsItem = v1_toleration_parseFromJSON(tolerations_local_nonprimitive);
|
|
|
|
|
|
|
|
|
|
list_addElement(tolerationsList, tolerationsItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_scheduling_local_var = v1_scheduling_create_internal (
|
2021-09-14 21:52:06 +08:00
|
|
|
node_selector ? node_selectorList : NULL,
|
|
|
|
|
tolerations ? tolerationsList : NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_scheduling_local_var;
|
|
|
|
|
end:
|
2022-03-29 10:12:05 +08:00
|
|
|
if (node_selectorList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, node_selectorList) {
|
2025-02-11 19:36:46 +00:00
|
|
|
keyValuePair_t *localKeyValue = listEntry->data;
|
2022-03-29 10:12:05 +08:00
|
|
|
free(localKeyValue->key);
|
|
|
|
|
localKeyValue->key = NULL;
|
|
|
|
|
free(localKeyValue->value);
|
|
|
|
|
localKeyValue->value = NULL;
|
|
|
|
|
keyValuePair_free(localKeyValue);
|
|
|
|
|
localKeyValue = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(node_selectorList);
|
|
|
|
|
node_selectorList = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (tolerationsList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, tolerationsList) {
|
|
|
|
|
v1_toleration_free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(tolerationsList);
|
|
|
|
|
tolerationsList = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|