Skip to content

Commit e60a04b

Browse files
authored
GoogleC2P: remove dependency on metadata server for IPv6 node metadata (#8550)
Remove reliance on metadata server since it's result is no longer needed, hardcode IPv6 support in node metadata instead. Related c++ change: grpc/grpc#40571 Note we preserve prior behavior in case experiment `NewPickFirstEnabled` is disabled, because our testing/qualification has not covered that being disabled. Related: internal issue b/407587619 RELEASE NOTES: n/a
1 parent 3012391 commit e60a04b

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

xds/googledirectpath/googlec2p.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ func newNodeConfig(zone string, ipv6Capable bool) map[string]any {
182182
"id": fmt.Sprintf("C2P-%d", randInt()),
183183
"locality": map[string]any{"zone": zone},
184184
}
185+
if envconfig.NewPickFirstEnabled {
186+
// Enable dualstack endpoints in TD.
187+
// TODO(https://github.com/grpc/grpc-go/issues/8561): remove IPv6 metadata server queries entirely after old pick first is removed.
188+
ipv6Capable = true
189+
} else {
190+
logger.Infof("GRPC_EXPERIMENTAL_ENABLE_NEW_PICK_FIRST is disabled, setting ipv6Capable node metadata based on metadata server query")
191+
}
185192
if ipv6Capable {
186193
node["metadata"] = map[string]any{ipv6CapableMetadataName: true}
187194
}

xds/googledirectpath/googlec2p_test.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ func useCleanUniverseDomain(t *testing.T) {
103103
})
104104
}
105105

106+
// TODO(https://github.com/grpc/grpc-go/issues/8561): this content can be hardcoded directly
107+
// in wanted bootstraps again after old pick first is removed.
108+
func expectedNodeJSON(ipv6Capable bool) []byte {
109+
if !envconfig.NewPickFirstEnabled && !ipv6Capable {
110+
return []byte(`{
111+
"id": "C2P-666",
112+
"locality": {
113+
"zone": "test-zone"
114+
}
115+
}`)
116+
}
117+
// Otherwise, return the node metadata including the IPv6 capability flag.
118+
return []byte(`{
119+
"id": "C2P-666",
120+
"locality": {
121+
"zone": "test-zone"
122+
},
123+
"metadata": {
124+
"TRAFFICDIRECTOR_DIRECTPATH_C2P_IPV6_CAPABLE": true
125+
}
126+
}`)
127+
}
128+
106129
// Tests the scenario where the bootstrap env vars are set and we're running on
107130
// GCE. The test builds a google-c2p resolver and verifies that an xDS resolver
108131
// is built and that we don't fallback to DNS (because federation is enabled by
@@ -218,10 +241,7 @@ func (s) TestBuildXDS(t *testing.T) {
218241
]
219242
}`),
220243
},
221-
Node: []byte(`{
222-
"id": "C2P-666",
223-
"locality": {"zone": "test-zone"}
224-
}`),
244+
Node: expectedNodeJSON(false),
225245
}),
226246
},
227247
{
@@ -244,13 +264,7 @@ func (s) TestBuildXDS(t *testing.T) {
244264
]
245265
}`),
246266
},
247-
Node: []byte(`{
248-
"id": "C2P-666",
249-
"locality": {"zone": "test-zone"},
250-
"metadata": {
251-
"TRAFFICDIRECTOR_DIRECTPATH_C2P_IPV6_CAPABLE": true
252-
}
253-
}`),
267+
Node: expectedNodeJSON(true),
254268
}),
255269
},
256270
{
@@ -274,13 +288,7 @@ func (s) TestBuildXDS(t *testing.T) {
274288
]
275289
}`),
276290
},
277-
Node: []byte(`{
278-
"id": "C2P-666",
279-
"locality": {"zone": "test-zone"},
280-
"metadata": {
281-
"TRAFFICDIRECTOR_DIRECTPATH_C2P_IPV6_CAPABLE": true
282-
}
283-
}`),
291+
Node: expectedNodeJSON(true),
284292
}),
285293
},
286294
} {
@@ -442,10 +450,7 @@ func (s) TestSetUniverseDomainNonDefault(t *testing.T) {
442450
]
443451
}`),
444452
},
445-
Node: []byte(`{
446-
"id": "C2P-666",
447-
"locality": {"zone": "test-zone"}
448-
}`),
453+
Node: expectedNodeJSON(false),
449454
})
450455
if diff := cmp.Diff(wantBootstrapConfig, gotConfig); diff != "" {
451456
t.Fatalf("Unexpected diff in bootstrap config (-want +got):\n%s", diff)
@@ -513,10 +518,7 @@ func (s) TestDefaultUniverseDomain(t *testing.T) {
513518
]
514519
}`),
515520
},
516-
Node: []byte(`{
517-
"id": "C2P-666",
518-
"locality": {"zone": "test-zone"}
519-
}`),
521+
Node: expectedNodeJSON(false),
520522
})
521523
if diff := cmp.Diff(wantBootstrapConfig, gotConfig); diff != "" {
522524
t.Fatalf("Unexpected diff in bootstrap config (-want +got):\n%s", diff)

0 commit comments

Comments
 (0)