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 EL Status URL for kubernetesresource.serviceport #1632

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions pkg/reconciler/eventlistener/resources/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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),
},
Expand Down
19 changes: 19 additions & 0 deletions pkg/reconciler/eventlistener/resources/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func TestService(t *testing.T) {
}

func TestServicePort(t *testing.T) {

k8sResSvcPort := int32(80)

tests := []struct {
name string
el *v1beta1.EventListener
Expand Down Expand Up @@ -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),
Expand Down