我正在尝试为本地minikube集群中现有的Kubernetes部署创建补丁。我已经成功实现了创建新部署的功能。
对于部署补丁,我想我必须在api\AppsV1API.c
中使用以下函数:
v1_deployment_t *
AppsV1API_patchNamespacedDeployment(apiClient_t *apiClient, char *name, char *_namespace, object_t *body, char *pretty, char *dryRun, char *fieldManager, char *fieldValidation, int force)
字符串
我不明白object_t *body
的函数的正确参数。
部署配置文件:
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "busybox-deployment"
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "busybox"
}
},
"template": {
"metadata": {
"labels": {
"app": "busybox"
}
},
"spec": {
"containers": [
{
"name": "busybox-container",
"image": "busybox",
"command": ["sleep", "3600"]
}
]
}
}
}
}
型
我想把replicas
从1改为3。
我用来插入[{'op': 'replace', 'path': '/spec/replicas', 'value': 2}]
作为主体的代码:
cJSON *jsonArray = cJSON_CreateArray();
cJSON *jsonObject = cJSON_CreateObject();
cJSON_AddStringToObject(jsonObject, "op", "replace");
cJSON_AddStringToObject(jsonObject, "path", "/spec/replicas");
cJSON_AddNumberToObject(jsonObject, "value", 2);
cJSON_AddItemToArray(jsonArray, jsonObject);
object_t *body = object_parseFromJSON(jsonArray);
v1_deployment_t *updatedDeployment = AppsV1API_patchNamespacedDeployment(apiClient, deploymentInfo->metadata->name, namespc, body, NULL, NULL, NULL, NULL, 0);
型
我用来插入{'spec': {'replicas': 2}}
作为主体的代码:
cJSON *root = cJSON_CreateObject();
cJSON *specObject = cJSON_CreateObject();
cJSON_AddNumberToObject(specObject, "replicas", 2);
cJSON_AddItemToObject(root, "spec", specObject);
object_t *body = object_parseFromJSON(root);
v1_deployment_t *updatedDeployment = AppsV1API_patchNamespacedDeployment(apiClient, deploymentInfo->metadata->name, namespc, body, NULL, NULL, NULL, NULL, 0);
型
两者都失败,apiClient->responseCode
为422(有效负载错误)。
1条答案
按热度按时间cwdobuhd1#
你的代码看起来和我写的一样好用。下面是我完整的测试用例(对
AppsV1API_patchNamespacedDeployment
的调用和你的一样,除了name
和namespace
是用字符串文字指定的):字符串
考虑以下部署:
型
上面的代码成功运行,结果是:
型