Skip to content

Commit

Permalink
implement ContentsByName for runtime cache
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <[email protected]>
  • Loading branch information
skriss committed Mar 4, 2024
1 parent 1fc02b1 commit be82890
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/xdscache/v3/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"sync"

envoy_service_runtime_v3 "github.com/envoyproxy/go-control-plane/envoy/service/runtime/v3"
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"
Expand Down Expand Up @@ -58,7 +59,7 @@ func NewRuntimeCache(runtimeSettings ConfigurableRuntimeSettings) *RuntimeCache
}
}

func (c *RuntimeCache) buildDynamicLayer() []proto.Message {
func (c *RuntimeCache) buildDynamicLayer() []*envoy_service_runtime_v3.Runtime {
values := make(map[string]*structpb.Value)
for k, v := range c.runtimeKV {
values[k] = v
Expand All @@ -68,23 +69,29 @@ func (c *RuntimeCache) buildDynamicLayer() []proto.Message {
for k, v := range c.dynamicRuntimeKV {
values[k] = v
}
return protobuf.AsMessages(envoy_v3.RuntimeLayers(values))
return envoy_v3.RuntimeLayers(values)
}

// Contents returns all Runtime layers (currently only the dynamic layer).
func (c *RuntimeCache) Contents() []proto.Message {
return c.buildDynamicLayer()
return protobuf.AsMessages(c.buildDynamicLayer())
}

func (c *RuntimeCache) ContentsByName() map[string]proto.Message {
panic("not implemented")
res := map[string]proto.Message{}

for _, c := range c.buildDynamicLayer() {
res[c.Name] = c
}

return res
}

// Query returns only the "dynamic" layer if requested, otherwise empty.
func (c *RuntimeCache) Query(names []string) []proto.Message {
for _, name := range names {
if name == envoy_v3.DynamicRuntimeLayerName {
return c.buildDynamicLayer()
return c.Contents()
}
}
return []proto.Message{}
Expand Down

0 comments on commit be82890

Please sign in to comment.