99"net"
1010"net/http"
1111"net/netip"
12+ "slices"
1213"strings"
1314"time"
1415
@@ -47,6 +48,7 @@ type TunnelServerOption func(*tunnelServerOptions)
4748
4849type tunnelServerOptions struct {
4950proxyAddr string
51+ publicAddr string
5052ulaPrefix netip.Prefix
5153certPath string
5254keyPath string
@@ -58,6 +60,7 @@ type tunnelServerOptions struct {
5860func defaultServerOptions () * tunnelServerOptions {
5961return & tunnelServerOptions {
6062proxyAddr : "0.0.0.0:9443" ,
63+ publicAddr : "" ,
6164ulaPrefix : netip .MustParsePrefix ("fd00::/64" ),
6265certPath : "/etc/apoxy/certs/tunnelproxy.crt" ,
6366keyPath : "/etc/apoxy/certs/tunnelproxy.key" ,
@@ -74,6 +77,14 @@ func WithProxyAddr(addr string) TunnelServerOption {
7477}
7578}
7679
80+ // WithPublicAddr sets the address tunnel proxy is reachable at. This
81+ // address will be set on the TunnelNode objects that this proxy is serving.
82+ func WithPublicAddr (addr string ) TunnelServerOption {
83+ return func (o * tunnelServerOptions ) {
84+ o .publicAddr = addr
85+ }
86+ }
87+
7788// WithULAPrefix sets the Unique Local Address prefix.
7889func WithULAPrefix (prefix netip.Prefix ) TunnelServerOption {
7990return func (o * tunnelServerOptions ) {
@@ -472,6 +483,19 @@ func (t *TunnelServer) reconcile(ctx context.Context, request reconcile.Request)
472483return reconcile.Result {}, nil
473484}
474485
486+ if t .options .publicAddr != "" {
487+ var updated bool
488+ if ! slices .Contains (node .Status .Addresses , t .options .publicAddr ) {
489+ node .Status .Addresses = append (node .Status .Addresses , t .options .publicAddr )
490+ updated = true
491+ }
492+ if updated {
493+ if err := t .Status ().Update (ctx , node ); err != nil {
494+ return reconcile.Result {}, fmt .Errorf ("failed to update TunnelNode status: %w" , err )
495+ }
496+ }
497+ }
498+
475499t .AddTunnelNode (node )
476500
477501return ctrl.Result {}, nil
0 commit comments