Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteBackends(config *InCloud, slbid, listenerId string, backendIdList []string) error
- func DeleteLoadBalancer(config *InCloud, service *v1.Service) error
- func GetListenerPrefix(service *corev1.Service) string
- func GetNodeInstanceID(node *v1.Node) string
- func UpdateBackends(config *InCloud, listener *Listener, backends interface{}) error
- type Backend
- type BackendList
- type BackendServer
- type Config
- type CreateBackendOpts
- type CreateListenerOpts
- type CreateOptsBuilder
- type InCloud
- func (ic *InCloud) Clusters() (cloudprovider.Clusters, bool)
- func (ic *InCloud) EnsureLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error)
- func (ic *InCloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName string, service *v1.Service) error
- func (ic *InCloud) GetLoadBalancer(ctx context.Context, clusterName string, service *v1.Service) (status *v1.LoadBalancerStatus, exists bool, err error)
- func (ic *InCloud) GetLoadBalancerName(_ context.Context, clusterName string, service *v1.Service) string
- func (ic *InCloud) GetZone(ctx context.Context) (cloudprovider.Zone, error)
- func (ic *InCloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeName) (cloudprovider.Zone, error)
- func (ic *InCloud) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error)
- func (ic *InCloud) HasClusterID() bool
- func (ic *InCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{})
- func (ic *InCloud) Instances() (cloudprovider.Instances, bool)
- func (ic *InCloud) LoadBalancer() (cloudprovider.LoadBalancer, bool)
- func (ic *InCloud) ProviderName() string
- func (ic *InCloud) Routes() (cloudprovider.Routes, bool)
- func (ic *InCloud) UpdateLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) error
- func (ic *InCloud) Zones() (cloudprovider.Zones, bool)
- type Instance
- type InstanceSpec
- type Listener
- func CreateListener(config *InCloud, opts CreateListenerOpts) (*Listener, error)
- func GetListener(config *InCloud, service *corev1.Service, listenerId string) (*Listener, error)
- func GetListenerForPort(existingListeners []Listener, port corev1.ServicePort) *Listener
- func GetListeners(config *InCloud, service *corev1.Service) ([]Listener, error)
- func UpdateListener(config *InCloud, listenerid string, opts CreateListenerOpts) (*Listener, error)
- type LoadBalancer
- type LoadBalancerStatus
- type NewLoadBalancerOption
- type Protocol
- type SlbResponse
Constants ¶
const ( ProviderName = "incloud" DefaultCloudConfigPath = "/etc/kubernetes/cloud-config" )
Variables ¶
var ( ErrorNotFoundInCloud = fmt.Errorf("Cannot find lb in incloud") ErrorSlbIdNotDefined = fmt.Errorf("Could not find Service SLB Id ") )
var ErrorBackendNotFound = fmt.Errorf("Cannot find backend")
Functions ¶
func DeleteBackends ¶
func GetListenerPrefix ¶
func GetNodeInstanceID ¶
Make sure incloud instance hostname or override-hostname (if provided) is equal to InstanceId Recommended to use override-hostname
func UpdateBackends ¶
Types ¶
type Backend ¶
type BackendList ¶
type BackendList struct { Message string `json:"message"` Data []*BackendServer `json:"data"` // contains filtered or unexported fields }
func CreateBackends ¶
func CreateBackends(config *InCloud, opts CreateBackendOpts) (*BackendList, error)
type BackendServer ¶
type Config ¶
type Config struct { KeycloakUrl string `gcfg:"keycloakUrl"` ClientSecret string `gcfg:"client-secret"` RequestedSubject string `gcfg:"requested-subject"` TokenClientID string `gcfg:"token-client-id"` SubnetID string `gcfg:"subnet-id"` //由于loadbalancer本身不在cloud controller manager创建,不需要 SlbUrlPre string `gcfg:"slbUrl-pre"` //cloud-config中配置slb url前缀; KeycloakToken string `gcfg:"kktoken"` }
func LoadCloudCfg ¶
type CreateBackendOpts ¶
type CreateBackendOpts struct { SLBId string `json:"slbId"` ListenerId string `json:"listenerId"` Servers []*BackendServer `json:"servers"` }
type CreateListenerOpts ¶
type CreateListenerOpts struct { SLBId string `json:"slbId"` ListenerName string `json:"listenerName"` Protocol Protocol `json:"protocol"` Port int32 `json:"port"` ForwardRule string `json:"forwardRule"` IsHealthCheck string `json:"isHealthCheck"` TypeHealthCheck string `json:"typeHealthCheck"` PortHealthCheck int `json:"portHealthCheck""` PeriodHealthCheck int `json:"periodHealthCheck"` TimeoutHealthCheck int `json:"timeoutHealthCheck"` MaxHealthCheck int `json:"maxHealthCheck"` DomainHealthCheck string `json:"domainHealthCheck"` PathHealthCheck string `json:"pathHealthCheck"` }
创建结构体,和Listener不一样
type CreateOptsBuilder ¶
type InCloud ¶
type InCloud struct { LbUrlPre string KeycloakToken string RequestedSubject string TokenClientID string ClientSecret string KeycloakUrl string // contains filtered or unexported fields }
A single Kubernetes cluster can run in multiple zones, but only within the same region (and cloud provider).
func (*InCloud) EnsureLoadBalancer ¶
func (ic *InCloud) EnsureLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error)
EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer Implementations must treat the *v1.Service and *v1.Node parameters as read-only and not modify them. Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager by inspur 这里不创建LoadBalancer,查询LoadBalancer,有则创建Listener以及backend,无则报错 改进点:根据service查询后端pod所在节点,只注册pod所在节点到loadbalancer上,当pod漂移时,需要刷新loadbalancer的member;当pod个数变更时,需要刷新loadbalancer的member
func (*InCloud) EnsureLoadBalancerDeleted ¶
func (ic *InCloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName string, service *v1.Service) error
EnsureLoadBalancerDeleted deletes the specified load balancer if it exists, returning nil if the load balancer specified either didn't exist or was successfully deleted. This construction is useful because many cloud providers' load balancers have multiple underlying components, meaning a Get could say that the LB doesn't exist even if some part of it is still laying around. Implementations must treat the *v1.Service parameter as read-only and not modify it. Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager
func (*InCloud) GetLoadBalancer ¶
func (ic *InCloud) GetLoadBalancer(ctx context.Context, clusterName string, service *v1.Service) (status *v1.LoadBalancerStatus, exists bool, err error)
GetLoadBalancer returns whether the specified load balancer exists, and if so, what its status is.
func (*InCloud) GetLoadBalancerName ¶
func (ic *InCloud) GetLoadBalancerName(_ context.Context, clusterName string, service *v1.Service) string
GetLoadBalancerName returns the name of the load balancer. Implementations must treat the *v1.Service parameter as read-only and not modify it.
func (*InCloud) GetZoneByNodeName ¶
func (ic *InCloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeName) (cloudprovider.Zone, error)
GetZoneByNodeName implements Zones.GetZoneByNodeName This is particularly useful in external cloud providers where the kubelet does not initialize node data.
func (*InCloud) GetZoneByProviderID ¶
func (ic *InCloud) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error)
GetZoneByProviderID implements Zones.GetZoneByProviderID This is particularly useful in external cloud providers where the kubelet does not initialize node data.
func (*InCloud) HasClusterID ¶
HasClusterID returns true if the cluster has a clusterID
func (*InCloud) Initialize ¶
func (ic *InCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{})
func (*InCloud) LoadBalancer ¶
LoadBalancer returns an implementation of LoadBalancer for InCloud.
func (*InCloud) ProviderName ¶
func (*InCloud) UpdateLoadBalancer ¶
func (ic *InCloud) UpdateLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) error
UpdateLoadBalancer updates hosts under the specified load balancer. Implementations must treat the *v1.Service and *v1.Node parameters as read-only and not modify them. Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager
type Instance ¶
type Instance struct { Name string // contains filtered or unexported fields }
func (*Instance) GetInstanceID ¶
func (*Instance) GetK8sAddress ¶
func (i *Instance) GetK8sAddress() ([]v1.NodeAddress, error)
func (i *Instance) LoadQcInstanceByID(id string) error { status := []*string{qcservice.String("pending"), qcservice.String("running"), qcservice.String("stopped")} input := &qcservice.DescribeInstancesInput{ Instances: []*string{&id}, Status: status, Verbose: qcservice.Int(1), } if i.isApp { input.IsClusterNode = qcservice.Int(1) } output, err := i.instanceApi.DescribeInstances(input) if err != nil { return err } if len(output.InstanceSet) == 0 { return cloudprovider.InstanceNotFound } i.Status = output.InstanceSet[0] return nil }
type InstanceSpec ¶
type InstanceSpec struct { }
type Listener ¶
type Listener struct { SLBId string `json:"slbId"` ListenerId string `json:"listenerId"` ListenerName string `json:"listenerName"` Protocol string `json:"protocol"` Port int `json:"port"` ForwardRule string `json:"forwardRule"` IsHealthCheck string `json:"isHealthCheck"` BackendServer []*BackendServer }
返回结构体
func CreateListener ¶
func CreateListener(config *InCloud, opts CreateListenerOpts) (*Listener, error)
func GetListener ¶
GetListener get listener by listenerid
func GetListenerForPort ¶
func GetListenerForPort(existingListeners []Listener, port corev1.ServicePort) *Listener
get listener for a port or nil if does not exist
func GetListeners ¶
GetListeners use should mannually load listener because sometimes we do not need load entire topology. For example, deletion GetListeners get listeners by slbid
func UpdateListener ¶
func UpdateListener(config *InCloud, listenerid string, opts CreateListenerOpts) (*Listener, error)
type LoadBalancer ¶
type LoadBalancer struct { //service *corev1.Service //Type int //TCPPorts []int //NodePorts []int //Nodes []*corev1.Node //Name string //clusterName string RegionId string `json:"regionId"` CreatedTime string `json:"createdTime"` ExpiredTime string `json:"expiredTime"` SpecificationId string `json:"specificationId"` SpecificationName string `json:"specificationName"` SlbId string `json:"slbId"` SlbName string `json:"slbName"` Scheme string `json:"scheme"` BusinessIp string `json:"businessIp"` VpcId string `json:"vpcId"` VpcName string `json:"vpcName"` SubnetId string `json:"subnetId"` EipId string `json:"eipId"` EipAddress string `json:"eipAddress"` ListenerCount int `json:"listenerCount"` SlbType string `json:"slbType"` State string `json:"state"` UserId string `json:"userId"` }
func GetLoadBalancer ¶
func GetLoadBalancer(config *InCloud, service *v1.Service) (*LoadBalancer, error)
GetLoadBalancer by slbid,use incloud api to get lb in cloud, return err if not found
func (*LoadBalancer) GetNodesInstanceIDs ¶
func (lb *LoadBalancer) GetNodesInstanceIDs() []string
GetNodesInstanceIDs return resource ids for listener to create backends
type LoadBalancerStatus ¶
type LoadBalancerStatus struct {
K8sLoadBalancerStatus *v1.LoadBalancerStatus
}
type NewLoadBalancerOption ¶
type NewLoadBalancerOption struct { NodeLister corev1lister.NodeLister K8sNodes []*v1.Node K8sService *v1.Service Context context.Context ClusterName string }
type SlbResponse ¶
type SlbResponse struct { RegionId string `json:"regionId"` CreatedTime time.Time `json:"createdTime"` ExpiredTime time.Time `json:"expiredTime"` SpecificationId string `json:"specificationId"` SpecificationName string `json:"specificationName"` SlbId string `json:"slbId"` SlbName string `json:"slbName"` Scheme string `json:"scheme"` BusinessIp string `json:"businessIp"` VpcId string `json:"vpcId"` SubnetId string `json:"subnetId"` EipId string `json:"eipId"` EipAddress string `json:"eipAddress"` ListenerCount int `json:"listenerCount"` ChargeType string `json:"chargeType"` PurchaseTime string `json:"purchaseTime"` Type string `json:"type"` State string `json:"state"` }