yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/kube_nodes.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package qcloud 16 17 import ( 18 "fmt" 19 20 "yunion.io/x/pkg/errors" 21 22 "yunion.io/x/cloudmux/pkg/cloudprovider" 23 "yunion.io/x/cloudmux/pkg/multicloud" 24 ) 25 26 type SKubeNode struct { 27 multicloud.SResourceBase 28 QcloudTags 29 30 cluster *SKubeCluster 31 32 InstanceId string 33 InstanceRole string 34 FailedReason string 35 InstanceState string 36 DrainStatus string 37 InstanceAdvancedSettings struct { 38 MountTarget string 39 DockerGraphPath string 40 UserScript string 41 Unschedulable int 42 DesiredPodNumber int 43 PreStartUserScript string 44 Labels []struct { 45 Name string 46 Value string 47 } 48 DataDisks []struct { 49 DiskType string 50 FileSystem string 51 DiskSize int 52 AutoFormatAndMount bool 53 MountTarget string 54 DiskPartition string 55 } 56 ExtraArgs struct { 57 Kubelet []string 58 } 59 } 60 CreatedTime string 61 LanIP string 62 NodePoolId string 63 AutoscalingGroupId string 64 } 65 66 func (self *SKubeNode) GetId() string { 67 return self.InstanceId 68 } 69 70 func (self *SKubeNode) GetGlobalId() string { 71 return self.InstanceId 72 } 73 74 func (self *SKubeNode) GetName() string { 75 return self.InstanceId 76 } 77 78 func (self *SKubeNode) GetStatus() string { 79 return self.DrainStatus 80 } 81 82 func (self *SKubeNode) GetINodePoolId() string { 83 return self.NodePoolId 84 } 85 86 func (self *SKubeCluster) GetIKubeNodes() ([]cloudprovider.ICloudKubeNode, error) { 87 nodes := []SKubeNode{} 88 for { 89 part, total, err := self.region.GetKubeNodes(self.ClusterId, 100, len(nodes)/100) 90 if err != nil { 91 return nil, errors.Wrapf(err, "GetIKubeNodes") 92 } 93 nodes = append(nodes, part...) 94 if len(nodes) >= total || len(part) == 0 { 95 break 96 } 97 } 98 ret := []cloudprovider.ICloudKubeNode{} 99 for i := range nodes { 100 nodes[i].cluster = self 101 ret = append(ret, &nodes[i]) 102 } 103 return ret, nil 104 } 105 106 func (self *SRegion) GetKubeNodes(clusterId string, limit, offset int) ([]SKubeNode, int, error) { 107 if limit < 1 || limit > 100 { 108 limit = 100 109 } 110 params := map[string]string{ 111 "Limit": fmt.Sprintf("%d", limit), 112 "Offset": fmt.Sprintf("%d", offset), 113 "ClusterId": clusterId, 114 } 115 resp, err := self.tkeRequest("DescribeClusterInstances", params) 116 if err != nil { 117 return nil, 0, errors.Wrapf(err, "DescribeClusterInstances") 118 } 119 nodes := []SKubeNode{} 120 err = resp.Unmarshal(&nodes, "InstanceSet") 121 if err != nil { 122 return nil, 0, errors.Wrapf(err, "resp.Unmarshal") 123 } 124 totalCount, _ := resp.Float("TotalCount") 125 return nodes, int(totalCount), nil 126 }