yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/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 aliyun
    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 SKubeNodePool struct {
    27  	multicloud.SResourceBase
    28  	AliyunTags
    29  
    30  	cluster *SKubeCluster
    31  
    32  	AutoScaling struct {
    33  		EipBandwidth int    `json:"eip_bandwidth"`
    34  		IsBondEip    bool   `json:"is_bond_eip"`
    35  		Enable       bool   `json:"enable"`
    36  		MaxInstances int    `json:"max_instances"`
    37  		MinInstances int    `json:"min_instances"`
    38  		Type         string `json:"type"`
    39  	} `json:"auto_scaling"`
    40  	KubernetesConfig struct {
    41  		CmsEnabled     bool   `json:"cms_enabled"`
    42  		CpuPolicy      string `json:"cpu_policy"`
    43  		Runtime        string `json:"runtime"`
    44  		RuntimeVersion string `json:"runtime_version"`
    45  		UserData       string `json:"user_data"`
    46  	} `json:"kubernetes_config"`
    47  	NodepoolInfo struct {
    48  		Created         string `json:"created"`
    49  		IsDefault       bool   `json:"is_default"`
    50  		Name            string `json:"name"`
    51  		NodepoolId      string `json:"nodepool_id"`
    52  		RegionId        string `json:"region_id"`
    53  		ResourceGroupId string `json:"resource_group_id"`
    54  		Type            string `json:"type"`
    55  		Updated         string `json:"updated"`
    56  	} `json:"nodepool_info"`
    57  	ScalingGroup struct {
    58  		AutoRenew                           bool     `json:"auto_renew"`
    59  		AutoRenewPeriod                     int      `json:"auto_renew_period"`
    60  		ImageId                             string   `json:"image_id"`
    61  		InstanceChargeType                  string   `json:"instance_charge_type"`
    62  		Instance_types                      []string `json:"instance_types"`
    63  		MultiAzPolicy                       string   `json:"multi_az_policy"`
    64  		OnDemandBaseCapacity                int      `json:"on_demand_base_capacity"`
    65  		OnDemandPercentageAboveBaseCapacity int      `json:"on_demand_percentage_above_base_capacity"`
    66  		SpotInstancePools                   int      `json:"spot_instance_pools"`
    67  		SpotInstanceRemedy                  bool     `json:"spot_instance_remedy"`
    68  		CompensateWithOnDemand              bool     `json:"compensate_with_on_demand"`
    69  		Period                              int      `json:"period"`
    70  		PeriodUnit                          string   `json:"period_unit"`
    71  		Platform                            string   `json:"platform"`
    72  		RamPolicy                           string   `json:"ram_policy"`
    73  		SpotStrategy                        string   `json:"spot_strategy"`
    74  		SpotPriceLimit                      []struct {
    75  			InstanceType string `json:"instance_type"`
    76  			PriceLimit   string `json:"price_limit"`
    77  		} `json:"spot_price_limit"`
    78  		RdsInstances       []string `json:"rds_instances"`
    79  		ScalingGroupId     string   `json:"scaling_group_id"`
    80  		ScalingPolicy      string   `json:"scaling_policy"`
    81  		SecurityGroupId    string   `json:"security_group_id"`
    82  		SystemDiskCategory string   `json:"system_disk_category"`
    83  		SystemDiskSize     int      `json:"system_disk_size"`
    84  		VswitchIds         []string `json:"vswitch_ids"`
    85  		LoginPassword      string   `json:"login_password"`
    86  		KeyPair            string   `json:"key_pair"`
    87  	} `json:"scaling_group"`
    88  	Status struct {
    89  		FailedNodes   string `json:"failed_nodes"`
    90  		HealthyNodes  string `json:"healthy_nodes"`
    91  		InitialNodes  string `json:"initial_nodes"`
    92  		OfflineNodes  string `json:"offline_nodes"`
    93  		RemovingNodes string `json:"removing_nodes"`
    94  		ServingNodes  string `json:"serving_nodes"`
    95  		State         string `json:"state"`
    96  		TotalNodes    int    `json:"total_nodes"`
    97  	} `json:"status"`
    98  	TeeConfig struct {
    99  		TeeEnable bool `json:"tee_enable"`
   100  	} `json:"tee_config"`
   101  	Management struct {
   102  		Enable        bool `json:"enable"`
   103  		AutoRepair    bool `json:"auto_repair"`
   104  		UpgradeConfig struct {
   105  			AutoUpgrade     bool `json:"auto_upgrade"`
   106  			Surge           int  `json:"surge"`
   107  			SurgePercentage int  `json:"surge_percentage"`
   108  			MaxUnavailable  int  `json:"max_unavailable"`
   109  		} `json:"upgrade_config"`
   110  	} `json:"management"`
   111  }
   112  
   113  func (self *SKubeNodePool) GetName() string {
   114  	return self.NodepoolInfo.Name
   115  }
   116  
   117  func (self *SKubeNodePool) GetId() string {
   118  	return self.NodepoolInfo.NodepoolId
   119  }
   120  
   121  func (self *SKubeNodePool) GetGlobalId() string {
   122  	return self.NodepoolInfo.NodepoolId
   123  }
   124  
   125  func (self *SKubeNodePool) GetStatus() string {
   126  	return self.Status.State
   127  }
   128  
   129  func (self *SKubeCluster) GetIKubeNodePools() ([]cloudprovider.ICloudKubeNodePool, error) {
   130  	pools, err := self.region.GetKubeNodePools(self.ClusterId)
   131  	if err != nil {
   132  		return nil, errors.Wrapf(err, "GetKubeNodePools")
   133  	}
   134  	ret := []cloudprovider.ICloudKubeNodePool{}
   135  	for i := range pools {
   136  		pools[i].cluster = self
   137  		ret = append(ret, &pools[i])
   138  	}
   139  	return ret, nil
   140  }
   141  
   142  func (self *SRegion) GetKubeNodePools(clusterId string) ([]SKubeNodePool, error) {
   143  	params := map[string]string{
   144  		"PathPattern": fmt.Sprintf("/clusters/%s/nodepools", clusterId),
   145  	}
   146  	resp, err := self.k8sRequest("DescribeClusterNodePools", params)
   147  	if err != nil {
   148  		return nil, errors.Wrapf(err, "DescribeClusterNodePools")
   149  	}
   150  	pools := []SKubeNodePool{}
   151  	err = resp.Unmarshal(&pools, "nodepools")
   152  	if err != nil {
   153  		return nil, errors.Wrapf(err, "resp.Unmarshal")
   154  	}
   155  	return pools, nil
   156  }