Skip to content

Commit

Permalink
Repopulate service if missing when creating port list
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed May 3, 2023
1 parent ab63a8e commit f1bd95c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ func (c *Controller) syncHandler(key string) error {
return err
}

if tunnel.Spec.ServiceRef == nil {
return fmt.Errorf("tunnel %s.%s has no service reference", tunnel.Name, tunnel.Namespace)
}

if service == nil {
svc, err := c.serviceLister.Services(tunnel.Namespace).Get(tunnel.Spec.ServiceRef.Name)
if err != nil {
return fmt.Errorf("error getting service: %s", err)
}
service = svc
}

start := time.Now()
hostConfig, err := getHostConfig(c,
tunnel,
Expand Down Expand Up @@ -645,6 +657,7 @@ func createClientDeployment(tunnel *inletsv1alpha1.Tunnel, c *Controller) error
licenseKey, _ := c.infraConfig.ProConfig.GetLicenseKey()

ports := getPortsString(service)

client := makeClientDeployment(tunnel,
c.infraConfig.GetInletsClientImage(),
ports,
Expand Down Expand Up @@ -789,17 +802,11 @@ func getHostConfig(c *Controller, tunnel *inletsv1alpha1.Tunnel, service *corev1

case "ec2":

ports := []string{}

if service != nil {
for _, port := range service.Spec.Ports {
ports = append(ports, fmt.Sprintf("%d", port.Port))
}
}
ports := getPortsString(service)

var additional = map[string]string{
"inlets-port": strconv.Itoa(inletsPort),
"ports": strings.Join(ports, ","),
"ports": ports,
}

if len(c.infraConfig.VpcID) > 0 {
Expand Down Expand Up @@ -1217,9 +1224,14 @@ func manageService(controller Controller, service corev1.Service) bool {
}

func getPortsString(service *corev1.Service) string {
if service == nil {
return ""
}

ports := ""
for _, p := range service.Spec.Ports {
ports = ports + fmt.Sprintf("%d,", p.Port)
}

return strings.TrimRight(ports, ",")
}

0 comments on commit f1bd95c

Please sign in to comment.