github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cce/v3/clusters/results.go (about) 1 package clusters 2 3 import ( 4 "encoding/json" 5 6 "github.com/chnsz/golangsdk" 7 "github.com/chnsz/golangsdk/openstack/common/tags" 8 ) 9 10 type ListCluster struct { 11 // API type, fixed value Cluster 12 Kind string `json:"kind"` 13 //API version, fixed value v3 14 ApiVersion string `json:"apiVersion"` 15 //all Clusters 16 Clusters []Clusters `json:"items"` 17 } 18 19 type Clusters struct { 20 // API type, fixed value Cluster 21 Kind string `json:"kind" required:"true"` 22 //API version, fixed value v3 23 ApiVersion string `json:"apiversion" required:"true"` 24 //Metadata of a Cluster 25 Metadata MetaData `json:"metadata" required:"true"` 26 //specifications of a Cluster 27 Spec Spec `json:"spec" required:"true"` 28 //status of a Cluster 29 Status Status `json:"status"` 30 } 31 32 // Metadata required to create a cluster 33 type MetaData struct { 34 //Cluster unique name 35 Name string `json:"name"` 36 //Cluster unique Id 37 Id string `json:"uid"` 38 // Cluster tag, key/value pair format 39 Labels map[string]string `json:"labels,omitempty"` 40 //Cluster annotation, key/value pair format 41 Annotations map[string]string `json:"annotations,omitempty"` 42 // Cluster alias 43 Alias string `json:"alias"` 44 } 45 46 // Specifications to create a cluster 47 type Spec struct { 48 //Cluster Type: VirtualMachine, BareMetal, or Windows 49 Type string `json:"type" required:"true"` 50 // Cluster specifications 51 Flavor string `json:"flavor" required:"true"` 52 // For the cluster version, please fill in v1.7.3-r10 or v1.9.2-r1. Currently only Kubernetes 1.7 and 1.9 clusters are supported. 53 Version string `json:"version,omitempty"` 54 //Cluster description 55 Description string `json:"description,omitempty"` 56 //Public IP ID 57 PublicIP string `json:"publicip_id,omitempty"` 58 // Node network parameters 59 HostNetwork HostNetworkSpec `json:"hostNetwork" required:"true"` 60 //Container network parameters 61 ContainerNetwork ContainerNetworkSpec `json:"containerNetwork" required:"true"` 62 //ENI network parameters 63 EniNetwork *EniNetworkSpec `json:"eniNetwork,omitempty"` 64 // Enable Distributed Cluster Management 65 EnableDistMgt bool `json:"enableDistMgt,omitempty"` 66 //Authentication parameters 67 Authentication AuthenticationSpec `json:"authentication,omitempty"` 68 // Charging mode of the cluster, which is 0 (on demand) 69 BillingMode int `json:"billingMode,omitempty"` 70 //Extended parameter for a cluster 71 ExtendParam map[string]interface{} `json:"extendParam,omitempty"` 72 //Advanced configuration of master node 73 Masters []MasterSpec `json:"masters,omitempty"` 74 //Range of kubernetes clusterIp 75 KubernetesSvcIPRange string `json:"kubernetesSvcIpRange,omitempty"` 76 //Custom san list for certificates 77 CustomSan []string `json:"customSan,omitempty"` 78 // Tags of cluster, key value pair format 79 ClusterTags []tags.ResourceTag `json:"clusterTags,omitempty"` 80 // configurationsOverride 81 ConfigurationsOverride []PackageConfiguration `json:"configurationsOverride,omitempty"` 82 // Whether to enable IPv6 83 IPv6Enable bool `json:"ipv6enable,omitempty"` 84 // K8s proxy mode 85 KubeProxyMode string `json:"kubeProxyMode,omitempty"` 86 // Whether to enable Istio 87 SupportIstio bool `json:"supportIstio,omitempty"` 88 // The category, the value can be CCE and CCE 89 Category string `json:"category,omitempty"` 90 } 91 92 type PackageConfiguration struct { 93 Name string `json:"name,omitempty"` 94 Configurations []interface{} `json:"configurations,omitempty"` 95 } 96 97 // Node network parameters 98 type HostNetworkSpec struct { 99 //The ID of the VPC used to create the node 100 VpcId string `json:"vpc" required:"true"` 101 //The ID of the subnet used to create the node 102 SubnetId string `json:"subnet" required:"true"` 103 // The ID of the high speed network used to create bare metal nodes. 104 // This parameter is required when creating a bare metal cluster. 105 HighwaySubnet string `json:"highwaySubnet,omitempty"` 106 //The ID of the Security Group used to create the node 107 SecurityGroup string `json:"SecurityGroup,omitempty"` 108 } 109 110 // Container network parameters 111 type ContainerNetworkSpec struct { 112 //Container network type: overlay_l2 , underlay_ipvlan or vpc-router 113 Mode string `json:"mode" required:"true"` 114 //Container network segment: 172.16.0.0/16 ~ 172.31.0.0/16. If there is a network segment conflict, it will be automatically reselected. 115 Cidr string `json:"cidr,omitempty"` 116 // List of container CIDR blocks. In clusters of v1.21 and later, the cidrs field is used. 117 // When the cluster network type is vpc-router, you can add multiple container CIDR blocks. 118 // In versions earlier than v1.21, if the cidrs field is used, the first CIDR element in the array is used as the container CIDR block. 119 Cidrs []CidrSpec `json:"cidrs,omitempty"` 120 } 121 122 type CidrSpec struct { 123 // Container network segment. Recommended: 10.0.0.0/12-19, 172.16.0.0/16-19, and 192.168.0.0/16-19 124 Cidr string `json:"cidr" required:"true"` 125 } 126 127 type EniNetworkSpec struct { 128 //Eni network subnet id, will be deprecated in the future 129 SubnetId string `json:"eniSubnetId,omitempty"` 130 //Eni network cidr, will be deprecated in the future 131 Cidr string `json:"eniSubnetCIDR,omitempty"` 132 // Eni network subnet IDs 133 Subnets []EniSubnetSpec `json:"subnets" required:"true"` 134 } 135 136 type EniSubnetSpec struct { 137 SubnetID string `json:"subnetID" required:"true"` 138 } 139 140 // Authentication parameters 141 type AuthenticationSpec struct { 142 //Authentication mode: rbac , x509 or authenticating_proxy 143 Mode string `json:"mode" required:"true"` 144 AuthenticatingProxy map[string]string `json:"authenticatingProxy" required:"true"` 145 } 146 147 type MasterSpec struct { 148 // AZ of master node 149 MasterAZ string `json:"availabilityZone,omitempty"` 150 } 151 152 type Status struct { 153 //The state of the cluster 154 Phase string `json:"phase"` 155 //The ID of the Job that is operating asynchronously in the cluster 156 JobID string `json:"jobID"` 157 //Reasons for the cluster to become current 158 Reason string `json:"reason"` 159 //The status of each component in the cluster 160 Conditions Conditions `json:"conditions"` 161 //Kube-apiserver access address in the cluster 162 Endpoints []Endpoints `json:"-"` 163 } 164 165 type Conditions struct { 166 //The type of component 167 Type string `json:"type"` 168 //The state of the component 169 Status string `json:"status"` 170 //The reason that the component becomes current 171 Reason string `json:"reason"` 172 } 173 174 type Endpoints struct { 175 //The address accessed within the user's subnet - Huawei 176 Url string `json:"url"` 177 //Public network access address - Huawei 178 Type string `json:"type"` 179 //Internal network address - OTC 180 Internal string `json:"internal"` 181 //External network address - OTC 182 External string `json:"external"` 183 //Endpoint of the cluster to be accessed through API Gateway - OTC 184 ExternalOTC string `json:"external_otc"` 185 } 186 187 type Certificate struct { 188 //API type, fixed value Config 189 Kind string `json:"kind"` 190 //API version, fixed value v1 191 ApiVersion string `json:"apiVersion"` 192 //Cluster list 193 Clusters []CertClusters `json:"clusters"` 194 //User list 195 Users []CertUsers `json:"users"` 196 //Context list 197 Contexts []CertContexts `json:"contexts"` 198 //The current context 199 CurrentContext string `json:"current-context"` 200 } 201 202 type CertClusters struct { 203 //Cluster name 204 Name string `json:"name"` 205 //Cluster information 206 Cluster CertCluster `json:"cluster"` 207 } 208 209 type CertCluster struct { 210 //Server IP address 211 Server string `json:"server"` 212 //Certificate data 213 CertAuthorityData string `json:"certificate-authority-data"` 214 //whether skip tls verify 215 InsecureSkipTLSVerify bool `json:"insecure-skip-tls-verify"` 216 } 217 218 type CertUsers struct { 219 //User name 220 Name string `json:"name"` 221 //Cluster information 222 User CertUser `json:"user"` 223 } 224 225 type CertUser struct { 226 //Client certificate 227 ClientCertData string `json:"client-certificate-data"` 228 //Client key data 229 ClientKeyData string `json:"client-key-data"` 230 } 231 232 type CertContexts struct { 233 //Context name 234 Name string `json:"name"` 235 //Context information 236 Context CertContext `json:"context"` 237 } 238 239 type CertContext struct { 240 //Cluster name 241 Cluster string `json:"cluster"` 242 //User name 243 User string `json:"user"` 244 } 245 246 // UnmarshalJSON helps to unmarshal Status fields into needed values. 247 // OTC and Huawei have different data types and child fields for `endpoints` field in Cluster Status. 248 // This function handles the unmarshal for both 249 func (r *Status) UnmarshalJSON(b []byte) error { 250 type tmp Status 251 var s struct { 252 tmp 253 Endpoints []Endpoints `json:"endpoints"` 254 } 255 256 err := json.Unmarshal(b, &s) 257 258 if err != nil { 259 switch err.(type) { 260 case *json.UnmarshalTypeError: //check if type error occurred (handles the different endpoint structure for huawei and otc) 261 var s struct { 262 tmp 263 Endpoints Endpoints `json:"endpoints"` 264 } 265 err := json.Unmarshal(b, &s) 266 if err != nil { 267 return err 268 } 269 *r = Status(s.tmp) 270 r.Endpoints = []Endpoints{{Internal: s.Endpoints.Internal, 271 External: s.Endpoints.External, 272 ExternalOTC: s.Endpoints.ExternalOTC}} 273 return nil 274 default: 275 return err 276 } 277 } 278 279 *r = Status(s.tmp) 280 r.Endpoints = s.Endpoints 281 282 return err 283 } 284 285 type commonResult struct { 286 golangsdk.Result 287 } 288 289 // Extract is a function that accepts a result and extracts a cluster. 290 func (r commonResult) Extract() (*Clusters, error) { 291 var s Clusters 292 err := r.ExtractInto(&s) 293 return &s, err 294 } 295 296 // ExtractCluster is a function that accepts a ListOpts struct, which allows you to filter and sort 297 // the returned collection for greater efficiency. 298 func (r commonResult) ExtractClusters() ([]Clusters, error) { 299 var s ListCluster 300 err := r.ExtractInto(&s) 301 if err != nil { 302 return nil, err 303 } 304 305 return s.Clusters, nil 306 307 } 308 309 // CreateResult represents the result of a create operation. Call its Extract 310 // method to interpret it as a Cluster. 311 type CreateResult struct { 312 commonResult 313 } 314 315 // GetResult represents the result of a get operation. Call its Extract 316 // method to interpret it as a Cluster. 317 type GetResult struct { 318 commonResult 319 } 320 321 // UpdateResult represents the result of an update operation. Call its Extract 322 // method to interpret it as a Cluster. 323 type UpdateResult struct { 324 commonResult 325 } 326 327 // DeleteResult represents the result of a delete operation. Call its ExtractErr 328 // method to determine if the request succeeded or failed. 329 type DeleteResult struct { 330 golangsdk.ErrResult 331 } 332 333 // ListResult represents the result of a list operation. Call its ExtractCluster 334 // method to interpret it as a Cluster. 335 type ListResult struct { 336 commonResult 337 } 338 339 type GetCertResult struct { 340 golangsdk.Result 341 } 342 343 // Extract is a function that accepts a result and extracts a cluster. 344 func (r GetCertResult) Extract() (*Certificate, error) { 345 var s Certificate 346 err := r.ExtractInto(&s) 347 return &s, err 348 } 349 350 // UpdateIpResult represents the result of an update operation. Call its Extract 351 // method to interpret it as a Cluster. 352 type UpdateIpResult struct { 353 golangsdk.ErrResult 354 } 355 356 type OperationResult struct { 357 golangsdk.ErrResult 358 }