diff --git a/go.mod b/go.mod index 8502395c..66d94cc9 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.1 golang.ngrok.com/ngrok v1.3.1 + golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df golang.org/x/sync v0.1.0 k8s.io/api v0.26.0 k8s.io/apimachinery v0.26.0 @@ -81,7 +82,7 @@ require ( go.uber.org/multierr v1.10.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.ngrok.com/muxado/v2 v2.0.0 // indirect - golang.org/x/mod v0.8.0 // indirect + golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/oauth2 v0.3.0 // indirect golang.org/x/sys v0.8.0 // indirect diff --git a/go.sum b/go.sum index 8973a0a5..d60150b0 100644 --- a/go.sum +++ b/go.sum @@ -598,6 +598,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -621,8 +623,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/internal/store/driver.go b/internal/store/driver.go index 285c0b2d..21fea600 100644 --- a/internal/store/driver.go +++ b/internal/store/driver.go @@ -11,6 +11,7 @@ import ( "time" "github.com/go-logr/logr" + "golang.org/x/exp/maps" corev1 "k8s.io/api/core/v1" netv1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/runtime" @@ -453,11 +454,18 @@ func (d *Driver) calculateHTTPSEdges() []ingressv1alpha1.HTTPSEdge { func (d *Driver) calculateTunnels() []ingressv1alpha1.Tunnel { // Tunnels should be unique on a service and port basis so if they are referenced more than once, we // only create one tunnel per service and port. - tunnelMap := make(map[string]ingressv1alpha1.Tunnel) + var tunnels = map[string]map[string]ingressv1alpha1.Tunnel{} + ingresses := d.ListNgrokIngressesV1() for _, ingress := range ingresses { namespace := ingress.Namespace + namespaceTunnels, namespaceOk := tunnels[namespace] + if !namespaceOk { + namespaceTunnels = make(map[string]ingressv1alpha1.Tunnel) + tunnels[namespace] = namespaceTunnels + } + for _, rule := range ingress.Spec.Rules { for _, path := range rule.HTTP.Paths { // We only support service backends right now. TODO: support resource backends @@ -474,7 +482,7 @@ func (d *Driver) calculateTunnels() []ingressv1alpha1.Tunnel { tunnelAddr := fmt.Sprintf("%s.%s.%s:%d", serviceName, namespace, clusterDomain, servicePort) tunnelName := fmt.Sprintf("%s-%d", serviceName, servicePort) - tunnelMap[tunnelName] = ingressv1alpha1.Tunnel{ + namespaceTunnels[tunnelName] = ingressv1alpha1.Tunnel{ ObjectMeta: metav1.ObjectMeta{ Name: tunnelName, Namespace: ingress.Namespace, @@ -491,11 +499,11 @@ func (d *Driver) calculateTunnels() []ingressv1alpha1.Tunnel { } } - tunnels := make([]ingressv1alpha1.Tunnel, 0, len(tunnelMap)) - for _, tunnel := range tunnelMap { - tunnels = append(tunnels, tunnel) + var allTunnels []ingressv1alpha1.Tunnel + for _, namespaceTunnels := range maps.Values(tunnels) { + allTunnels = append(allTunnels, maps.Values(namespaceTunnels)...) } - return tunnels + return allTunnels } func (d *Driver) calculateIngressLoadBalancerIPStatus(ing *netv1.Ingress, c client.Reader) []netv1.IngressLoadBalancerIngress {