github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/cce/v3/clusters/results.go (about)

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