文档首页/ 云容器引擎 CCE/ API参考/ API/ 节点池管理/ 同步节点池 - UpgradeNodePool
更新时间:2026-08-24 GMT+08:00
分享

同步节点池 - UpgradeNodePool

功能介绍

该API用于同步节点池中已有节点的配置

集群管理的URL格式为:https://Endpoint/uri。其中uri为资源路径,也即API访问的路径

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,需具备如下身份策略权限。

    授权项

    访问级别

    资源类型(*为必须)

    条件键

    别名

    依赖的授权项

    cce:nodepool:upgradeNodepool

    Write

    cluster *

    -

    cce:nodepool:update

    -

    -

    g:EnterpriseProjectId

URI

POST /api/v3/projects/{project_id}/clusters/{cluster_id}/nodepools/{nodepool_id}/operation/upgrade

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,获取方式请参见如何获取接口URI中参数

约束限制:

不涉及

取值范围:

账号的项目ID

默认取值:

不涉及

cluster_id

String

参数解释:

集群ID,获取方式请参见如何获取接口URI中参数

约束限制:

不涉及

取值范围:

集群ID

默认取值:

不涉及

nodepool_id

String

参数解释:

节点池ID,获取方式请参见如何获取接口URI中参数

约束限制:

不涉及

取值范围:

节点池ID

默认取值:

不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

Content-Type

String

参数解释:

消息体的类型(格式),默认为application/json,有其他取值时会在具体接口中专门说明。

约束限制:

GET方法不做校验

取值范围:

不涉及

默认取值:

不涉及

X-Auth-Token

String

参数解释:

调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值,获取方式请参见获取token

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

表3 请求Body参数

参数

是否必选

参数类型

描述

kind

String

参数解释:

API类型。

约束限制:

该值不可修改。

取值范围:

不涉及

默认取值:

NodePool

apiVersion

String

参数解释:

API版本。

约束限制:

该值不可修改

取值范围:

不涉及

默认取值:

v3

metadata

NodePoolMetadata object

节点池的元数据信息

spec

UpgradeNodePoolSpec object

参数解释

同步节点池请求详细参数

约束限制

不涉及

表4 NodePoolMetadata

参数

是否必选

参数类型

描述

name

String

参数解释

节点名池名称。

约束限制

不允许创建名为 DefaultPool 的节点池。

取值范围

以小写字母开头,由小写字母、数字、中划线(-)组成,长度范围1-63位,且不能以中划线(-)结尾。

默认取值

不涉及

uid

String

参数解释

节点池的uid。

约束限制

创建成功后自动生成,填写无效。

取值范围

不涉及

默认取值

不涉及

annotations

Map<String,String>

参数解释

节点池的注解,以key value对表示。

约束限制

仅用于查询,不支持请求时传入,填写无效。

updateTimestamp

String

参数解释

节点池更新时间。

约束限制

更新节点池时自动记录,不支持传入。

取值范围

不涉及

默认取值

不涉及

creationTimestamp

String

参数解释

节点池创建时间。

约束限制

创建节点池时自动记录,不支持传入。

取值范围

不涉及

默认取值

不涉及

resourceVersion

Integer

参数解释

节点池最后更新时间的时间戳。

约束限制

创建节点池时自动记录,不支持传入。

取值范围

不涉及

默认取值

不涉及

表5 UpgradeNodePoolSpec

参数

是否必选

参数类型

描述

maxUnavailable

Integer

参数解释

每批最大同步节点。节点升级时,允许节点不可用的最大数量。节点重置方式进行同步时节点将不可用,请合理设置该参数,尽量避免出现集群节点不可用数量过多导致Pod无法调度的情况。

约束限制

不涉及

取值范围

取值范围[1-20]

默认取值

不涉及

nodeIDs

Array of strings

参数解释

本次操作同步的节点池中选择的节点ID列表,获取方式请参见如何获取接口URI中参数

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

nodePoolID

String

参数解释

节点池ID,获取方式请参见如何获取接口URI中参数

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

nodeTemplate

UpgradeNodePoolSpecNodeTemplate object

参数解释

同步节点池模板参数

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表6 UpgradeNodePoolSpecNodeTemplate

参数

是否必选

参数类型

描述

lifeCycle

NodeLifecycleConfig object

参数解释

节点自定义生命周期配置

约束限制

不涉及

login

Login object

参数解释

节点的登录方式。密钥对和密码登录方式二者必选其一。

约束限制

不涉及

volumeConfig

VolumeConfig object

参数解释

节点池同步场景磁盘配置。

约束限制

不涉及

表7 NodeLifecycleConfig

参数

是否必选

参数类型

描述

preInstall

String

参数解释

安装前执行脚本。

约束限制

安装前/后执行脚本统一计算字符,转码后的字符总数不能超过10240。

输入的值需要经过Base64编码,方法如下:

echo -n "待编码内容" | base64

取值范围

不涉及

默认取值

不涉及

postInstall

String

参数解释

安装后执行脚本。

约束限制

安装前/后执行脚本统一计算字符,转码后的字符总数不能超过10240。

输入的值需要经过Base64编码,方法如下:

echo -n "待编码内容" | base64

取值范围

不涉及

默认取值

不涉及

waitPostInstallFinish

Boolean

参数解释:

该参数用于控制重置/纳管/批量重置节点时, post-install脚本执行完成前允许节点调度 的行为。当操作的节点属于节点池时,以节点池相关配置为准。当该参数未设置或者为false时,在kubernetes节点就绪时,容器即可被调度到可用节点。当该参数为true时,在kubernetes节点就绪时且post-install脚本执行完成时,容器才可被调度到可用节点。

约束限制:

不涉及

取值范围:

  • false:在kubernetes节点就绪时,容器即可被调度到可用节点。

  • true:在kubernetes节点就绪时且post-install脚本执行完成时,容器才可被调度到可用节点。

默认取值:

false

表8 Login

参数

是否必选

参数类型

描述

sshKey

String

参数解释

选择密钥对方式登录时的密钥对名称。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

userPassword

UserPassword object

参数解释

选择密码方式登录时的账号密码信息,之后可通过此账号密码登录节点。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

removeUserPassword

Boolean

参数解释

更新节点池时,移除当前节点池密码方式登录的配置

约束限制

仅更新节点池场景支持该参数,设置为true时不允许设置userPassword

取值范围

不涉及

默认取值

false

removeSSHKey

Boolean

参数解释

更新节点池时,移除当前节点池密钥对方式登录的配置

约束限制

仅更新节点池场景支持该参数,设置为true时不允许设置sshKey

取值范围

不涉及

默认取值

false

表9 UserPassword

参数

是否必选

参数类型

描述

username

String

参数解释

登录账号,默认为“root”。

约束限制

不涉及

取值范围

不涉及

默认取值

root。

password

String

参数解释

登录密码,若创建节点通过用户名密码方式,即使用该字段,则响应体中该字段作屏蔽展示。

约束限制

创建节点时password字段需要加盐加密,具体方法请参见创建节点时password字段加盐加密

取值范围

密码复杂度要求:

  • 长度为8-26位。

  • 密码至少必须包含大写字母、小写字母、数字和特殊字符(!@$%^-_=+[{}]:,./?)中的三种。

  • 密码不能包含用户名或用户名的逆序。

默认取值

不涉及

表10 VolumeConfig

参数

是否必选

参数类型

描述

volumeResetPolicy

String

参数解释

节点重置时磁盘数据的保留策略。

不传或该字段为空时,默认使用reset_managed_volumes策略清空由CCE管理的数据盘。

约束限制

当保留自定义挂载卷时,挂载到指定目录与作为持久存储卷的高级配置不允许修改。

取值范围

  • reset_managed_volumes:清空由CCE管理的数据盘。

  • retain_custom_volumes:保留用户自定义挂载卷(包括挂载到指定目录的卷和用作本地持久卷的卷),集群版本需为v1.29.15-r90、v1.30.14-r90、v1.31.14-r50、v1.32.13-r20、v1.33.12-r0、v1.34.8-r0、v1.35.5-r0、v1.36.1-r10或以上版本。

默认取值

reset_managed_volumes

响应参数

状态码:200

表11 响应Body参数

参数

参数类型

描述

jobid

String

参数解释

提交任务成功后返回的任务ID,用户可以使用该ID对任务执行情况进行查询。

取值范围

不涉及

请求示例

  • 同步节点池(自建节点池)

    {
      "spec" : {
        "maxUnavailable" : 1,
        "nodeIDs" : [ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb" ],
        "nodePoolID" : "cccccccc-cccc-cccc-cccc-cccccccccccc"
      }
    }
  • 同步节点池(默认节点池)

    {
      "spec" : {
        "maxUnavailable" : 1,
        "nodeIDs" : [ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb" ],
        "nodePoolID" : "DefaultPool",
        "nodeTemplate" : {
          "lifeCycle" : {
            "preInstall" : "ZWNobyAx",
            "postInstall" : "ZWNobyAx"
          },
          "login" : {
            "userPassword" : {
              "password" : "xxxxx",
              "username" : "root"
            }
          }
        }
      }
    }

响应示例

状态码:200

表示获取任务信息成功。

{
  "jobid" : "7b9a1695-ab29-11ef-a522-0255ac101231"
}

SDK代码示例

SDK代码示例如下。

  • 同步节点池(自建节点池)

     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
    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 UpgradeNodePoolSolution {
    
        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();
            UpgradeNodePoolRequest request = new UpgradeNodePoolRequest();
            request.withClusterId("{cluster_id}");
            request.withNodepoolId("{nodepool_id}");
            UpgradeNodePool body = new UpgradeNodePool();
            List<String> listSpecNodeIDs = new ArrayList<>();
            listSpecNodeIDs.add("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
            listSpecNodeIDs.add("bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb");
            NodePoolUpgradeSpec specbody = new NodePoolUpgradeSpec();
            specbody.withMaxUnavailable(1)
                .withNodeIDs(listSpecNodeIDs)
                .withNodePoolID("cccccccc-cccc-cccc-cccc-cccccccccccc");
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpgradeNodePoolResponse response = client.upgradeNodePool(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());
            }
        }
    }
    
  • 同步节点池(默认节点池)

     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
    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 UpgradeNodePoolSolution {
    
        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();
            UpgradeNodePoolRequest request = new UpgradeNodePoolRequest();
            request.withClusterId("{cluster_id}");
            request.withNodepoolId("{nodepool_id}");
            UpgradeNodePool body = new UpgradeNodePool();
            UserPassword userPasswordLogin = new UserPassword();
            userPasswordLogin.withUsername("root")
                .withPassword("xxxxx");
            Login loginNodeTemplate = new Login();
            loginNodeTemplate.withUserPassword(userPasswordLogin);
            NodeTemplate nodeTemplateSpec = new NodeTemplate();
            nodeTemplateSpec.withLogin(loginNodeTemplate);
            List<String> listSpecNodeIDs = new ArrayList<>();
            listSpecNodeIDs.add("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
            listSpecNodeIDs.add("bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb");
            NodePoolUpgradeSpec specbody = new NodePoolUpgradeSpec();
            specbody.withMaxUnavailable(1)
                .withNodeIDs(listSpecNodeIDs)
                .withNodePoolID("DefaultPool")
                .withNodeTemplate(nodeTemplateSpec);
            body.withSpec(specbody);
            request.withBody(body);
            try {
                UpgradeNodePoolResponse response = client.upgradeNodePool(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());
            }
        }
    }
    
  • 同步节点池(自建节点池)

     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
    # 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 = UpgradeNodePoolRequest()
            request.cluster_id = "{cluster_id}"
            request.nodepool_id = "{nodepool_id}"
            listNodeIDsSpec = [
                "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
                "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb"
            ]
            specbody = NodePoolUpgradeSpec(
                max_unavailable=1,
                node_i_ds=listNodeIDsSpec,
                node_pool_id="cccccccc-cccc-cccc-cccc-cccccccccccc"
            )
            request.body = UpgradeNodePool(
                spec=specbody
            )
            response = client.upgrade_node_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 同步节点池(默认节点池)

     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
    # 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 = UpgradeNodePoolRequest()
            request.cluster_id = "{cluster_id}"
            request.nodepool_id = "{nodepool_id}"
            userPasswordLogin = UserPassword(
                username="root",
                password="xxxxx"
            )
            loginNodeTemplate = Login(
                user_password=userPasswordLogin
            )
            nodeTemplateSpec = NodeTemplate(
                login=loginNodeTemplate
            )
            listNodeIDsSpec = [
                "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
                "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb"
            ]
            specbody = NodePoolUpgradeSpec(
                max_unavailable=1,
                node_i_ds=listNodeIDsSpec,
                node_pool_id="DefaultPool",
                node_template=nodeTemplateSpec
            )
            request.body = UpgradeNodePool(
                spec=specbody
            )
            response = client.upgrade_node_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 同步节点池(自建节点池)

     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
    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, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := cce.CceClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := cce.NewCceClient(hcClient)
    
        request := &model.UpgradeNodePoolRequest{}
    	request.ClusterId = "{cluster_id}"
    	request.NodepoolId = "{nodepool_id}"
    	var listNodeIDsSpec = []string{
            "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
    	    "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb",
        }
    	maxUnavailableSpec:= int32(1)
    	specbody := &model.NodePoolUpgradeSpec{
    		MaxUnavailable: &maxUnavailableSpec,
    		NodeIDs: &listNodeIDsSpec,
    		NodePoolID: "cccccccc-cccc-cccc-cccc-cccccccccccc",
    	}
    	request.Body = &model.UpgradeNodePool{
    		Spec: specbody,
    	}
    	response, err := client.UpgradeNodePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 同步节点池(默认节点池)

     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
    73
    74
    75
    76
    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, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := cce.CceClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := cce.NewCceClient(hcClient)
    
        request := &model.UpgradeNodePoolRequest{}
    	request.ClusterId = "{cluster_id}"
    	request.NodepoolId = "{nodepool_id}"
    	usernameUserPassword:= "root"
    	userPasswordLogin := &model.UserPassword{
    		Username: &usernameUserPassword,
    		Password: "xxxxx",
    	}
    	loginNodeTemplate := &model.Login{
    		UserPassword: userPasswordLogin,
    	}
    	nodeTemplateSpec := &model.NodeTemplate{
    		Login: loginNodeTemplate,
    	}
    	var listNodeIDsSpec = []string{
            "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
    	    "bbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb",
        }
    	maxUnavailableSpec:= int32(1)
    	specbody := &model.NodePoolUpgradeSpec{
    		MaxUnavailable: &maxUnavailableSpec,
    		NodeIDs: &listNodeIDsSpec,
    		NodePoolID: "DefaultPool",
    		NodeTemplate: nodeTemplateSpec,
    	}
    	request.Body = &model.UpgradeNodePool{
    		Spec: specbody,
    	}
    	response, err := client.UpgradeNodePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

表示获取任务信息成功。

错误码

请参见错误码

相关文档