2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_stateful_set_update_strategy.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_stateful_set_update_strategy_t *v1_stateful_set_update_strategy_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
v1_rolling_update_stateful_set_strategy_t *rolling_update,
|
2022-06-05 18:16:17 +00:00
|
|
|
char *type
|
2020-03-18 17:24:33 +08:00
|
|
|
) {
|
|
|
|
|
v1_stateful_set_update_strategy_t *v1_stateful_set_update_strategy_local_var = malloc(sizeof(v1_stateful_set_update_strategy_t));
|
|
|
|
|
if (!v1_stateful_set_update_strategy_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_stateful_set_update_strategy_local_var->rolling_update = rolling_update;
|
|
|
|
|
v1_stateful_set_update_strategy_local_var->type = type;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_stateful_set_update_strategy_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_stateful_set_update_strategy_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_stateful_set_update_strategy_t *v1_stateful_set_update_strategy_create(
|
|
|
|
|
v1_rolling_update_stateful_set_strategy_t *rolling_update,
|
|
|
|
|
char *type
|
|
|
|
|
) {
|
|
|
|
|
return v1_stateful_set_update_strategy_create_internal (
|
|
|
|
|
rolling_update,
|
|
|
|
|
type
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_stateful_set_update_strategy_free(v1_stateful_set_update_strategy_t *v1_stateful_set_update_strategy) {
|
|
|
|
|
if(NULL == v1_stateful_set_update_strategy){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_stateful_set_update_strategy->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_stateful_set_update_strategy_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_stateful_set_update_strategy->rolling_update) {
|
|
|
|
|
v1_rolling_update_stateful_set_strategy_free(v1_stateful_set_update_strategy->rolling_update);
|
|
|
|
|
v1_stateful_set_update_strategy->rolling_update = NULL;
|
|
|
|
|
}
|
2022-06-05 18:16:17 +00:00
|
|
|
if (v1_stateful_set_update_strategy->type) {
|
|
|
|
|
free(v1_stateful_set_update_strategy->type);
|
|
|
|
|
v1_stateful_set_update_strategy->type = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_stateful_set_update_strategy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_stateful_set_update_strategy_convertToJSON(v1_stateful_set_update_strategy_t *v1_stateful_set_update_strategy) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_stateful_set_update_strategy->rolling_update
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_stateful_set_update_strategy->rolling_update) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *rolling_update_local_JSON = v1_rolling_update_stateful_set_strategy_convertToJSON(v1_stateful_set_update_strategy->rolling_update);
|
|
|
|
|
if(rolling_update_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "rollingUpdate", rolling_update_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_stateful_set_update_strategy->type
|
2022-06-05 18:16:17 +00:00
|
|
|
if(v1_stateful_set_update_strategy->type) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "type", v1_stateful_set_update_strategy->type) == NULL) {
|
|
|
|
|
goto fail; //String
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_stateful_set_update_strategy_t *v1_stateful_set_update_strategy_parseFromJSON(cJSON *v1_stateful_set_update_strategyJSON){
|
|
|
|
|
|
|
|
|
|
v1_stateful_set_update_strategy_t *v1_stateful_set_update_strategy_local_var = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_stateful_set_update_strategy->rolling_update
|
|
|
|
|
v1_rolling_update_stateful_set_strategy_t *rolling_update_local_nonprim = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_stateful_set_update_strategy->rolling_update
|
|
|
|
|
cJSON *rolling_update = cJSON_GetObjectItemCaseSensitive(v1_stateful_set_update_strategyJSON, "rollingUpdate");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(rolling_update)) {
|
|
|
|
|
rolling_update = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (rolling_update) {
|
|
|
|
|
rolling_update_local_nonprim = v1_rolling_update_stateful_set_strategy_parseFromJSON(rolling_update); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_stateful_set_update_strategy->type
|
|
|
|
|
cJSON *type = cJSON_GetObjectItemCaseSensitive(v1_stateful_set_update_strategyJSON, "type");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(type)) {
|
|
|
|
|
type = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (type) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(type) && !cJSON_IsNull(type))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
2022-06-05 18:16:17 +00:00
|
|
|
goto end; //String
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_stateful_set_update_strategy_local_var = v1_stateful_set_update_strategy_create_internal (
|
2020-03-18 17:24:33 +08:00
|
|
|
rolling_update ? rolling_update_local_nonprim : NULL,
|
2022-12-29 10:58:47 +08:00
|
|
|
type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL
|
2020-03-18 17:24:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_stateful_set_update_strategy_local_var;
|
|
|
|
|
end:
|
2021-01-11 12:15:24 +08:00
|
|
|
if (rolling_update_local_nonprim) {
|
|
|
|
|
v1_rolling_update_stateful_set_strategy_free(rolling_update_local_nonprim);
|
|
|
|
|
rolling_update_local_nonprim = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|