| 1 |
package cs |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
"net/url" |
| 6 |
|
| 7 |
"math" |
| 8 |
"strconv" |
| 9 |
"time" |
| 10 |
|
| 11 |
"fmt" |
| 12 |
|
| 13 |
"encoding/json" |
| 14 |
"github.com/denverdino/aliyungo/common" |
| 15 |
"github.com/denverdino/aliyungo/ecs" |
| 16 |
) |
| 17 |
|
| 18 |
type ClusterState string |
| 19 |
|
| 20 |
const ( |
| 21 |
Initial = ClusterState("initial") |
| 22 |
Running = ClusterState("running") |
| 23 |
Updating = ClusterState("updating") |
| 24 |
Scaling = ClusterState("scaling") |
| 25 |
Failed = ClusterState("failed") |
| 26 |
Deleting = ClusterState("deleting") |
| 27 |
DeleteFailed = ClusterState("deleteFailed") |
| 28 |
Deleted = ClusterState("deleted") |
| 29 |
InActive = ClusterState("inactive") |
| 30 |
) |
| 31 |
|
| 32 |
type NodeStatus struct { |
| 33 |
Health int64 `json:"health"` |
| 34 |
Unhealth int64 `json:"unhealth"` |
| 35 |
} |
| 36 |
|
| 37 |
type NetworkModeType string |
| 38 |
|
| 39 |
const ( |
| 40 |
ClassicNetwork = NetworkModeType("classic") |
| 41 |
VPCNetwork = NetworkModeType("vpc") |
| 42 |
) |
| 43 |
|
| 44 |
|
| 45 |
type ClusterType struct { |
| 46 |
AgentVersion string `json:"agent_version"` |
| 47 |
ClusterID string `json:"cluster_id"` |
| 48 |
Name string `json:"name"` |
| 49 |
Created time.Time `json:"created"` |
| 50 |
ExternalLoadbalancerID string `json:"external_loadbalancer_id"` |
| 51 |
MasterURL string `json:"master_url"` |
| 52 |
NetworkMode NetworkModeType `json:"network_mode"` |
| 53 |
RegionID common.Region `json:"region_id"` |
| 54 |
SecurityGroupID string `json:"security_group_id"` |
| 55 |
Size int64 `json:"size"` |
| 56 |
State ClusterState `json:"state"` |
| 57 |
Updated time.Time `json:"updated"` |
| 58 |
VPCID string `json:"vpc_id"` |
| 59 |
VSwitchID string `json:"vswitch_id"` |
| 60 |
NodeStatus string `json:"node_status"` |
| 61 |
DockerVersion string `json:"docker_version"` |
| 62 |
ClusterType string `json:"cluster_type"` |
| 63 |
} |
| 64 |
|
| 65 |
func (client *Client) DescribeClusters(nameFilter string) (clusters []ClusterType, err error) { |
| 66 |
query := make(url.Values) |
| 67 |
|
| 68 |
if nameFilter != "" { |
| 69 |
query.Add("name", nameFilter) |
| 70 |
} |
| 71 |
|
| 72 |
err = client.Invoke("", http.MethodGet, "/clusters", query, nil, &clusters) |
| 73 |
return |
| 74 |
} |
| 75 |
|
| 76 |
func (client *Client) DescribeCluster(id string) (cluster ClusterType, err error) { |
| 77 |
err = client.Invoke("", http.MethodGet, "/clusters/"+id, nil, nil, &cluster) |
| 78 |
return |
| 79 |
} |
| 80 |
|
| 81 |
type ClusterCreationArgs struct { |
| 82 |
Name string `json:"name"` |
| 83 |
Size int64 `json:"size"` |
| 84 |
NetworkMode NetworkModeType `json:"network_mode"` |
| 85 |
SubnetCIDR string `json:"subnet_cidr,omitempty"` |
| 86 |
InstanceType string `json:"instance_type"` |
| 87 |
VPCID string `json:"vpc_id,omitempty"` |
| 88 |
VSwitchID string `json:"vswitch_id,omitempty"` |
| 89 |
Password string `json:"password"` |
| 90 |
DataDiskSize int64 `json:"data_disk_size"` |
| 91 |
DataDiskCategory ecs.DiskCategory `json:"data_disk_category"` |
| 92 |
ECSImageID string `json:"ecs_image_id,omitempty"` |
| 93 |
IOOptimized ecs.IoOptimized `json:"io_optimized"` |
| 94 |
ReleaseEipFlag bool `json:"release_eip_flag"` |
| 95 |
} |
| 96 |
|
| 97 |
type ClusterCreationResponse struct { |
| 98 |
Response |
| 99 |
ClusterID string `json:"cluster_id"` |
| 100 |
} |
| 101 |
|
| 102 |
func (client *Client) CreateCluster(region common.Region, args *ClusterCreationArgs) (cluster ClusterCreationResponse, err error) { |
| 103 |
err = client.Invoke(region, http.MethodPost, "/clusters", nil, args, &cluster) |
| 104 |
return |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
type KubernetesStackArgs struct { |
| 109 |
VPCID string `json:"VpcId,omitempty"` |
| 110 |
VSwitchID string `json:"VSwitchId,omitempty"` |
| 111 |
MasterInstanceType string `json:"MasterInstanceType,omitempty"` |
| 112 |
WorkerInstanceType string `json:"WorkerInstanceType,omitempty"` |
| 113 |
NumOfNodes int64 `json:"NumOfNodes,omitempty"` |
| 114 |
Password string `json:"LoginPassword,omitempty"` |
| 115 |
DockerVersion string `json:"DockerVersion,omitempty"` |
| 116 |
KubernetesVersion string `json:"KubernetesVersion,omitempty"` |
| 117 |
ZoneId string `json:"ZoneId,omitempty"` |
| 118 |
ContainerCIDR string `json:"ContainerCIDR,omitempty"` |
| 119 |
ServiceCIDR string `json:"ServiceCIDR,omitempty"` |
| 120 |
SSHFlags bool `json:"SSHFlags,omitempty"` |
| 121 |
MasterSystemDiskSize int64 `json:"MasterSystemDiskSize,omitempty"` |
| 122 |
MasterSystemDiskCategory ecs.DiskCategory `json:"MasterSystemDiskCategory,omitempty"` |
| 123 |
WorkerSystemDiskSize int64 `json:"WorkerSystemDiskSize,omitempty"` |
| 124 |
WorkerSystemDiskCategory ecs.DiskCategory `json:"WorkerSystemDiskCategory,omitempty"` |
| 125 |
ImageID string `json:"ImageId,omitempty"` |
| 126 |
CloudMonitorFlags bool `json:"CloudMonitorFlags,omitempty"` |
| 127 |
SNatEntry bool `json:"SNatEntry,omitempty"` |
| 128 |
} |
| 129 |
|
| 130 |
type KubernetesCreationArgs struct { |
| 131 |
DisableRollback bool `json:"disable_rollback"` |
| 132 |
Name string `json:"name"` |
| 133 |
TimeoutMins int64 `json:"timeout_mins"` |
| 134 |
ZoneId string `json:"zoneid,omitempty"` |
| 135 |
VPCID string `json:"vpcid,omitempty"` |
| 136 |
VSwitchId string `json:"vswitchid,omitempty"` |
| 137 |
ContainerCIDR string `json:"container_cidr,omitempty"` |
| 138 |
ServiceCIDR string `json:"service_cidr,omitempty"` |
| 139 |
MasterInstanceType string `json:"master_instance_type,omitempty"` |
| 140 |
MasterSystemDiskSize int64 `json:"master_system_disk_size,omitempty"` |
| 141 |
MasterSystemDiskCategory ecs.DiskCategory `json:"master_system_disk_category,omitempty"` |
| 142 |
WorkerInstanceType string `json:"worker_instance_type,omitempty"` |
| 143 |
WorkerSystemDiskSize int64 `json:"worker_system_disk_size,omitempty"` |
| 144 |
WorkerSystemDiskCategory ecs.DiskCategory `json:"worker_system_disk_category,omitempty"` |
| 145 |
WorkerDataDisk bool `json:"worker_data_disk,omitempty"` |
| 146 |
WorkerDataDiskCategory string `json:"worker_data_disk_category,omitempty"` |
| 147 |
WorkerDataDiskSize int64 `json:"worker_data_disk_size,omitempty"` |
| 148 |
LoginPassword string `json:"login_password,omitempty"` |
| 149 |
KeyPair string `json:"key_pair,omitempty"` |
| 150 |
NumOfNodes int64 `json:"num_of_nodes,omitempty"` |
| 151 |
SNatEntry bool `json:"snat_entry,omitempty"` |
| 152 |
SSHFlags bool `json:"ssh_flags,omitempty"` |
| 153 |
CloudMonitorFlags bool `json:"cloud_monitor_flags,omitempty"` |
| 154 |
|
| 155 |
ClusterType string `json:"cluster_type"` |
| 156 |
Network string `json:"network,omitempty"` |
| 157 |
|
| 158 |
KubernetesVersion string `json:"kubernetes_version,omitempty"` |
| 159 |
StackParams KubernetesStackArgs `json:"stack_params,omitempty"` |
| 160 |
} |
| 161 |
|
| 162 |
type KubernetesMultiAZCreationArgs struct { |
| 163 |
DisableRollback bool `json:"disable_rollback"` |
| 164 |
Name string `json:"name"` |
| 165 |
TimeoutMins int64 `json:"timeout_mins"` |
| 166 |
ClusterType string `json:"cluster_type"` |
| 167 |
MultiAZ bool `json:"multi_az,omitempty"` |
| 168 |
VPCID string `json:"vpcid,omitempty"` |
| 169 |
ContainerCIDR string `json:"container_cidr"` |
| 170 |
ServiceCIDR string `json:"service_cidr"` |
| 171 |
VSwitchIdA string `json:"vswitch_id_a,omitempty"` |
| 172 |
VSwitchIdB string `json:"vswitch_id_b,omitempty"` |
| 173 |
VSwitchIdC string `json:"vswitch_id_c,omitempty"` |
| 174 |
MasterInstanceTypeA string `json:"master_instance_type_a,omitempty"` |
| 175 |
MasterInstanceTypeB string `json:"master_instance_type_b,omitempty"` |
| 176 |
MasterInstanceTypeC string `json:"master_instance_type_c,omitempty"` |
| 177 |
MasterSystemDiskCategory ecs.DiskCategory `json:"master_system_disk_category"` |
| 178 |
MasterSystemDiskSize int64 `json:"master_system_disk_size"` |
| 179 |
WorkerInstanceTypeA string `json:"worker_instance_type_a,omitempty"` |
| 180 |
WorkerInstanceTypeB string `json:"worker_instance_type_b,omitempty"` |
| 181 |
WorkerInstanceTypeC string `json:"worker_instance_type_c,omitempty"` |
| 182 |
WorkerSystemDiskCategory ecs.DiskCategory `json:"worker_system_disk_category"` |
| 183 |
WorkerSystemDiskSize int64 `json:"worker_system_disk_size"` |
| 184 |
WorkerDataDisk bool `json:"worker_data_disk"` |
| 185 |
WorkerDataDiskCategory string `json:"worker_data_disk_category"` |
| 186 |
WorkerDataDiskSize int64 `json:"worker_data_disk_size"` |
| 187 |
NumOfNodesA int64 `json:"num_of_nodes_a"` |
| 188 |
NumOfNodesB int64 `json:"num_of_nodes_b"` |
| 189 |
NumOfNodesC int64 `json:"num_of_nodes_c"` |
| 190 |
LoginPassword string `json:"login_password,omitempty"` |
| 191 |
KeyPair string `json:"key_pair,omitempty"` |
| 192 |
SSHFlags bool `json:"ssh_flags"` |
| 193 |
CloudMonitorFlags bool `json:"cloud_monitor_flags"` |
| 194 |
|
| 195 |
KubernetesVersion string `json:"kubernetes_version,omitempty"` |
| 196 |
Network string `json:"network,omitempty"` |
| 197 |
} |
| 198 |
|
| 199 |
func (client *Client) CreateKubernetesMultiAZCluster(region common.Region, args *KubernetesMultiAZCreationArgs) (cluster ClusterCreationResponse, err error) { |
| 200 |
err = client.Invoke(region, http.MethodPost, "/clusters", nil, args, &cluster) |
| 201 |
return |
| 202 |
} |
| 203 |
|
| 204 |
func (client *Client) CreateKubernetesCluster(region common.Region, args *KubernetesCreationArgs) (cluster ClusterCreationResponse, err error) { |
| 205 |
err = client.Invoke(region, http.MethodPost, "/clusters", nil, args, &cluster) |
| 206 |
return |
| 207 |
} |
| 208 |
|
| 209 |
type KubernetesClusterMetaData struct { |
| 210 |
DockerVersion string `json:"DockerVersion"` |
| 211 |
EtcdVersion string `json:"EtcdVersion"` |
| 212 |
KubernetesVersion string `json:"KubernetesVersion"` |
| 213 |
MultiAZ bool `json:"MultiAZ"` |
| 214 |
SubClass string `json:"SubClass"` |
| 215 |
} |
| 216 |
|
| 217 |
type KubernetesClusterParameter struct { |
| 218 |
ServiceCidr string `json:"ServiceCIDR"` |
| 219 |
ContainerCidr string `json:"ContainerCIDR"` |
| 220 |
DockerVersion string `json:"DockerVersion"` |
| 221 |
EtcdVersion string `json:"EtcdVersion"` |
| 222 |
KubernetesVersion string `json:"KubernetesVersion"` |
| 223 |
VPCID string `json:"VpcId"` |
| 224 |
KeyPair string `json:"KeyPair"` |
| 225 |
MasterSystemDiskCategory string `json:"MasterSystemDiskCategory"` |
| 226 |
MasterSystemDiskSize string `json:"MasterSystemDiskSize"` |
| 227 |
WorkerSystemDiskCategory string `json:"WorkerSystemDiskCategory"` |
| 228 |
WorkerSystemDiskSize string `json:"WorkerSystemDiskSize"` |
| 229 |
ZoneId string `json:"ZoneId"` |
| 230 |
|
| 231 |
|
| 232 |
MasterInstanceType string `json:"MasterInstanceType"` |
| 233 |
WorkerInstanceType string `json:"WorkerInstanceType"` |
| 234 |
NumOfNodes string `json:"NumOfNodes"` |
| 235 |
VSwitchID string `json:"VSwitchId"` |
| 236 |
|
| 237 |
|
| 238 |
MasterInstanceTypeA string `json:"MasterInstanceTypeA"` |
| 239 |
MasterInstanceTypeB string `json:"MasterInstanceTypeB"` |
| 240 |
MasterInstanceTypeC string `json:"MasterInstanceTypeC"` |
| 241 |
WorkerInstanceTypeA string `json:"WorkerInstanceTypeA"` |
| 242 |
WorkerInstanceTypeB string `json:"WorkerInstanceTypeB"` |
| 243 |
WorkerInstanceTypeC string `json:"WorkerInstanceTypeC"` |
| 244 |
NumOfNodesA string `json:"NumOfNodesA"` |
| 245 |
NumOfNodesB string `json:"NumOfNodesB"` |
| 246 |
NumOfNodesC string `json:"NumOfNodesC"` |
| 247 |
VSwitchIdA string `json:"VSwitchIdA"` |
| 248 |
VSwitchIdB string `json:"VSwitchIdB"` |
| 249 |
VSwitchIdC string `json:"VSwitchIdC"` |
| 250 |
} |
| 251 |
|
| 252 |
type KubernetesCluster struct { |
| 253 |
ClusterType |
| 254 |
|
| 255 |
AgentVersion string `json:"agent_version"` |
| 256 |
ClusterID string `json:"cluster_id"` |
| 257 |
Name string `json:"name"` |
| 258 |
Created time.Time `json:"created"` |
| 259 |
MasterURL string `json:"master_url"` |
| 260 |
NetworkMode NetworkModeType `json:"network_mode"` |
| 261 |
RegionID common.Region `json:"region_id"` |
| 262 |
SecurityGroupID string `json:"security_group_id"` |
| 263 |
Size int64 `json:"size"` |
| 264 |
State ClusterState `json:"state"` |
| 265 |
Updated time.Time `json:"updated"` |
| 266 |
VPCID string `json:"vpc_id"` |
| 267 |
VSwitchID string `json:"vswitch_id"` |
| 268 |
NodeStatus string `json:"node_status"` |
| 269 |
DockerVersion string `json:"docker_version"` |
| 270 |
|
| 271 |
ZoneId string `json:"zone_id"` |
| 272 |
RawMetaData string `json:"meta_data,omitempty"` |
| 273 |
MetaData KubernetesClusterMetaData |
| 274 |
InitVersion string `json:"init_version"` |
| 275 |
CurrentVersion string `json:"current_version"` |
| 276 |
ExternalLoadbalancerId string `json:"external_loadbalancer_id"` |
| 277 |
|
| 278 |
Parameters KubernetesClusterParameter `json:"parameters"` |
| 279 |
} |
| 280 |
|
| 281 |
func (client *Client) DescribeKubernetesCluster(id string) (cluster KubernetesCluster, err error) { |
| 282 |
err = client.Invoke("", http.MethodGet, "/clusters/"+id, nil, nil, &cluster) |
| 283 |
if err != nil { |
| 284 |
return cluster, err |
| 285 |
} |
| 286 |
var metaData KubernetesClusterMetaData |
| 287 |
err = json.Unmarshal([]byte(cluster.RawMetaData), &metaData) |
| 288 |
cluster.MetaData = metaData |
| 289 |
cluster.RawMetaData = "" |
| 290 |
return |
| 291 |
} |
| 292 |
|
| 293 |
type ClusterResizeArgs struct { |
| 294 |
Size int64 `json:"size"` |
| 295 |
InstanceType string `json:"instance_type"` |
| 296 |
Password string `json:"password"` |
| 297 |
DataDiskSize int64 `json:"data_disk_size"` |
| 298 |
DataDiskCategory ecs.DiskCategory `json:"data_disk_category"` |
| 299 |
ECSImageID string `json:"ecs_image_id,omitempty"` |
| 300 |
IOOptimized ecs.IoOptimized `json:"io_optimized"` |
| 301 |
} |
| 302 |
|
| 303 |
type ModifyClusterNameArgs struct { |
| 304 |
Name string `json:"name"` |
| 305 |
} |
| 306 |
|
| 307 |
func (client *Client) ResizeCluster(clusterID string, args *ClusterResizeArgs) error { |
| 308 |
return client.Invoke("", http.MethodPut, "/clusters/"+clusterID, nil, args, nil) |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
func (client *Client) ResizeKubernetes(clusterID string, args *KubernetesCreationArgs) error { |
| 314 |
return client.Invoke("", http.MethodPut, "/clusters/"+clusterID, nil, args, nil) |
| 315 |
} |
| 316 |
|
| 317 |
type KubernetesClusterResizeArgs struct { |
| 318 |
DisableRollback bool `json:"disable_rollback"` |
| 319 |
TimeoutMins int64 `json:"timeout_mins"` |
| 320 |
LoginPassword string `json:"login_password,omitempty"` |
| 321 |
|
| 322 |
|
| 323 |
WorkerInstanceType string `json:"worker_instance_type"` |
| 324 |
NumOfNodes int64 `json:"num_of_nodes"` |
| 325 |
|
| 326 |
|
| 327 |
WorkerInstanceTypeA string `json:"worker_instance_type_a"` |
| 328 |
WorkerInstanceTypeB string `json:"worker_instance_type_b"` |
| 329 |
WorkerInstanceTypeC string `json:"worker_instance_type_c"` |
| 330 |
NumOfNodesA int64 `json:"num_of_nodes_a"` |
| 331 |
NumOfNodesB int64 `json:"num_of_nodes_b"` |
| 332 |
NumOfNodesC int64 `json:"num_of_nodes_c"` |
| 333 |
} |
| 334 |
|
| 335 |
func (client *Client) ResizeKubernetesCluster(clusterID string, args *KubernetesClusterResizeArgs) error { |
| 336 |
return client.Invoke("", http.MethodPut, "/clusters/"+clusterID, nil, args, nil) |
| 337 |
} |
| 338 |
|
| 339 |
func (client *Client) ModifyClusterName(clusterID, clusterName string) error { |
| 340 |
return client.Invoke("", http.MethodPost, "/clusters/"+clusterID+"/name/"+clusterName, nil, nil, nil) |
| 341 |
} |
| 342 |
|
| 343 |
func (client *Client) DeleteCluster(clusterID string) error { |
| 344 |
return client.Invoke("", http.MethodDelete, "/clusters/"+clusterID, nil, nil, nil) |
| 345 |
} |
| 346 |
|
| 347 |
type ClusterCerts struct { |
| 348 |
CA string `json:"ca,omitempty"` |
| 349 |
Key string `json:"key,omitempty"` |
| 350 |
Cert string `json:"cert,omitempty"` |
| 351 |
} |
| 352 |
|
| 353 |
func (client *Client) GetClusterCerts(id string) (certs ClusterCerts, err error) { |
| 354 |
err = client.Invoke("", http.MethodGet, "/clusters/"+id+"/certs", nil, nil, &certs) |
| 355 |
return |
| 356 |
} |
| 357 |
|
| 358 |
type ClusterConfig struct { |
| 359 |
Config string `json:"config"` |
| 360 |
} |
| 361 |
|
| 362 |
func (client *Client) GetClusterConfig(id string) (config ClusterConfig, err error) { |
| 363 |
err = client.Invoke("", http.MethodGet, "/k8s/"+id+"/user_config", nil, nil, &config) |
| 364 |
return |
| 365 |
} |
| 366 |
|
| 367 |
type KubernetesNodeType struct { |
| 368 |
InstanceType string `json:"instance_type"` |
| 369 |
IpAddress []string `json:"ip_address"` |
| 370 |
InstanceChargeType string `json:"instance_charge_type"` |
| 371 |
InstanceRole string `json:"instance_role"` |
| 372 |
CreationTime string `json:"creation_time"` |
| 373 |
InstanceName string `json:"instance_name"` |
| 374 |
InstanceTypeFamily string `json:"instance_type_family"` |
| 375 |
HostName string `json:"host_name"` |
| 376 |
ImageId string `json:"image_id"` |
| 377 |
InstanceId string `json:"instance_id"` |
| 378 |
} |
| 379 |
|
| 380 |
type GetKubernetesClusterNodesResponse struct { |
| 381 |
Response |
| 382 |
Page PaginationResult `json:"page"` |
| 383 |
Nodes []KubernetesNodeType `json:"nodes"` |
| 384 |
} |
| 385 |
|
| 386 |
func (client *Client) GetKubernetesClusterNodes(id string, pagination common.Pagination) (nodes []KubernetesNodeType, paginationResult *PaginationResult, err error) { |
| 387 |
response := &GetKubernetesClusterNodesResponse{} |
| 388 |
err = client.Invoke("", http.MethodGet, "/clusters/"+id+"/nodes?pageNumber="+strconv.Itoa(pagination.PageNumber)+"&pageSize="+strconv.Itoa(pagination.PageSize), nil, nil, &response) |
| 389 |
if err != nil { |
| 390 |
return nil, nil, err |
| 391 |
} |
| 392 |
|
| 393 |
return response.Nodes, &response.Page, nil |
| 394 |
} |
| 395 |
|
| 396 |
const ClusterDefaultTimeout = 300 |
| 397 |
const DefaultWaitForInterval = 10 |
| 398 |
const DefaultPreSleepTime = 240 |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
func (client *Client) WaitForClusterAsyn(clusterId string, status ClusterState, timeout int) error { |
| 403 |
if timeout <= 0 { |
| 404 |
timeout = ClusterDefaultTimeout |
| 405 |
} |
| 406 |
cluster, err := client.DescribeCluster(clusterId) |
| 407 |
if err != nil { |
| 408 |
return err |
| 409 |
} else if cluster.State == status { |
| 410 |
|
| 411 |
return nil |
| 412 |
} |
| 413 |
|
| 414 |
sleep := math.Min(float64(timeout), float64(DefaultPreSleepTime)) |
| 415 |
time.Sleep(time.Duration(sleep) * time.Second) |
| 416 |
|
| 417 |
for { |
| 418 |
cluster, err := client.DescribeCluster(clusterId) |
| 419 |
if err != nil { |
| 420 |
return err |
| 421 |
} else if cluster.State == Failed { |
| 422 |
return fmt.Errorf("Waitting for cluster %s %s failed. Looking the specified reason in the web console.", clusterId, status) |
| 423 |
} else if cluster.State == status { |
| 424 |
|
| 425 |
break |
| 426 |
} |
| 427 |
timeout = timeout - DefaultWaitForInterval |
| 428 |
if timeout <= 0 { |
| 429 |
return common.GetClientErrorFromString("Timeout") |
| 430 |
} |
| 431 |
time.Sleep(DefaultWaitForInterval * time.Second) |
| 432 |
} |
| 433 |
return nil |
| 434 |
} |
| 435 |
|
| 436 |
func (client *Client) GetProjectClient(clusterId string) (projectClient *ProjectClient, err error) { |
| 437 |
cluster, err := client.DescribeCluster(clusterId) |
| 438 |
if err != nil { |
| 439 |
return |
| 440 |
} |
| 441 |
|
| 442 |
certs, err := client.GetClusterCerts(clusterId) |
| 443 |
if err != nil { |
| 444 |
return |
| 445 |
} |
| 446 |
|
| 447 |
projectClient, err = NewProjectClient(clusterId, cluster.MasterURL, certs) |
| 448 |
|
| 449 |
if err != nil { |
| 450 |
return |
| 451 |
} |
| 452 |
|
| 453 |
projectClient.SetDebug(client.debug) |
| 454 |
|
| 455 |
return |
| 456 |
} |