Skip to content

Commit 55f8c8c

Browse files
committed
Use strongly type IR when sending data to remote infra server
Signed-off-by: Zachary Nixon <nixozach@amazon.com>
1 parent 4d7bb2b commit 55f8c8c

15 files changed

Lines changed: 3724 additions & 361 deletions

File tree

examples/remote-infra/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ The provider implements the four RPCs defined in
2424
| `CreateOrUpdateRateLimitInfra` | No-op. Rate limiting must be provisioned out of band, see below |
2525
| `DeleteRateLimitInfra` | No-op |
2626

27-
The IR is delivered as JSON in the request's `ir_bytes` field. The example
28-
ignores fields it doesn't understand, which is the same forward-compatibility
29-
posture you'll want in your own provider.
27+
The IR is delivered as a structured `Infra` protobuf message in the request's
28+
`infra` field. The example maps only the subset of fields it understands onto
29+
its own pared-down types (see `synthesizer/ir.go`) and ignores the rest, which
30+
is the same forward-compatibility posture you'll want in your own provider.
3031

3132
## Layout
3233

examples/remote-infra/main.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package main
1313

1414
import (
1515
"context"
16-
"encoding/json"
1716
"errors"
1817
"flag"
1918
"fmt"
@@ -43,27 +42,64 @@ type basicServer struct {
4342
}
4443

4544
func (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

5652
func (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+
67103
func (bs *basicServer) CreateOrUpdateRateLimitInfra(_ context.Context, _ *pb.CreateOrUpdateRateLimitInfraRequest) (*pb.CreateOrUpdateRateLimitInfraResponse, error) {
68104
return new(pb.CreateOrUpdateRateLimitInfraResponse{}), nil
69105
}

0 commit comments

Comments
 (0)