Skip to content

Commit

Permalink
feat: set full URI for the envoy-gateway service using name and names…
Browse files Browse the repository at this point in the history
…pace (#4533)

* feat: set full URI for the envoy-gateway service using name and namespace

Signed-off-by: Rajat Vig <[email protected]>

* Use the correct namespace and dnsdomain from Gateway config

Signed-off-by: Rajat Vig <[email protected]>

* Use constant from config

Signed-off-by: Rajat Vig <[email protected]>

---------

Signed-off-by: Rajat Vig <[email protected]>
  • Loading branch information
rajatvig authored Oct 26, 2024
1 parent 6f5ae8e commit 3e8730f
Show file tree
Hide file tree
Showing 42 changed files with 65 additions and 54 deletions.
4 changes: 4 additions & 0 deletions internal/infrastructure/kubernetes/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Infra struct {
// Namespace is the Namespace used for managed infra.
Namespace string

// DNSDomain is the dns domain used by k8s services. Defaults to "cluster.local".
DNSDomain string

// EnvoyGateway is the configuration used to startup Envoy Gateway.
EnvoyGateway *egv1a1.EnvoyGateway

Expand All @@ -61,6 +64,7 @@ type Infra struct {
func NewInfra(cli client.Client, cfg *config.Server) *Infra {
return &Infra{
Namespace: cfg.Namespace,
DNSDomain: cfg.DNSDomain,
EnvoyGateway: cfg.EnvoyGateway,
Client: New(cli),
}
Expand Down
3 changes: 3 additions & 0 deletions internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
containerSpec *egv1a1.KubernetesContainerSpec,
shutdownConfig *egv1a1.ShutdownConfig,
shutdownManager *egv1a1.ShutdownManager,
namespace string,
dnsDomain string,
) ([]corev1.Container, error) {
// Define slice to hold container ports
var ports []corev1.ContainerPort
Expand Down Expand Up @@ -132,6 +134,7 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
TrustedCA: filepath.Join("/sds", common.SdsCAFilename),
},
MaxHeapSizeBytes: maxHeapSizeBytes,
XdsServerHost: ptr.To(fmt.Sprintf("%s.%s.svc.%s", config.EnvoyGatewayServiceName, namespace, dnsDomain)),
}

args, err := common.BuildProxyArgs(infra, shutdownConfig, bootstrapConfigOptions, fmt.Sprintf("$(%s)", envoyPodEnvVar))
Expand Down
10 changes: 7 additions & 3 deletions internal/infrastructure/kubernetes/proxy/resource_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ type ResourceRender struct {
// Namespace is the Namespace used for managed infra.
Namespace string

// DNSDomain is the dns domain used by k8s services. Defaults to "cluster.local".
DNSDomain string

ShutdownManager *egv1a1.ShutdownManager
}

func NewResourceRender(ns string, infra *ir.ProxyInfra, gateway *egv1a1.EnvoyGateway) *ResourceRender {
func NewResourceRender(ns string, dnsDomain string, infra *ir.ProxyInfra, gateway *egv1a1.EnvoyGateway) *ResourceRender {
return &ResourceRender{
Namespace: ns,
DNSDomain: dnsDomain,
infra: infra,
ShutdownManager: gateway.GetEnvoyGatewayProvider().GetEnvoyGatewayKubeProvider().ShutdownManager,
}
Expand Down Expand Up @@ -258,7 +262,7 @@ func (r *ResourceRender) Deployment() (*appsv1.Deployment, error) {

proxyConfig := r.infra.GetProxyConfig()
// Get expected bootstrap configurations rendered ProxyContainers
containers, err := expectedProxyContainers(r.infra, deploymentConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager)
containers, err := expectedProxyContainers(r.infra, deploymentConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.Namespace, r.DNSDomain)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -360,7 +364,7 @@ func (r *ResourceRender) DaemonSet() (*appsv1.DaemonSet, error) {
proxyConfig := r.infra.GetProxyConfig()

// Get expected bootstrap configurations rendered ProxyContainers
containers, err := expectedProxyContainers(r.infra, daemonSetConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager)
containers, err := expectedProxyContainers(r.infra, daemonSetConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager, r.Namespace, r.DNSDomain)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func TestDeployment(t *testing.T) {
tc.infra.Proxy.Config.Spec.ExtraArgs = tc.extraArgs
}

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
r := NewResourceRender(cfg.Namespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
dp, err := r.Deployment()
require.NoError(t, err)

Expand Down Expand Up @@ -993,7 +993,7 @@ func TestDaemonSet(t *testing.T) {
tc.infra.Proxy.Config.Spec.ExtraArgs = tc.extraArgs
}

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
r := NewResourceRender(cfg.Namespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
ds, err := r.DaemonSet()
require.NoError(t, err)

Expand Down Expand Up @@ -1143,7 +1143,7 @@ func TestService(t *testing.T) {
provider.EnvoyService = tc.service
}

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
r := NewResourceRender(cfg.Namespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
svc, err := r.Service()
require.NoError(t, err)

Expand Down Expand Up @@ -1186,7 +1186,7 @@ func TestConfigMap(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
r := NewResourceRender(cfg.Namespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
cm, err := r.ConfigMap()
require.NoError(t, err)

Expand Down Expand Up @@ -1229,7 +1229,7 @@ func TestServiceAccount(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
r := NewResourceRender(cfg.Namespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
sa, err := r.ServiceAccount()
require.NoError(t, err)

Expand Down Expand Up @@ -1285,7 +1285,7 @@ func TestPDB(t *testing.T) {

provider.GetEnvoyProxyKubeProvider()

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
r := NewResourceRender(cfg.Namespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)

pdb, err := r.PodDisruptionBudget()
require.NoError(t, err)
Expand Down Expand Up @@ -1371,7 +1371,7 @@ func TestHorizontalPodAutoscaler(t *testing.T) {
}
provider.GetEnvoyProxyKubeProvider()

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
r := NewResourceRender(cfg.Namespace, cfg.DNSDomain, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
hpa, err := r.HorizontalPodAutoscaler()
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
endpoint:
address:
socket_address:
address: envoy-gateway
address: envoy-gateway.envoy-gateway-system.svc.cluster.local
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
Expand Down
Loading

0 comments on commit 3e8730f

Please sign in to comment.