Skip to content

Commit 726f64f

Browse files
committed
add local hash name func
Signed-off-by: Karol Szwaj <[email protected]>
1 parent ac19643 commit 726f64f

File tree

5 files changed

+9
-61
lines changed

5 files changed

+9
-61
lines changed

internal/infrastructure/kubernetes/infra.go

-9
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,10 @@ type Infra struct {
6262

6363
// NewInfra returns a new Infra.
6464
func NewInfra(cli client.Client, cfg *config.Server) *Infra {
65-
<<<<<<< HEAD
6665
return &Infra{
6766
// Always set infra namespace to cfg.ControllerNamespace,
6867
// Otherwise RateLimit resource provider will failed to create/delete.
6968
Namespace: cfg.ControllerNamespace,
70-
=======
71-
var ns string
72-
if !cfg.EnvoyGateway.GatewayNamespaceMode() {
73-
ns = cfg.ControllerNamespace
74-
}
75-
return &Infra{
76-
Namespace: ns,
77-
>>>>>>> 445c3b09 (Revert "Add controller namespace to infra")
7869
DNSDomain: cfg.DNSDomain,
7970
EnvoyGateway: cfg.EnvoyGateway,
8071
Client: New(cli),

internal/infrastructure/kubernetes/proxy/resource_provider.go

-25
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,7 @@ type ResourceRender struct {
5959

6060
func NewResourceRender(ns, dnsDomain string, infra *ir.ProxyInfra, gateway *egv1a1.EnvoyGateway) *ResourceRender {
6161
return &ResourceRender{
62-
<<<<<<< HEAD
63-
<<<<<<< HEAD
6462
namespace: ns,
65-
=======
66-
Namespace: infraNamespace,
67-
ControllerNamespace: controllerNamespace,
68-
>>>>>>> 5aa72e72 (Add controller namespace to infra)
69-
=======
70-
Namespace: ns,
71-
>>>>>>> 445c3b09 (Revert "Add controller namespace to infra")
7263
DNSDomain: dnsDomain,
7364
infra: infra,
7465
ShutdownManager: gateway.GetEnvoyGatewayProvider().GetEnvoyGatewayKubeProvider().ShutdownManager,
@@ -293,15 +284,7 @@ func (r *ResourceRender) Deployment() (*appsv1.Deployment, error) {
293284
}
294285

295286
// Get expected bootstrap configurations rendered ProxyContainers
296-
<<<<<<< HEAD
297-
<<<<<<< HEAD
298287
containers, err := expectedProxyContainers(r.infra, deploymentConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.Namespace(), r.DNSDomain, r.GatewayNamespaceMode)
299-
=======
300-
containers, err := expectedProxyContainers(r.infra, deploymentConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.ControllerNamespace, r.DNSDomain, r.GatewayNamespaceMode)
301-
>>>>>>> 5aa72e72 (Add controller namespace to infra)
302-
=======
303-
containers, err := expectedProxyContainers(r.infra, deploymentConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.Namespace, r.DNSDomain, r.GatewayNamespaceMode)
304-
>>>>>>> 445c3b09 (Revert "Add controller namespace to infra")
305288
if err != nil {
306289
return nil, err
307290
}
@@ -389,15 +372,7 @@ func (r *ResourceRender) DaemonSet() (*appsv1.DaemonSet, error) {
389372
}
390373

391374
// Get expected bootstrap configurations rendered ProxyContainers
392-
<<<<<<< HEAD
393-
<<<<<<< HEAD
394375
containers, err := expectedProxyContainers(r.infra, daemonSetConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.Namespace(), r.DNSDomain, r.GatewayNamespaceMode)
395-
=======
396-
containers, err := expectedProxyContainers(r.infra, daemonSetConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.ControllerNamespace, r.DNSDomain, r.GatewayNamespaceMode)
397-
>>>>>>> 5aa72e72 (Add controller namespace to infra)
398-
=======
399-
containers, err := expectedProxyContainers(r.infra, daemonSetConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.Namespace, r.DNSDomain, r.GatewayNamespaceMode)
400-
>>>>>>> 445c3b09 (Revert "Add controller namespace to infra")
401376
if err != nil {
402377
return nil, err
403378
}

internal/infrastructure/kubernetes/proxy/resource_provider_test.go

-9
Original file line numberDiff line numberDiff line change
@@ -1315,8 +1315,6 @@ func TestServiceAccount(t *testing.T) {
13151315

13161316
for _, tc := range cases {
13171317
t.Run(tc.name, func(t *testing.T) {
1318-
<<<<<<< HEAD
1319-
<<<<<<< HEAD
13201318
ns := cfg.ControllerNamespace
13211319
if tc.gatewayNamespaceMode {
13221320
deployType := egv1a1.KubernetesDeployModeType(egv1a1.KubernetesDeployModeTypeGatewayNamespace)
@@ -1331,13 +1329,6 @@ func TestServiceAccount(t *testing.T) {
13311329
ns = tc.infra.GetProxyInfra().Namespace
13321330
}
13331331
r := NewResourceRender(ns, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
1334-
1335-
=======
1336-
r := NewResourceRender(cfg.ControllerNamespace, cfg.ControllerNamespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
1337-
>>>>>>> 5aa72e72 (Add controller namespace to infra)
1338-
=======
1339-
r := NewResourceRender(cfg.ControllerNamespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
1340-
>>>>>>> 445c3b09 (Revert "Add controller namespace to infra")
13411332
sa, err := r.ServiceAccount()
13421333
require.NoError(t, err)
13431334

internal/infrastructure/kubernetes/proxy_infra.go

-16
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@ func (i *Infra) CreateOrUpdateProxyInfra(ctx context.Context, infra *ir.Infra) e
2323
return errors.New("infra proxy ir is nil")
2424
}
2525

26-
<<<<<<< HEAD
2726
ns := i.GetResourceNamespace(infra)
2827
r := proxy.NewResourceRender(ns, i.DNSDomain, infra.GetProxyInfra(), i.EnvoyGateway)
29-
=======
30-
if i.EnvoyGateway.GatewayNamespaceMode() && i.Namespace == "" {
31-
i.Namespace = infra.Proxy.Namespace
32-
}
33-
34-
r := proxy.NewResourceRender(i.Namespace, i.DNSDomain, infra.GetProxyInfra(), i.EnvoyGateway)
35-
>>>>>>> 445c3b09 (Revert "Add controller namespace to infra")
3628
return i.createOrUpdate(ctx, r)
3729
}
3830

@@ -42,16 +34,8 @@ func (i *Infra) DeleteProxyInfra(ctx context.Context, infra *ir.Infra) error {
4234
return errors.New("infra ir is nil")
4335
}
4436

45-
<<<<<<< HEAD
4637
ns := i.GetResourceNamespace(infra)
4738
r := proxy.NewResourceRender(ns, i.DNSDomain, infra.GetProxyInfra(), i.EnvoyGateway)
48-
=======
49-
if i.EnvoyGateway.GatewayNamespaceMode() && i.Namespace == "" {
50-
i.Namespace = infra.Proxy.Namespace
51-
}
52-
53-
r := proxy.NewResourceRender(i.Namespace, i.DNSDomain, infra.GetProxyInfra(), i.EnvoyGateway)
54-
>>>>>>> 445c3b09 (Revert "Add controller namespace to infra")
5539
return i.delete(ctx, r)
5640
}
5741

internal/xds/server/kubejwt/tokenreview.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
"k8s.io/client-go/kubernetes"
1717
"k8s.io/client-go/rest"
1818

19-
"github.com/envoyproxy/gateway/internal/infrastructure/kubernetes/proxy"
19+
"github.com/envoyproxy/gateway/internal/envoygateway/config"
20+
"github.com/envoyproxy/gateway/internal/utils"
2021
)
2122

2223
// GetKubernetesClient creates a Kubernetes client using in-cluster configuration.
@@ -66,10 +67,16 @@ func (i *JWTAuthInterceptor) validateKubeJWT(ctx context.Context, token string)
6667

6768
irKeys := i.cache.GetIrKeys()
6869
for _, irKey := range irKeys {
69-
if proxy.ExpectedResourceHashedName(irKey) == sa {
70+
if irKey2ServiceAccountName(irKey) == sa {
7071
return nil
7172
}
7273
}
7374

7475
return fmt.Errorf("envoy service account %s not found in the cache", sa)
7576
}
77+
78+
// this is the same logic used in infra pkg func ExpectedResourceHashedName to generate the resource name.
79+
func irKey2ServiceAccountName(irKey string) string {
80+
hashedName := utils.GetHashedName(irKey, 48)
81+
return fmt.Sprintf("%s-%s", config.EnvoyPrefix, hashedName)
82+
}

0 commit comments

Comments
 (0)