Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kuma-cp): guard the nil version in metadata #3969

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/core/xds/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func (m *DataplaneMetadata) GetVersion() *mesh_proto.Version {
}

func DataplaneMetadataFromXdsMetadata(xdsMetadata *structpb.Struct) *DataplaneMetadata {
// Be extra careful here about nil checks since xdsMetadata is a "user" input.
// Even if we know that something should not be nil since we are generating metadata,
// the DiscoveryRequest can still be crafted manually to crash the CP.
metadata := DataplaneMetadata{}
if xdsMetadata == nil {
return &metadata
Expand Down Expand Up @@ -172,7 +175,9 @@ func DataplaneMetadataFromXdsMetadata(xdsMetadata *structpb.Struct) *DataplaneMe
for field, val := range value.GetStructValue().GetFields() {
if strings.HasPrefix(field, FieldPrefixDependenciesVersion) {
dependencyName := strings.TrimPrefix(field, FieldPrefixDependenciesVersion+".")
metadata.Version.Dependencies[dependencyName] = val.GetStringValue()
if metadata.GetVersion().GetDependencies() != nil {
metadata.Version.Dependencies[dependencyName] = val.GetStringValue()
}
} else {
dynamicMetadata[field] = val.GetStringValue()
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/core/xds/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ var _ = Describe("DataplaneMetadataFromXdsMetadata", func() {
EmptyDNSPort: 8001,
},
}),
Entry("should ignore dependencies version provided through metadata if version is not set at all", testCase{
node: &structpb.Struct{
Fields: map[string]*structpb.Value{
"dynamicMetadata": {
Kind: &structpb.Value_StructValue{
StructValue: &structpb.Struct{
Fields: map[string]*structpb.Value{
"version.dependencies.coredns": {
Kind: &structpb.Value_StringValue{
StringValue: "8000",
},
},
},
},
},
},
},
},
expected: xds.DataplaneMetadata{
DynamicMetadata: map[string]string{},
},
}),
)

It("should parse version", func() { // this has to be separate test because Equal does not work on proto
Expand Down