Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic when a port is not specified in an Openshift Route #1087

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions transformer/kubernetes/apiresource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,35 @@ func (d *Service) ingressToRoute(ingress networking.Ingress) []runtime.Object {

func (d *Service) routeToIngress(route okdroutev1.Route, ir irtypes.EnhancedIR, targetClusterSpec collecttypes.ClusterMetadataSpec) []runtime.Object {
targetPort := networking.ServiceBackendPort{}
if route.Spec.Port.TargetPort.Type == intstr.String {
targetPort.Name = route.Spec.Port.TargetPort.StrVal
if route.Spec.Port != nil {
if route.Spec.Port.TargetPort.Type == intstr.String {
targetPort.Name = route.Spec.Port.TargetPort.StrVal
} else {
targetPort.Number = route.Spec.Port.TargetPort.IntVal
}
} else {
targetPort.Number = route.Spec.Port.TargetPort.IntVal
targetName := route.Spec.To.Name
s, ok := ir.Services[targetName]
if !ok {
for _, s1 := range ir.Services {
if s1.BackendServiceName == targetName {
s = s1
ok = true
break
}
}
}
if !ok || len(s.ServiceToPodPortForwardings) == 0 {
logrus.Errorf("failed to find the service the route is pointing to. Exposing a default port (8080) in the Ingress")
targetPort.Number = 8080
} else {
portForwarding := s.ServiceToPodPortForwardings[0]
if portForwarding.ServicePort.Name != "" {
targetPort.Name = portForwarding.ServicePort.Name
} else {
targetPort.Number = portForwarding.ServicePort.Number
}
}
}

ingress := networking.Ingress{
Expand Down Expand Up @@ -281,9 +306,9 @@ func (d *Service) createRoutes(service irtypes.Service, ir irtypes.EnhancedIR, t
return routes
}

//TODO: Remove these two sections after helm v3 issue is fixed
//[https://github.com/openshift/origin/issues/24060]
//[https://bugzilla.redhat.com/show_bug.cgi?id=1773682]
// TODO: Remove these two sections after helm v3 issue is fixed
// [https://github.com/openshift/origin/issues/24060]
// [https://bugzilla.redhat.com/show_bug.cgi?id=1773682]
// Can't use https because of this https://github.com/openshift/origin/issues/2162
// When service has multiple ports,the route needs a port name. Port number doesn't seem to work.
func (d *Service) createRoute(irName string, service irtypes.Service, port core.ServicePort, hostprefix, path string, ir irtypes.EnhancedIR, targetCluster collecttypes.ClusterMetadata) *okdroutev1.Route {
Expand Down