diff --git a/pkg/reconciler/eventlistener/resources/service.go b/pkg/reconciler/eventlistener/resources/service.go index ef195d40c..6adffd41c 100644 --- a/pkg/reconciler/eventlistener/resources/service.go +++ b/pkg/reconciler/eventlistener/resources/service.go @@ -77,7 +77,7 @@ func ServicePort(el *v1beta1.EventListener, c Config) corev1.ServicePort { var elCert, elKey string servicePortName := eventListenerServicePortName - servicePortPort := *c.Port + servicePort := *c.Port certEnv := map[string]*corev1.EnvVarSource{} if el.Spec.Resources.KubernetesResource != nil { @@ -87,6 +87,9 @@ func ServicePort(el *v1beta1.EventListener, c Config) corev1.ServicePort { el.Spec.Resources.KubernetesResource.Template.Spec.Containers[0].Env[i].ValueFrom } } + if el.Spec.Resources.KubernetesResource.ServicePort != nil { + servicePort = int(*el.Spec.Resources.KubernetesResource.ServicePort) + } } if v, ok := certEnv["TLS_CERT"]; ok { @@ -105,14 +108,14 @@ func ServicePort(el *v1beta1.EventListener, c Config) corev1.ServicePort { if *c.Port == DefaultPort { // We return port 8443 if TLS is enabled and the default HTTP port is set. // This effectively makes 8443 the default HTTPS port unless a user explicitly sets a different port. - servicePortPort = 8443 + servicePort = 8443 } } return corev1.ServicePort{ Name: servicePortName, Protocol: corev1.ProtocolTCP, - Port: int32(servicePortPort), + Port: int32(servicePort), TargetPort: intstr.IntOrString{ IntVal: int32(eventListenerContainerPort), }, diff --git a/pkg/reconciler/eventlistener/resources/service_test.go b/pkg/reconciler/eventlistener/resources/service_test.go index 7e19774c5..d1f845a33 100644 --- a/pkg/reconciler/eventlistener/resources/service_test.go +++ b/pkg/reconciler/eventlistener/resources/service_test.go @@ -138,6 +138,9 @@ func TestService(t *testing.T) { } func TestServicePort(t *testing.T) { + + k8sResSvcPort := int32(80) + tests := []struct { name string el *v1beta1.EventListener @@ -200,6 +203,22 @@ func TestServicePort(t *testing.T) { IntVal: int32(eventListenerContainerPort), }, }, + }, { + name: "EventListener with ServicePort 80 in KubernetesResource", + el: makeEL(withStatus, withTLSPort, func(el *v1beta1.EventListener) { + el.Spec.Resources.KubernetesResource = &v1beta1.KubernetesResource{ + ServicePort: &k8sResSvcPort, + } + }), + config: *MakeConfig(), + expectedServicePort: corev1.ServicePort{ + Name: eventListenerServicePortName, + Protocol: corev1.ProtocolTCP, + Port: k8sResSvcPort, + TargetPort: intstr.IntOrString{ + IntVal: int32(eventListenerContainerPort), + }, + }, }, { name: "EventListener with ServicePort: 80", el: makeEL(withStatus, withServicePort80),