Skip to content

Commit

Permalink
make agentendpoint.spec.upstream.protocol optional with an internal d…
Browse files Browse the repository at this point in the history
…efault

Signed-off-by: Alice-Lilith <[email protected]>
  • Loading branch information
Alice-Lilith committed Dec 6, 2024
1 parent 6839f09 commit ff4e333
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 2 additions & 3 deletions api/ngrok/v1alpha1/agentendpoint_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ type EndpointUpstream struct {
// with prior knowledge (defaulting to http1). alpn negotiation is not currently supported.
//
// +kubebuilder:validation:Enum=http1;http2
// +kubebuilder:validation:Required
// +kubebuilder:default=http1
Protocol commonv1alpha1.ApplicationProtocol `json:"protocol"`
// +kubebuilder:validation:Optional
Protocol *commonv1alpha1.ApplicationProtocol `json:"protocol"`

// Optionally specify the version of proxy protocol to use if the upstream requires it
//
Expand Down
5 changes: 5 additions & 0 deletions api/ngrok/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions pkg/tunneldriver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ func (td *TunnelDriver) CreateAgentEndpoint(ctx context.Context, name string, sp
defer td.stopTunnel(context.Background(), tun)
}

upstreamProtocol := string(spec.Upstream.Protocol)
upstreamURL, err := ParseAndSanitizeEndpointURL(spec.Upstream.URL, false)
if err != nil {
err := fmt.Errorf("error parsing spec.upstream.url: %w", err)
Expand Down Expand Up @@ -447,7 +446,12 @@ func (td *TunnelDriver) CreateAgentEndpoint(ctx context.Context, name string, sp
for _, o := range commonOpts {
opts = append(opts, o)
}
opts = append(opts, config.WithAppProtocol(upstreamProtocol))
// Default upstream protocol to HTTP1 if not configured
upstreamProto := string(commonv1alpha1.ApplicationProtocol_HTTP1)
if spec.Upstream.Protocol != nil {
upstreamProto = string(*spec.Upstream.Protocol)
}
opts = append(opts, config.WithAppProtocol(upstreamProto))
tunnelConfig = config.HTTPEndpoint(opts...)
case "tls":
opts := []config.TLSEndpointOption{}
Expand Down Expand Up @@ -489,7 +493,7 @@ func (td *TunnelDriver) CreateAgentEndpoint(ctx context.Context, name string, sp
upstreamURL.Hostname(),
upstreamPort,
upstreamTLS,
&spec.Upstream.Protocol,
spec.Upstream.Protocol,
)
return nil
}
Expand Down

0 comments on commit ff4e333

Please sign in to comment.