kube_cluster.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. package compute
  15. import (
  16. "reflect"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/gotypes"
  19. "yunion.io/x/onecloud/pkg/apis"
  20. )
  21. const (
  22. KUBE_CLUSTER_STATUS_RUNNING = "running"
  23. KUBE_CLUSTER_STATUS_CREATING = "creating"
  24. KUBE_CLUSTER_STATUS_ABNORMAL = "abnormal"
  25. // 升级中
  26. KUBE_CLUSTER_STATUS_UPDATING = "updating"
  27. // 升级失败
  28. KUBE_CLUSTER_STATUS_UPDATING_FAILED = "updating_failed"
  29. // 伸缩中
  30. KUBE_CLUSTER_STATUS_SCALING = "scaling"
  31. // 停止
  32. KUBE_CLUSTER_STATUS_STOPPED = "stopped"
  33. )
  34. type KubeClusterListInput struct {
  35. apis.EnabledStatusInfrasResourceBaseListInput
  36. apis.ExternalizedResourceBaseListInput
  37. RegionalFilterListInput
  38. ManagedResourceListInput
  39. VpcFilterListInput
  40. }
  41. type KubeClusterCreateInput struct {
  42. apis.EnabledStatusInfrasResourceBaseCreateInput
  43. Version string `json:"version"`
  44. // required: true
  45. NetworkIds SKubeNetworkIds `json:"network_ids"`
  46. // swagger:ignore
  47. ManagerId string `json:"manager_id"`
  48. // swagger:ignore
  49. CloudregionId string `json:"cloudregion_id"`
  50. // required: true
  51. VpcResourceInput
  52. PrivateAccess bool `json:"private_access"`
  53. PublicAccess bool `json:"public_access"`
  54. RoleName string `json:"role_name"`
  55. }
  56. type KubeClusterDetails struct {
  57. apis.EnabledStatusInfrasResourceBaseDetails
  58. SKubeCluster
  59. VpcResourceInfo
  60. }
  61. func (self KubeClusterDetails) GetMetricTags() map[string]string {
  62. ret := map[string]string{
  63. "id": self.ExternalClusterId,
  64. "res_type": "kube_cluster",
  65. "cluster_id": self.ExternalClusterId,
  66. "cluster_name": self.Name,
  67. "status": self.Status,
  68. "cloudregion": self.Cloudregion,
  69. "cloudregion_id": self.CloudregionId,
  70. "region_ext_id": self.RegionExtId,
  71. "domain_id": self.DomainId,
  72. "project_domain": self.ProjectDomain,
  73. "account": self.Account,
  74. "account_id": self.AccountId,
  75. "external_id": self.ExternalId,
  76. }
  77. return AppendMetricTags(ret, self.MetadataResourceInfo)
  78. }
  79. func (self KubeClusterDetails) GetMetricPairs() map[string]string {
  80. ret := map[string]string{}
  81. return ret
  82. }
  83. type KubeClusterUpdateInput struct {
  84. apis.EnabledStatusInfrasResourceBaseUpdateInput
  85. }
  86. type GetKubeConfigInput struct {
  87. // 是否获取内网kubeconfig, 默认false即获取外网kubeconfig
  88. Private bool `json:"private"`
  89. // kubeconfig 到期时间
  90. // 阿里云: 15(15分钟)~4320(3天)
  91. // 腾讯云不传此参数默认时效是20年
  92. ExpireMinutes int `json:"expire_minutes"`
  93. }
  94. type KubeClusterDeleteInput struct {
  95. // 是否保留集群关联的实例及slb
  96. // default: false
  97. Retain bool `json:"retain"`
  98. }
  99. type SInstanceTypes []string
  100. func (kn SInstanceTypes) String() string {
  101. return jsonutils.Marshal(kn).String()
  102. }
  103. func (kn SInstanceTypes) IsZero() bool {
  104. return len(kn) == 0
  105. }
  106. type SKubeNetworkIds []string
  107. func (kn SKubeNetworkIds) String() string {
  108. return jsonutils.Marshal(kn).String()
  109. }
  110. func (kn SKubeNetworkIds) IsZero() bool {
  111. return len(kn) == 0
  112. }
  113. func init() {
  114. gotypes.RegisterSerializable(reflect.TypeOf(&SKubeNetworkIds{}), func() gotypes.ISerializable {
  115. return &SKubeNetworkIds{}
  116. })
  117. gotypes.RegisterSerializable(reflect.TypeOf(&SInstanceTypes{}), func() gotypes.ISerializable {
  118. return &SInstanceTypes{}
  119. })
  120. }