Skip to content

Commit

Permalink
xds: use ::1 if IPFamily is IPv6 on admin server (#4801)
Browse files Browse the repository at this point in the history
xds: use  if IPFamily is IPv6

Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain authored Nov 28, 2024
1 parent 9f9de74 commit 17e932c
Show file tree
Hide file tree
Showing 6 changed files with 595 additions and 11 deletions.
13 changes: 13 additions & 0 deletions internal/infrastructure/common/proxy_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ import (
"github.com/envoyproxy/gateway/internal/xds/bootstrap"
)

func getIPFamily(infra *ir.ProxyInfra) *egv1a1.IPFamily {
if infra == nil || infra.Config == nil {
return nil
}

return infra.Config.Spec.IPFamily
}

// BuildProxyArgs builds command arguments for proxy infrastructure.
func BuildProxyArgs(
infra *ir.ProxyInfra,
shutdownConfig *egv1a1.ShutdownConfig,
bootstrapConfigOptions *bootstrap.RenderBootstrapConfigOptions,
serviceNode string,
) ([]string, error) {
// If IPFamily is not set, try to determine it from the infrastructure.
if bootstrapConfigOptions != nil && bootstrapConfigOptions.IPFamily == nil {
bootstrapConfigOptions.IPFamily = getIPFamily(infra)
}

bootstrapConfigurations, err := bootstrap.GetRenderedBootstrapConfig(bootstrapConfigOptions)
if err != nil {
return nil, err
Expand Down
33 changes: 24 additions & 9 deletions internal/infrastructure/kubernetes/proxy/resource_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ func newTestInfra() *ir.Infra {
return newTestInfraWithAnnotations(nil)
}

func newTestIPv6Infra() *ir.Infra {
i := newTestInfra()
i.Proxy.Config = &egv1a1.EnvoyProxy{
Spec: egv1a1.EnvoyProxySpec{
IPFamily: ptr.To(egv1a1.IPv6),
},
}
return i
}

func newTestInfraWithAnnotations(annotations map[string]string) *ir.Infra {
return newTestInfraWithAnnotationsAndLabels(annotations, nil)
}
Expand Down Expand Up @@ -200,6 +210,11 @@ func TestDeployment(t *testing.T) {
deploy: nil,
bootstrap: `test bootstrap config`,
},
{
caseName: "ipv6",
infra: newTestIPv6Infra(),
deploy: nil,
},
{
caseName: "extension-env",
infra: newTestInfra(),
Expand Down Expand Up @@ -568,15 +583,6 @@ func TestDeployment(t *testing.T) {
dp, err := r.Deployment()
require.NoError(t, err)

expected, err := loadDeployment(tc.caseName)
require.NoError(t, err)

sortEnv := func(env []corev1.EnvVar) {
sort.Slice(env, func(i, j int) bool {
return env[i].Name > env[j].Name
})
}

if *overrideTestData {
deploymentYAML, err := yaml.Marshal(dp)
require.NoError(t, err)
Expand All @@ -586,8 +592,17 @@ func TestDeployment(t *testing.T) {
return
}

expected, err := loadDeployment(tc.caseName)
require.NoError(t, err)

sortEnv := func(env []corev1.EnvVar) {
sort.Slice(env, func(i, j int) bool {
return env[i].Name > env[j].Name
})
}
sortEnv(dp.Spec.Template.Spec.Containers[0].Env)
sortEnv(expected.Spec.Template.Spec.Containers[0].Env)

assert.Equal(t, expected, dp)
})
}
Expand Down
Loading

0 comments on commit 17e932c

Please sign in to comment.