Skip to content

Commit e0326cd

Browse files
mathetakenacx
andauthored
controller: removes all panics from extension server (envoyproxy#1610)
**Description** This removes all panics from extension server code paths, mostly for making it resilient against any bad input from EG --------- Signed-off-by: Takeshi Yoneda <[email protected]> Co-authored-by: Ignasi Barrera <[email protected]>
1 parent 23779b7 commit e0326cd

File tree

9 files changed

+572
-217
lines changed

9 files changed

+572
-217
lines changed

internal/extensionserver/extensionserver.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ package extensionserver
77

88
import (
99
"context"
10+
"fmt"
1011

1112
egextension "github.com/envoyproxy/gateway/proto/extension"
1213
"github.com/go-logr/logr"
1314
"google.golang.org/grpc/codes"
1415
"google.golang.org/grpc/health/grpc_health_v1"
1516
"google.golang.org/grpc/status"
17+
"google.golang.org/protobuf/proto"
18+
"google.golang.org/protobuf/types/known/anypb"
1619
"sigs.k8s.io/controller-runtime/pkg/client"
1720
)
1821

@@ -51,3 +54,16 @@ func (s *Server) List(context.Context, *grpc_health_v1.HealthListRequest) (*grpc
5154
serverName: {Status: grpc_health_v1.HealthCheckResponse_SERVING},
5255
}}, nil
5356
}
57+
58+
// toAny marshals the provided message to an Any message.
59+
func toAny(msg proto.Message) (*anypb.Any, error) {
60+
b, err := proto.Marshal(msg)
61+
if err != nil {
62+
return nil, fmt.Errorf("failed to marshal message to Any: %w", err)
63+
}
64+
const envoyAPIPrefix = "type.googleapis.com/"
65+
return &anypb.Any{
66+
TypeUrl: envoyAPIPrefix + string(msg.ProtoReflect().Descriptor().FullName()),
67+
Value: b,
68+
}, nil
69+
}

0 commit comments

Comments
 (0)