批量创建插件检查任务 - BatchCreateAddonPrecheck
功能介绍
该API用于在指定集群下批量创建插件检查任务。
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
- 如果使用身份策略授权,当前API调用无需身份策略权限。
URI
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/addons/precheck
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
project_id |
是 |
String |
参数解释: 项目ID,获取方式请参见如何获取接口URI中参数。 约束限制: 不涉及 取值范围: 账号的项目ID 默认取值: 不涉及 |
|
cluster_id |
是 |
String |
参数解释: 集群ID,获取方式请参见如何获取接口URI中参数。 约束限制: 不涉及 取值范围: 集群ID 默认取值: 不涉及 |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
Content-Type |
是 |
String |
参数解释: 消息体的类型(格式) 约束限制: GET方法不做校验 取值范围:
默认取值: 不涉及 |
|
X-Auth-Token |
是 |
String |
参数解释: 调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值,获取方式请参见获取token。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
kind |
是 |
String |
参数解释: API类型 约束限制: 该值不可修改 取值范围: 固定值"AddonCheck" 默认取值: AddonCheck |
|
apiVersion |
是 |
String |
参数解释: API版本 约束限制: 该值不可修改 取值范围: 固定值"v3" 默认取值: v3 |
|
spec |
是 |
AddonCheckSpec object |
参数解释: spec是集合类的元素类型,内容为插件检查具体信息,检查配置的详细描述主体部分都在spec中给出 约束限制: 不涉及 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
clusterID |
是 |
String |
参数解释: 集群ID 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
|
addonList |
是 |
Array of AddonInfo objects |
参数解释: 插件检查信息列表,包含了需要检查的插件模板名称,插件实例ID,插件升级配置等。 约束限制: 不涉及 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
addonTemplateName |
是 |
String |
参数解释: 插件模板名称 约束限制: 不涉及 取值范围: cce服务支持的插件模板 默认取值: 不涉及 |
|
addonInstanceID |
是 |
String |
参数解释: 插件实例ID,可以通过获取AddonInstance列表中的items[].metadata.uid字段获取 约束限制: 此参数必填 取值范围: 不涉及 默认取值: 不涉及 |
|
targetVersion |
否 |
String |
参数解释: 插件升级的目标版本 约束限制: 插件升级场景下,此参数必填。 取值范围: cce服务提供的插件版本,可以通过查询AddonTemplates列表中的items[].spec.versions.version字段获取 默认取值: 不涉及 |
|
type |
是 |
String |
参数解释: 插件检查类型 约束限制: 此参数必填。 取值范围:
默认取值: 不涉及 |
|
values |
否 |
Map<String,Object> |
参数解释: 插件模板编辑/升级参数(各插件不同),请根据具体插件模板信息填写参数 约束限制: 不涉及 |
响应参数
状态码:201
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
kind |
String |
参数解释: API类型 约束限制: 该值不可修改 取值范围: 固定值"AddonCheck" 默认取值: AddonCheck |
|
apiVersion |
String |
参数解释: API版本 约束限制: 该值不可修改 取值范围: 固定值"v3" 默认取值: v3 |
|
spec |
AddonCheckSpec object |
参数解释: spec是集合类的元素类型,内容为插件检查具体信息,检查配置的详细描述主体部分都在spec中给出 约束限制: 不涉及 |
|
status |
AddonCheckStatus object |
参数解释: status是集合类的元素类型,内容为插件检查任务的创建结果,包含task_id用于插件检查结果查询 约束限制: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
clusterID |
String |
参数解释: 集群ID 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
|
addonList |
Array of AddonInfo objects |
参数解释: 插件检查信息列表,包含了需要检查的插件模板名称,插件实例ID,插件升级配置等。 约束限制: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
addonTemplateName |
String |
参数解释: 插件模板名称 约束限制: 不涉及 取值范围: cce服务支持的插件模板 默认取值: 不涉及 |
|
addonInstanceID |
String |
参数解释: 插件实例ID,可以通过获取AddonInstance列表中的items[].metadata.uid字段获取 约束限制: 此参数必填 取值范围: 不涉及 默认取值: 不涉及 |
|
targetVersion |
String |
参数解释: 插件升级的目标版本 约束限制: 插件升级场景下,此参数必填。 取值范围: cce服务提供的插件版本,可以通过查询AddonTemplates列表中的items[].spec.versions.version字段获取 默认取值: 不涉及 |
|
type |
String |
参数解释: 插件检查类型 约束限制: 此参数必填。 取值范围:
默认取值: 不涉及 |
|
values |
Map<String,Object> |
参数解释: 插件模板编辑/升级参数(各插件不同),请根据具体插件模板信息填写参数 约束限制: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
items |
Array of AddonCheckTask objects |
参数解释: 插件检查任务信息列表,包含了插件检查任务ID,插件模板名称,插件实例ID等。 约束限制: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
metadata |
CheckTaskMetadata object |
参数解释: 基本信息,为集合类的元素类型,包含一组由不同名称定义的属性 约束限制: 不涉及 |
|
spec |
CheckTaskSpec object |
参数解释: 插件检查目标信息,包含插件升级的目标版本 约束限制: 不涉及 |
|
status |
CheckTaskStatus object |
参数解释: 插件检查任务状态信息 约束限制: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
type |
String |
参数解释: 插件检查类型 取值范围:
|
|
taskID |
String |
参数解释: 插件检查任务ID,用于任务检查结果查询 取值范围: 不涉及 |
|
addonTemplateName |
String |
参数解释: 插件模板名称 取值范围: cce服务提供的插件模板,可以通过查询AddonTemplates列表中的items[].metadata.name字段获取 |
|
addonInstanceName |
String |
参数解释: 插件实例名称 取值范围: 不涉及 |
|
addonInstanceID |
String |
参数解释: 插件实例ID 取值范围: 不涉及 |
|
createTimeStamp |
String |
参数解释: 插件检查任务创建时间 取值范围: 不涉及 |
|
expireTimeStamp |
String |
参数解释: 插件检查任务超时时间,仅终态(Failed/Success)任务存在此字段 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
status |
String |
参数解释: 插件检查状态 取值范围:
|
|
message |
String |
参数解释: 插件检查结果信息 取值范围: 不涉及 |
|
riskList |
Array of CheckTaskRisk objects |
参数解释: 插件检查风险项列表,不同插件对应的风险检查项不同。 约束限制: 不涉及 |
请求示例
-
创建一个coredns插件的检查任务,检查类型为插件升级。
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/addons/precheck { "kind" : "AddonCheck", "apiVersion" : "v3", "spec" : { "clusterID" : "6b400e1c-4368-11f0-ba56-0255ac100037", "addonList" : [ { "addonTemplateName" : "coredns", "addonInstanceID" : "8fcaa506-809d-4f33-91b3-b27efcbeb540", "type" : "addonUpgrade", "values" : { "basic" : { "cluster_ip" : "10.247.3.10", "image_version" : "1.17.15", "platform" : "linux-amd64", "rbac_enabled" : true, "swr_addr" : "", "swr_user" : "hwofficial" }, "custom" : { "cluster_id" : "8fcaa506-809d-4f33-91b3-b27efcbeb540", "stub_domains" : { }, "tenant_id" : "0504201b6c80256b2f08c0099f0c8fe4", "upstream_nameservers" : [ ] }, "flavor" : { "name" : 2500, "replicas" : 2, "resources" : [ { "limitsCpu" : "500m", "limitsMem" : "512Mi", "name" : "coredns", "requestsCpu" : "500m", "requestsMem" : "512Mi" } ] } } } ] } } -
创建一个coredns插件的检查任务,检查类型为插件巡检。
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/addons/precheck { "kind" : "AddonCheck", "apiVersion" : "v3", "spec" : { "clusterID" : "6b400e1c-4368-11f0-ba56-0255ac100037", "addonList" : [ { "addonTemplateName" : "coredns", "addonInstanceID" : "8fcaa506-809d-4f33-91b3-b27efcbeb540", "type" : "addonStatic" } ] } }
响应示例
状态码:201
表示在指定集群下批量创建插件检查任务下发成功。
{
"kind" : "AddonCheck",
"apiVersion" : "v3",
"spec" : {
"clusterID" : "6b400e1c-4368-11f0-ba56-0255ac100037",
"addonList" : [ {
"addonTemplateName" : "coredns",
"addonInstanceID" : "8fcaa506-809d-4f33-91b3-b27efcbeb540",
"type" : "addonUpgrade",
"values" : {
"basic" : {
"cluster_ip" : "10.247.3.10",
"image_version" : "1.17.15",
"platform" : "linux-amd64",
"rbac_enabled" : true,
"swr_addr" : "",
"swr_user" : "hwofficial"
},
"custom" : {
"cluster_id" : "8fcaa506-809d-4f33-91b3-b27efcbeb540",
"stub_domains" : { },
"tenant_id" : "0504201b6c80256b2f08c0099f0c8fe4",
"upstream_nameservers" : [ ]
},
"flavor" : {
"name" : 2500,
"replicas" : 2,
"resources" : [ {
"limitsCpu" : "500m",
"limitsMem" : "512Mi",
"name" : "coredns",
"requestsCpu" : "500m",
"requestsMem" : "512Mi"
} ]
}
}
} ]
},
"status" : {
"items" : [ {
"metadata" : {
"type" : "addonUpgrade",
"taskID" : "22386048-d955-4409-bc71-20cc2b774245",
"addonTemplateName" : "coredns",
"addonInstanceName" : "cceaddon-coredns",
"addonInstanceID" : "8fcaa506-809d-4f33-91b3-b27efcbeb540",
"createTimeStamp" : "2025-08-13T11:24:37.312017086+08:00"
},
"spec" : {
"addonTargetVersion" : "1.27.1"
},
"status" : {
"status" : "Init",
"riskList" : [ {
"riskName" : "K8sResourceModified",
"status" : "Init",
"level" : "Warning"
}, {
"riskName" : "AddonValidate",
"status" : "Init",
"level" : "Warning"
}, {
"riskName" : "AddonStatus",
"status" : "Init",
"level" : "Warning"
} ]
}
} ]
}
}
SDK代码示例
SDK代码示例如下。
-
创建一个coredns插件的检查任务,检查类型为插件升级。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.cce.v3.region.CceRegion; import com.huaweicloud.sdk.cce.v3.*; import com.huaweicloud.sdk.cce.v3.model.*; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; public class BatchCreateAddonPrecheckSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("<YOUR REGION>")) .build(); BatchCreateAddonPrecheckRequest request = new BatchCreateAddonPrecheckRequest(); request.withClusterId("{cluster_id}"); AddonCheckRequest body = new AddonCheckRequest(); Map<String, Object> listAddonListValues = new HashMap<>(); listAddonListValues.put("basic", "{\"rbac_enabled\":true,\"swr_user\":\"hwofficial\",\"image_version\":\"1.17.15\",\"cluster_ip\":\"10.247.3.10\",\"platform\":\"linux-amd64\",\"swr_addr\":\"\"}"); listAddonListValues.put("custom", "{\"tenant_id\":\"0504201b6c80256b2f08c0099f0c8fe4\",\"cluster_id\":\"8fcaa506-809d-4f33-91b3-b27efcbeb540\",\"stub_domains\":{},\"upstream_nameservers\":[]}"); listAddonListValues.put("flavor", "{\"replicas\":2,\"name\":2500,\"resources\":[{\"limitsCpu\":\"500m\",\"name\":\"coredns\",\"limitsMem\":\"512Mi\",\"requestsMem\":\"512Mi\",\"requestsCpu\":\"500m\"}]}"); List<AddonInfo> listSpecAddonList = new ArrayList<>(); listSpecAddonList.add( new AddonInfo() .withAddonTemplateName("coredns") .withAddonInstanceID("8fcaa506-809d-4f33-91b3-b27efcbeb540") .withType(AddonInfo.TypeEnum.fromValue("addonUpgrade")) .withValues(listAddonListValues) ); AddonCheckSpec specbody = new AddonCheckSpec(); specbody.withClusterID("6b400e1c-4368-11f0-ba56-0255ac100037") .withAddonList(listSpecAddonList); body.withSpec(specbody); body.withApiVersion("v3"); body.withKind("AddonCheck"); request.withBody(body); try { BatchCreateAddonPrecheckResponse response = client.batchCreateAddonPrecheck(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
创建一个coredns插件的检查任务,检查类型为插件巡检。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.cce.v3.region.CceRegion; import com.huaweicloud.sdk.cce.v3.*; import com.huaweicloud.sdk.cce.v3.model.*; import java.util.List; import java.util.ArrayList; public class BatchCreateAddonPrecheckSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("<YOUR REGION>")) .build(); BatchCreateAddonPrecheckRequest request = new BatchCreateAddonPrecheckRequest(); request.withClusterId("{cluster_id}"); AddonCheckRequest body = new AddonCheckRequest(); List<AddonInfo> listSpecAddonList = new ArrayList<>(); listSpecAddonList.add( new AddonInfo() .withAddonTemplateName("coredns") .withAddonInstanceID("8fcaa506-809d-4f33-91b3-b27efcbeb540") .withType(AddonInfo.TypeEnum.fromValue("addonStatic")) ); AddonCheckSpec specbody = new AddonCheckSpec(); specbody.withClusterID("6b400e1c-4368-11f0-ba56-0255ac100037") .withAddonList(listSpecAddonList); body.withSpec(specbody); body.withApiVersion("v3"); body.withKind("AddonCheck"); request.withBody(body); try { BatchCreateAddonPrecheckResponse response = client.batchCreateAddonPrecheck(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
创建一个coredns插件的检查任务,检查类型为插件升级。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcce.v3.region.cce_region import CceRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcce.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchCreateAddonPrecheckRequest() request.cluster_id = "{cluster_id}" listValuesAddonList = { "basic": "{\"rbac_enabled\":true,\"swr_user\":\"hwofficial\",\"image_version\":\"1.17.15\",\"cluster_ip\":\"10.247.3.10\",\"platform\":\"linux-amd64\",\"swr_addr\":\"\"}", "custom": "{\"tenant_id\":\"0504201b6c80256b2f08c0099f0c8fe4\",\"cluster_id\":\"8fcaa506-809d-4f33-91b3-b27efcbeb540\",\"stub_domains\":{},\"upstream_nameservers\":[]}", "flavor": "{\"replicas\":2,\"name\":2500,\"resources\":[{\"limitsCpu\":\"500m\",\"name\":\"coredns\",\"limitsMem\":\"512Mi\",\"requestsMem\":\"512Mi\",\"requestsCpu\":\"500m\"}]}" } listAddonListSpec = [ AddonInfo( addon_template_name="coredns", addon_instance_id="8fcaa506-809d-4f33-91b3-b27efcbeb540", type="addonUpgrade", values=listValuesAddonList ) ] specbody = AddonCheckSpec( cluster_id="6b400e1c-4368-11f0-ba56-0255ac100037", addon_list=listAddonListSpec ) request.body = AddonCheckRequest( spec=specbody, api_version="v3", kind="AddonCheck" ) response = client.batch_create_addon_precheck(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
创建一个coredns插件的检查任务,检查类型为插件巡检。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcce.v3.region.cce_region import CceRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcce.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchCreateAddonPrecheckRequest() request.cluster_id = "{cluster_id}" listAddonListSpec = [ AddonInfo( addon_template_name="coredns", addon_instance_id="8fcaa506-809d-4f33-91b3-b27efcbeb540", type="addonStatic" ) ] specbody = AddonCheckSpec( cluster_id="6b400e1c-4368-11f0-ba56-0255ac100037", addon_list=listAddonListSpec ) request.body = AddonCheckRequest( spec=specbody, api_version="v3", kind="AddonCheck" ) response = client.batch_create_addon_precheck(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
创建一个coredns插件的检查任务,检查类型为插件升级。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchCreateAddonPrecheckRequest{} request.ClusterId = "{cluster_id}" var listValuesAddonList = map[string]interface{}{ "basic": "{\"rbac_enabled\":true,\"swr_user\":\"hwofficial\",\"image_version\":\"1.17.15\",\"cluster_ip\":\"10.247.3.10\",\"platform\":\"linux-amd64\",\"swr_addr\":\"\"}", "custom": "{\"tenant_id\":\"0504201b6c80256b2f08c0099f0c8fe4\",\"cluster_id\":\"8fcaa506-809d-4f33-91b3-b27efcbeb540\",\"stub_domains\":{},\"upstream_nameservers\":[]}", "flavor": "{\"replicas\":2,\"name\":2500,\"resources\":[{\"limitsCpu\":\"500m\",\"name\":\"coredns\",\"limitsMem\":\"512Mi\",\"requestsMem\":\"512Mi\",\"requestsCpu\":\"500m\"}]}", } var listAddonListSpec = []model.AddonInfo{ { AddonTemplateName: "coredns", AddonInstanceID: "8fcaa506-809d-4f33-91b3-b27efcbeb540", Type: model.GetAddonInfoTypeEnum().ADDON_UPGRADE, Values: listValuesAddonList, }, } specbody := &model.AddonCheckSpec{ ClusterID: "6b400e1c-4368-11f0-ba56-0255ac100037", AddonList: listAddonListSpec, } request.Body = &model.AddonCheckRequest{ Spec: specbody, ApiVersion: "v3", Kind: "AddonCheck", } response, err := client.BatchCreateAddonPrecheck(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
创建一个coredns插件的检查任务,检查类型为插件巡检。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchCreateAddonPrecheckRequest{} request.ClusterId = "{cluster_id}" var listAddonListSpec = []model.AddonInfo{ { AddonTemplateName: "coredns", AddonInstanceID: "8fcaa506-809d-4f33-91b3-b27efcbeb540", Type: model.GetAddonInfoTypeEnum().ADDON_STATIC, }, } specbody := &model.AddonCheckSpec{ ClusterID: "6b400e1c-4368-11f0-ba56-0255ac100037", AddonList: listAddonListSpec, } request.Body = &model.AddonCheckRequest{ Spec: specbody, ApiVersion: "v3", Kind: "AddonCheck", } response, err := client.BatchCreateAddonPrecheck(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
201 |
表示在指定集群下批量创建插件检查任务下发成功。 |
错误码
请参见错误码。