Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix: generate same key for create, update and delete LB (#302)
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <reaver@flomesh.io>
  • Loading branch information
reaver-flomesh authored Aug 8, 2023
1 parent 43845f6 commit 22684e6
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions controllers/flb/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ import (
"time"
)

// FLB API paths
const (
flbAuthApiPath = "/api/auth/local"
flbUpdateServiceApiPath = "/api/l-4-lbs/updateservice"
flbDeleteServiceApiPath = "/api/l-4-lbs/updateservice/delete"
)

// FLB annotations
const (
finalizerName = "servicelb.flomesh.io/flb"
flbDefaultSettingKey = "flb.flomesh.io/default-setting"
)

// FLB request HTTP headers
const (
finalizerName = "servicelb.flomesh.io/flb"
flbAuthApiPath = "/api/auth/local"
flbUpdateServiceApiPath = "/api/l-4-lbs/updateservice"
flbDeleteServiceApiPath = "/api/l-4-lbs/updateservice/delete"
flbClusterHeaderName = "X-Flb-Cluster"
flbAddressPoolHeaderName = "X-Flb-Address-Pool"
flbDesiredIPHeaderName = "X-Flb-Desired-Ip"
Expand All @@ -87,8 +97,7 @@ const (
xyz: abc
789: 123
*/
flbTagsHeaderName = "X-Flb-Tags"
flbDefaultSettingKey = "flb.flomesh.io/default-setting"
flbTagsHeaderName = "X-Flb-Tags"
)

// ServiceReconciler reconciles a Service object
Expand Down Expand Up @@ -483,9 +492,10 @@ func (r *ServiceReconciler) deleteEntryFromFLB(ctx context.Context, svc *corev1.
if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
klog.V(5).Infof("Service %s/%s is being deleted from FLB ...", svc.Namespace, svc.Name)

setting := r.settings[svc.Namespace]
result := make(map[string][]string)
for _, port := range svc.Spec.Ports {
svcKey := fmt.Sprintf("%s/%s:%d", svc.Namespace, svc.Name, port.Port)
svcKey := serviceKey(setting, svc, port)
result[svcKey] = make([]string, 0)
}

Expand Down Expand Up @@ -549,7 +559,7 @@ func (r *ServiceReconciler) getEndpoints(ctx context.Context, svc *corev1.Servic
result := make(map[string][]string)

for _, port := range svc.Spec.Ports {
svcKey := fmt.Sprintf("%s/%s/%s:%d", setting.k8sCluster, svc.Namespace, svc.Name, port.Port)
svcKey := serviceKey(setting, svc, port)
result[svcKey] = make([]string, 0)

for _, ss := range ep.Subsets {
Expand Down Expand Up @@ -835,6 +845,10 @@ func serviceIPs(svc *corev1.Service) []string {
return ips
}

func serviceKey(setting *setting, svc *corev1.Service, port corev1.ServicePort) string {
return fmt.Sprintf("%s/%s/%s:%d", setting.k8sCluster, svc.Namespace, svc.Name, port.Port)
}

func (r *ServiceReconciler) addFinalizer(ctx context.Context, svc *corev1.Service) error {
if !r.hasFinalizer(ctx, svc) {
svc.Finalizers = append(svc.Finalizers, finalizerName)
Expand Down

0 comments on commit 22684e6

Please sign in to comment.