This commit is contained in:
@@ -5,6 +5,7 @@ const (
|
|||||||
AnnotationIP = "lb.kloude.ir/ip"
|
AnnotationIP = "lb.kloude.ir/ip"
|
||||||
AnnotationVIP = "lb.kloude.ir/vip"
|
AnnotationVIP = "lb.kloude.ir/vip"
|
||||||
AnnotationLBID = "lb.kloude.ir/id"
|
AnnotationLBID = "lb.kloude.ir/id"
|
||||||
|
AnnotationNode = "lb.kloude.ir/node"
|
||||||
|
|
||||||
Namespace = "kube-system"
|
Namespace = "kube-system"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -191,6 +191,9 @@ func (c *Controller) sync(ctx context.Context, key string) error {
|
|||||||
patch.Annotations[kloudlb.AnnotationIP] = ingressIP
|
patch.Annotations[kloudlb.AnnotationIP] = ingressIP
|
||||||
patch.Annotations[kloudlb.AnnotationVIP] = vip
|
patch.Annotations[kloudlb.AnnotationVIP] = vip
|
||||||
patch.Annotations[kloudlb.AnnotationLBID] = lb.ID
|
patch.Annotations[kloudlb.AnnotationLBID] = lb.ID
|
||||||
|
if node := strings.TrimSpace(lb.Node); node != "" {
|
||||||
|
patch.Annotations[kloudlb.AnnotationNode] = node
|
||||||
|
}
|
||||||
patch.Status = corev1.ServiceStatus{
|
patch.Status = corev1.ServiceStatus{
|
||||||
LoadBalancer: corev1.LoadBalancerStatus{
|
LoadBalancer: corev1.LoadBalancerStatus{
|
||||||
Ingress: []corev1.LoadBalancerIngress{{IP: ingressIP}},
|
Ingress: []corev1.LoadBalancerIngress{{IP: ingressIP}},
|
||||||
|
|||||||
@@ -147,6 +147,10 @@ func (s *Speaker) sync(ctx context.Context, key string) error {
|
|||||||
s.stopLeading(key, vip)
|
s.stopLeading(key, vip)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if owner := serviceOwnerNode(svc); owner != "" && owner != s.nodeName {
|
||||||
|
s.stopLeading(key, vip)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
leaseName := leaseNameFor(key)
|
leaseName := leaseNameFor(key)
|
||||||
leader, err := s.acquireLease(ctx, leaseName, vip)
|
leader, err := s.acquireLease(ctx, leaseName, vip)
|
||||||
@@ -161,6 +165,13 @@ func (s *Speaker) sync(ctx context.Context, key string) error {
|
|||||||
return s.ensureVIP(vip)
|
return s.ensureVIP(vip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serviceOwnerNode(svc *corev1.Service) string {
|
||||||
|
if svc == nil || svc.Annotations == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(svc.Annotations[kloudlb.AnnotationNode])
|
||||||
|
}
|
||||||
|
|
||||||
func serviceExternalVIP(svc *corev1.Service) string {
|
func serviceExternalVIP(svc *corev1.Service) string {
|
||||||
if svc.Annotations != nil {
|
if svc.Annotations != nil {
|
||||||
if vip := strings.TrimSpace(svc.Annotations[kloudlb.AnnotationVIP]); vip != "" {
|
if vip := strings.TrimSpace(svc.Annotations[kloudlb.AnnotationVIP]); vip != "" {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ type LoadBalancer struct {
|
|||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
Namespace string `json:"namespace"`
|
Namespace string `json:"namespace"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Node string `json:"node,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AllocateRequest struct {
|
type AllocateRequest struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user