github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cce/v3/clusters/results.go (about)

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