@@ -13,7 +13,6 @@ package main
1313
1414import (
1515 "context"
16- "encoding/json"
1716 "errors"
1817 "flag"
1918 "fmt"
@@ -43,27 +42,64 @@ type basicServer struct {
4342}
4443
4544func (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- }
45+ ir := infraFromProto (req .GetInfra ())
5046
5147 fmt .Printf ("Creating proxy infra [%v]\n " , ir )
5248 err := bs .synth .CreateOrUpdate (ctx , ir )
5349 return new (pb.CreateOrUpdateProxyInfraResponse {}), err
5450}
5551
5652func (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- }
53+ ir := infraFromProto (req .GetInfra ())
6154
6255 fmt .Printf ("Deleting proxy infra [%v]\n " , ir )
6356 err := bs .synth .Delete (ctx , ir )
6457 return new (pb.DeleteProxyInfraResponse {}), err
6558}
6659
60+ // infraFromProto maps the structured proto IR onto the pared-down
61+ // synthesizer.Infra used by this example. Fields the synthesizer does not
62+ // consume (proxy config, addresses, resolved metric sinks, and the owner
63+ // reference within metadata) are intentionally dropped, demonstrating the
64+ // forward-compatible posture a provider should adopt: read only what you
65+ // understand.
66+ func infraFromProto (in * pb.Infra ) * synthesizer.Infra {
67+ if in == nil || in .GetProxy () == nil {
68+ return new (synthesizer.Infra {})
69+ }
70+
71+ p := in .GetProxy ()
72+ proxy := & synthesizer.ProxyInfra {
73+ Name : p .GetName (),
74+ Namespace : p .GetNamespace (),
75+ }
76+
77+ if md := p .GetMetadata (); md != nil {
78+ proxy .Metadata = & synthesizer.InfraMetadata {
79+ Annotations : md .GetAnnotations (),
80+ Labels : md .GetLabels (),
81+ }
82+ }
83+
84+ for _ , l := range p .GetListeners () {
85+ if l == nil {
86+ continue
87+ }
88+ listener := & synthesizer.ProxyListener {Name : l .GetName ()}
89+ for _ , port := range l .GetPorts () {
90+ listener .Ports = append (listener .Ports , synthesizer.ListenerPort {
91+ Name : port .GetName (),
92+ Protocol : port .GetProtocol (),
93+ ServicePort : port .GetServicePort (),
94+ ContainerPort : port .GetContainerPort (),
95+ })
96+ }
97+ proxy .Listeners = append (proxy .Listeners , listener )
98+ }
99+
100+ return & synthesizer.Infra {Proxy : proxy }
101+ }
102+
67103func (bs * basicServer ) CreateOrUpdateRateLimitInfra (_ context.Context , _ * pb.CreateOrUpdateRateLimitInfraRequest ) (* pb.CreateOrUpdateRateLimitInfraResponse , error ) {
68104 return new (pb.CreateOrUpdateRateLimitInfraResponse {}), nil
69105}
0 commit comments