yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/kube_node_pools.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  	"yunion.io/x/pkg/errors"
    19  
    20  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    21  	"yunion.io/x/cloudmux/pkg/multicloud"
    22  )
    23  
    24  type SKubeNodePool struct {
    25  	multicloud.SResourceBase
    26  	QcloudTags
    27  
    28  	cluster *SKubeCluster
    29  
    30  	NodePoolId            string
    31  	Name                  string
    32  	ClusterInstanceId     string
    33  	LifeState             string
    34  	LaunchConfigurationId string
    35  	AutoscalingGroupId    string
    36  	Labels                []struct {
    37  		Name  string
    38  		Value string
    39  	}
    40  	Taints []struct {
    41  		Kye    string
    42  		Value  string
    43  		Effect string
    44  	}
    45  	NodeCountSummary struct {
    46  		ManuallyAdded struct {
    47  			Joining      int
    48  			Initializing int
    49  			Normal       int
    50  			Total        int
    51  		}
    52  		AutoscalingAdded struct {
    53  			Joining      int
    54  			Initializing int
    55  			Normal       int
    56  			Total        int
    57  		}
    58  	}
    59  	AutoscalingGroupStatus string
    60  	MaxNodesNum            int
    61  	MinNodesNum            int
    62  	DesiredNodesNum        int
    63  	NodePoolOs             string
    64  	OsCustomizeType        string
    65  	ImageId                string
    66  	DesiredPodNum          int
    67  	UserScript             string
    68  }
    69  
    70  func (self *SKubeNodePool) GetId() string {
    71  	return self.NodePoolId
    72  }
    73  
    74  func (self *SKubeNodePool) GetGlobalId() string {
    75  	return self.NodePoolId
    76  }
    77  
    78  func (self *SKubeNodePool) GetName() string {
    79  	return self.Name
    80  }
    81  
    82  func (self *SKubeNodePool) GetStatus() string {
    83  	return self.LifeState
    84  }
    85  
    86  func (self *SKubeCluster) GetIKubeNodePools() ([]cloudprovider.ICloudKubeNodePool, error) {
    87  	pools, err := self.region.GetKubeNodePools(self.ClusterId)
    88  	if err != nil {
    89  		return nil, errors.Wrapf(err, "GetKubeNodePools")
    90  	}
    91  	ret := []cloudprovider.ICloudKubeNodePool{}
    92  	for i := range pools {
    93  		pools[i].cluster = self
    94  		ret = append(ret, &pools[i])
    95  	}
    96  	return ret, nil
    97  }
    98  
    99  func (self *SRegion) GetKubeNodePools(clusterId string) ([]SKubeNodePool, error) {
   100  	params := map[string]string{
   101  		"ClusterId": clusterId,
   102  	}
   103  	resp, err := self.tkeRequest("DescribeClusterNodePools", params)
   104  	if err != nil {
   105  		return nil, errors.Wrapf(err, "DescribeClusterNodePools")
   106  	}
   107  	pools := []SKubeNodePool{}
   108  	err = resp.Unmarshal(&pools, "NodePoolSet")
   109  	if err != nil {
   110  		return nil, errors.Wrapf(err, "NodePoolSet")
   111  	}
   112  	return pools, nil
   113  }