@@ -13,7 +13,6 @@ package main
1313
1414import (
1515 "context"
16- "encoding/json"
1716 "errors"
1817 "flag"
1918 "fmt"
@@ -22,11 +21,12 @@ import (
2221 "os"
2322 "path/filepath"
2423
25- "github.com/envoyproxy/gateway-remote-infra/pb"
26- "github.com/envoyproxy/gateway-remote-infra/synthesizer"
2724 "google.golang.org/grpc"
2825 "sigs.k8s.io/controller-runtime/pkg/client"
2926 clicfg "sigs.k8s.io/controller-runtime/pkg/client/config"
27+
28+ "github.com/envoyproxy/gateway-remote-infra/pb"
29+ "github.com/envoyproxy/gateway-remote-infra/synthesizer"
3030)
3131
3232var (
@@ -43,27 +43,64 @@ type basicServer struct {
4343}
4444
4545func (bs * basicServer ) CreateOrUpdateProxyInfra (ctx context.Context , req * pb.CreateOrUpdateProxyInfraRequest ) (* pb.CreateOrUpdateProxyInfraResponse , error ) {
46- ir := new (synthesizer.Infra {})
47- if err := json .Unmarshal (req .GetIrBytes (), ir ); err != nil {
48- return nil , fmt .Errorf ("failed to unmarshal IR: %w" , err )
49- }
46+ ir := infraFromProto (req .GetInfra ())
5047
5148 fmt .Printf ("Creating proxy infra [%v]\n " , ir )
5249 err := bs .synth .CreateOrUpdate (ctx , ir )
5350 return new (pb.CreateOrUpdateProxyInfraResponse {}), err
5451}
5552
5653func (bs * basicServer ) DeleteProxyInfra (ctx context.Context , req * pb.DeleteProxyInfraRequest ) (* pb.DeleteProxyInfraResponse , error ) {
57- ir := new (synthesizer.Infra {})
58- if err := json .Unmarshal (req .GetIrBytes (), ir ); err != nil {
59- return nil , fmt .Errorf ("failed to unmarshal IR: %w" , err )
60- }
54+ ir := infraFromProto (req .GetInfra ())
6155
6256 fmt .Printf ("Deleting proxy infra [%v]\n " , ir )
6357 err := bs .synth .Delete (ctx , ir )
6458 return new (pb.DeleteProxyInfraResponse {}), err
6559}
6660
61+ // infraFromProto maps the structured proto IR onto the pared-down
62+ // synthesizer.Infra used by this example. Fields the synthesizer does not
63+ // consume (proxy config, addresses, resolved metric sinks, and the owner
64+ // reference within metadata) are intentionally dropped, demonstrating the
65+ // forward-compatible posture a provider should adopt: read only what you
66+ // understand.
67+ func infraFromProto (in * pb.Infra ) * synthesizer.Infra {
68+ if in == nil || in .GetProxy () == nil {
69+ return new (synthesizer.Infra {})
70+ }
71+
72+ p := in .GetProxy ()
73+ proxy := & synthesizer.ProxyInfra {
74+ Name : p .GetName (),
75+ Namespace : p .GetNamespace (),
76+ }
77+
78+ if md := p .GetMetadata (); md != nil {
79+ proxy .Metadata = & synthesizer.InfraMetadata {
80+ Annotations : md .GetAnnotations (),
81+ Labels : md .GetLabels (),
82+ }
83+ }
84+
85+ for _ , l := range p .GetListeners () {
86+ if l == nil {
87+ continue
88+ }
89+ listener := & synthesizer.ProxyListener {Name : l .GetName ()}
90+ for _ , port := range l .GetPorts () {
91+ listener .Ports = append (listener .Ports , synthesizer.ListenerPort {
92+ Name : port .GetName (),
93+ Protocol : port .GetProtocol (),
94+ ServicePort : port .GetServicePort (),
95+ ContainerPort : port .GetContainerPort (),
96+ })
97+ }
98+ proxy .Listeners = append (proxy .Listeners , listener )
99+ }
100+
101+ return & synthesizer.Infra {Proxy : proxy }
102+ }
103+
67104func (bs * basicServer ) CreateOrUpdateRateLimitInfra (_ context.Context , _ * pb.CreateOrUpdateRateLimitInfraRequest ) (* pb.CreateOrUpdateRateLimitInfraResponse , error ) {
68105 return new (pb.CreateOrUpdateRateLimitInfraResponse {}), nil
69106}
0 commit comments