fix: send service ports on lb allocate
deploy / build (push) Successful in 3m7s
Release / release (push) Failing after 4s

This commit is contained in:
2026-08-01 07:25:02 +03:30
parent 10d741ceb6
commit 1ce335d3db
3 changed files with 83 additions and 0 deletions
+29
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strings"
"time"
corev1 "k8s.io/api/core/v1"
@@ -163,10 +164,15 @@ func (c *Controller) sync(ctx context.Context, key string) error {
if ingressIP(svc) != "" {
return nil
}
ports, err := servicePortsToAllocateRules(svc)
if err != nil {
return err
}
lb, err := c.lbClient.Allocate(ctx, provisioner.AllocateRequest{
Namespace: namespace,
Name: name,
Ports: ports,
})
if err != nil {
return err
@@ -217,6 +223,29 @@ func ingressIP(svc *corev1.Service) string {
return ""
}
func servicePortsToAllocateRules(svc *corev1.Service) ([]provisioner.AllocatePortRule, error) {
if svc == nil {
return nil, fmt.Errorf("service is required")
}
if len(svc.Spec.Ports) == 0 {
return nil, fmt.Errorf("service %s/%s has no ports", svc.Namespace, svc.Name)
}
out := make([]provisioner.AllocatePortRule, 0, len(svc.Spec.Ports))
for _, p := range svc.Spec.Ports {
protocol := string(p.Protocol)
if protocol == "" {
protocol = string(corev1.ProtocolTCP)
}
switch protocol {
case string(corev1.ProtocolTCP), string(corev1.ProtocolUDP):
out = append(out, provisioner.AllocatePortRule{Protocol: strings.ToLower(protocol), PortFrom: int(p.Port)})
default:
return nil, fmt.Errorf("service %s/%s has unsupported protocol %q for load balancer firewall", svc.Namespace, svc.Name, protocol)
}
}
return out, nil
}
func containsString(items []string, target string) bool {
for _, item := range items {
if item == target {