pkg

package
v0.0.0-...-cdf8e41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderName           = "incloud"
	DefaultCloudConfigPath = "/etc/kubernetes/cloud-config"
)

Variables

View Source
var (
	ErrorNotFoundInCloud = fmt.Errorf("Cannot find lb in incloud")
	ErrorSlbIdNotDefined = fmt.Errorf("Could not find Service SLB Id ")
)
View Source
var ErrorBackendNotFound = fmt.Errorf("Cannot find backend")

Functions

func DeleteBackends

func DeleteBackends(config *InCloud, slbid, listenerId string, backendIdList []string) error

func DeleteLoadBalancer

func DeleteLoadBalancer(config *InCloud, service *v1.Service) error

func GetListenerPrefix

func GetListenerPrefix(service *corev1.Service) string

func GetNodeInstanceID

func GetNodeInstanceID(node *v1.Node) string

Make sure incloud instance hostname or override-hostname (if provided) is equal to InstanceId Recommended to use override-hostname

func UpdateBackends

func UpdateBackends(config *InCloud, listener *Listener, backends interface{}) error

Types

type Backend

type Backend struct {
	BackendId   string `json:"backendId"`
	ListenerId  string `json:"listenerId"`
	ServerId    string `json:"serverId"`
	Port        int    `json:"port"`
	ServerName  string `json:"serverName"`
	ServerIp    string `json:"serverIp"`
	ServierType string `json:"type"`
	Weight      int    `json:"weight"`
}

func GetBackends

func GetBackends(config *InCloud, slbid, listenerId string) ([]Backend, error)

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 BackendServer struct {
	ServerId    string `json:"serverId"`
	Port        int    `json:"port"`
	ServerName  string `json:"serverName"`
	ServerIp    string `json:"serverIp"`
	ServierType string `json:"type"`
	Weight      int    `json:"weight"`
}

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

func LoadCloudCfg() (Config, error)

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 CreateOptsBuilder interface {
	ToListenerCreateMap() (map[string]interface{}, error)
}

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) Clusters

func (ic *InCloud) Clusters() (cloudprovider.Clusters, bool)

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) GetZone

func (ic *InCloud) GetZone(ctx context.Context) (cloudprovider.Zone, error)

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

func (ic *InCloud) HasClusterID() bool

HasClusterID returns true if the cluster has a clusterID

func (*InCloud) Initialize

func (ic *InCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{})

func (*InCloud) Instances

func (ic *InCloud) Instances() (cloudprovider.Instances, bool)

Instances returns an implementation of Instances for InCloud.

func (*InCloud) LoadBalancer

func (ic *InCloud) LoadBalancer() (cloudprovider.LoadBalancer, bool)

LoadBalancer returns an implementation of LoadBalancer for InCloud.

func (*InCloud) ProviderName

func (ic *InCloud) ProviderName() string

func (*InCloud) Routes

func (ic *InCloud) Routes() (cloudprovider.Routes, bool)

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

func (*InCloud) Zones

func (ic *InCloud) Zones() (cloudprovider.Zones, bool)

type Instance

type Instance struct {
	Name string
	// contains filtered or unexported fields
}

func (*Instance) GetInstanceID

func (i *Instance) GetInstanceID() string

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

func GetListener(config *InCloud, service *corev1.Service, listenerId string) (*Listener, error)

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

func GetListeners(config *InCloud, service *corev1.Service) ([]Listener, error)

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)

func (*Listener) DeleteListener

func (l *Listener) DeleteListener(config *InCloud, service *corev1.Service) 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 Protocol

type Protocol string
const (
	ProtocolTCP   Protocol = "TCP"
	ProtocolHTTP  Protocol = "HTTP"
	ProtocolHTTPS Protocol = "HTTPS"
)

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"`
}

func ModifyLoadBalancer

func ModifyLoadBalancer(config *InCloud, service *v1.Service, slbName string) (*SlbResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL