kubernetes platform后端开发-loadbalance相关组件

一、接口定义

1、Ingress
type IngressService interface {
    GetIngressList(ctx context.Context, request *structs.GetIngressListRequest) (*structs.GetIngressListResp, error)
    DescribeIngress(ctx context.Context, request *structs.DescribeIngressRequest) (*v1.Ingress, error)
    CreateIngress(ctx context.Context, request *structs.CreateIngressRequest) (*v1.Ingress, error)
    DeleteIngress(ctx context.Context, request *structs.DeleteIngressRequest) error
    UpdateIngress(ctx context.Context, request *structs.UpdateIngressRequest) (*v1.Ingress, error)
}
2、Service
type SVCService interface {
    GetSVCList(ctx context.Context, request *structs.GetSVCListRequest) (*structs.SVCListResp, error)
    DescribeSVCList(ctx context.Context, request *structs.DescribeSVCRequest) (*corev1.Service, error)
    CreateSVC(ctx context.Context, request *structs.CreateSVCRequest) (*corev1.Service, error)
    DeleteSVC(ctx context.Context, request *structs.DeleteSVCRequest) error
    UpdateSVC(ctx context.Context, request *structs.UpdateSVCRequest) (*corev1.Service, error)
}

二、结构体定义

1、Ingress
package structs

import (
    v1 "k8s.io/api/networking/v1"
)

type IngressTemplate struct {
    Name      string `json:"name"`
    Namespace string `json:"namespace"`
}
type GetIngressListRequest struct {
    *IngressTemplate
    FilterName string `json:"filterName"`
    *DataPagination
}
type DescribeIngressRequest struct {
    *IngressTemplate
}

type DeleteIngressRequest struct {
    *IngressTemplate
}
type UpdateIngressRequest struct {
    *IngressTemplate
    Content string `json:"content"`
}
type GetIngressListResp struct {
    Items []v1.Ingress `json:"items"`
    Count int          `json:"count"`
}

// 创建ingress相关
type CreateIngressRequest struct {
    *IngressTemplate
    Labels           map[string]string  `json:"labels"`
    Annotations      map[string]string  `json:"annotations"`
    IngressClassName *string            `json:"ingressClassName"`
    DefaultBackend   *v1.IngressBackend `json:"defaultBackend"`
    IngressInfo      []IngressPath      `json:"ingressInfo"`
    TLS              []IngressTLS       `json:"tls"`
    Rules            []IngressRule      `json:"rules"`
}

// 定义Ingress的http路径相关信息
type IngressPath struct {
    Path        string      `json:"path"`
    PathType    v1.PathType `json:"pathType"`
    ServiceName string      `json:"serviceName"`
    ServicePort int32       `json:"servicePort"`
}
type IngressRule struct {
    Host  string        `json:"host"`
    Paths []IngressPath `json:"paths"`
}

type IngressTLS struct {
    Hosts      []string `json:"hosts"`
    SecretName string   `json:"secretName"`
}
2、Service
package structs

import (
    corev1 "k8s.io/api/core/v1"
)

type ServiceTemplate struct {
    Name      string `json:"name"`
    Namespace string `json:"namespace"`
}
type GetSVCListRequest struct {
    *ServiceTemplate
    FilterName string `json:"filterName"`
    *DataPagination
}
type DescribeSVCRequest struct {
    *ServiceTemplate
}
type CreateSVCRequest struct {
    Labels     map[string]string `json:"labels"`
    Port       int32             `json:"port"`
    TargetPort int32             `json:"targetPort"`
    NodePort   int32             `json:"nodePort"`
    Type       ServiceType       `json:"type"`
    *ServiceTemplate
}
type DeleteSVCRequest struct {
    *ServiceTemplate
}
type UpdateSVCRequest struct {
    *ServiceTemplate
    Content string `json:"content"`
}
type SVCListResp struct {
    Items []corev1.Service `json:"items"`
    Count int              `json:"count"`
}