Skip to content

Commit d0ad27d

Browse files
authored
feat: configurable tls port (#30)
* feat: gateway config with tls port * feat: add tls port to gateway
1 parent 10d2f7e commit d0ad27d

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

api/crds/manifests/gateway.openmcp.cloud_gatewayserviceconfigs.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,20 @@ spec:
156156
required:
157157
- chart
158158
type: object
159+
gateway:
160+
description: Gateway configuration.
161+
properties:
162+
tlsPort:
163+
default: 9443
164+
description: TLSPort is the port on which the gateway will listen
165+
for TLS traffic.
166+
format: int32
167+
type: integer
168+
type: object
159169
required:
160170
- dns
161171
- envoyGateway
172+
- gateway
162173
type: object
163174
type: object
164175
served: true

api/gateway/v1alpha1/config_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type GatewayServiceConfigSpec struct {
1313
// Clusters that should be included in the gateway configuration.
1414
Clusters []ClusterTerm `json:"clusters,omitempty"`
1515

16+
// Gateway configuration.
17+
Gateway GatewayConfig `json:"gateway"`
18+
1619
// DNS configuration.
1720
DNS DNSConfig `json:"dns"`
1821
}
@@ -88,6 +91,12 @@ type ImagesConfig struct {
8891
ImagePullSecrets []meta.LocalObjectReference `json:"imagePullSecrets,omitempty"`
8992
}
9093

94+
type GatewayConfig struct {
95+
// TLSPort is the port on which the gateway will listen for TLS traffic.
96+
// +kubebuilder:default=9443
97+
TLSPort int32 `json:"tlsPort,omitempty"`
98+
}
99+
91100
type DNSConfig struct {
92101
// BaseDomain is the domain from which subdomains will be derived. Example: dev.openmcp.example.com.
93102
// +kubebuilder:validation:Required

api/gateway/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controllers/cluster/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func (r *ClusterReconciler) buildGatewayManager(ctx context.Context, req reconci
228228
gw := &envoy.Gateway{
229229
Cluster: c,
230230
EnvoyConfig: r.Config.Spec.EnvoyGateway,
231+
GatewayConfig: r.Config.Spec.Gateway,
231232
DNSConfig: r.Config.Spec.DNS,
232233
PlatformClient: r.PlatformCluster.Client(),
233234
ClusterClient: access.Client(),

pkg/envoy/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strconv"
78
"time"
89

910
corev1 "k8s.io/api/core/v1"
@@ -27,6 +28,7 @@ const (
2728
gatewayClassName = "envoy-gateway"
2829
gatewayName = "default"
2930
gatewayNamespace = "openmcp-system"
31+
tlsPortAnnotation = "gateway.openmcp.cloud/tls-port"
3032
baseDomainAnnotation = "dns.openmcp.cloud/base-domain"
3133
)
3234

@@ -102,7 +104,7 @@ func (g *Gateway) reconcileGatewayFunc(obj *gatewayv1.Gateway) func() error {
102104
obj.Spec.Listeners = []gatewayv1.Listener{
103105
{
104106
Name: "tls",
105-
Port: 9443,
107+
Port: g.getTLSPort(),
106108
Protocol: gatewayv1.TLSProtocolType,
107109
TLS: &gatewayv1.ListenerTLSConfig{
108110
Mode: ptr.To(gatewayv1.TLSModePassthrough),
@@ -124,6 +126,7 @@ func (g *Gateway) reconcileGatewayFunc(obj *gatewayv1.Gateway) func() error {
124126
}
125127

126128
baseDomain := g.generateBaseDomain()
129+
metav1.SetMetaDataAnnotation(&obj.ObjectMeta, tlsPortAnnotation, strconv.Itoa(int(g.getTLSPort())))
127130
metav1.SetMetaDataAnnotation(&obj.ObjectMeta, baseDomainAnnotation, baseDomain)
128131

129132
return nil
@@ -134,6 +137,13 @@ func (g *Gateway) generateBaseDomain() string {
134137
return fmt.Sprintf("%s.%s.%s", g.Cluster.Name, g.Cluster.Namespace, g.DNSConfig.BaseDomain)
135138
}
136139

140+
func (g *Gateway) getTLSPort() int32 {
141+
if g.GatewayConfig.TLSPort != 0 {
142+
return g.GatewayConfig.TLSPort
143+
}
144+
return 9443
145+
}
146+
137147
// ----- EnvoyProxy -----
138148

139149
func getEnvoyProxy() *unstructured.Unstructured {

pkg/envoy/deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
type Gateway struct {
3131
Cluster *clustersv1alpha1.Cluster
3232
EnvoyConfig v1alpha1.EnvoyGatewayConfig
33+
GatewayConfig v1alpha1.GatewayConfig
3334
DNSConfig v1alpha1.DNSConfig
3435
PlatformClient client.Client
3536
ClusterClient client.Client

0 commit comments

Comments
 (0)