Skip to content

Commit 97196f4

Browse files
authored
added ability to set annotations on services, and made the default traffic policy to local. (#1406)
1 parent 10f1365 commit 97196f4

File tree

7 files changed

+230
-172
lines changed

7 files changed

+230
-172
lines changed

internal/frontend/cuefrontend/node.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,42 @@ func parseCueNode(ctx context.Context, env *schema.Environment, pl parsing.Early
277277
if err != nil {
278278
return err
279279
}
280+
280281
node.Ingress = schema.Endpoint_Type(schema.Endpoint_Type_value[v])
281282
}
282283

284+
if serviceMetadata := v.LookupPath("annotations"); serviceMetadata.Exists() {
285+
var m map[string]string
286+
if err := serviceMetadata.Val.Decode(&m); err != nil {
287+
return err
288+
}
289+
290+
annotations := &schema.ServiceAnnotations{}
291+
for key, value := range m {
292+
annotations.KeyValue = append(annotations.KeyValue, &schema.ServiceAnnotations_KeyValue{
293+
Key: key,
294+
Value: value,
295+
})
296+
}
297+
298+
slices.SortFunc(annotations.KeyValue, func(a, b *schema.ServiceAnnotations_KeyValue) int {
299+
if a.Key == b.Key {
300+
return strings.Compare(a.Value, b.Value)
301+
}
302+
303+
return strings.Compare(a.Key, b.Key)
304+
})
305+
306+
pb, err := anypb.New(annotations)
307+
if err != nil {
308+
return err
309+
}
310+
311+
node.ServiceMetadata = append(node.ServiceMetadata, &schema.ServiceMetadata{
312+
Details: pb,
313+
})
314+
}
315+
283316
if e := v.LookupPath("exportServicesAsHttp"); e.Exists() {
284317
_, err := e.Val.Bool()
285318
if err != nil {

internal/planning/endpoints.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func ComputeEndpoints(planner runtime.Planner, srv Server, merged *schema.Server
6666
}
6767
}
6868

69-
nd, err := computeServiceEndpoint(planner, sch.Server, lst, pkg, service, service.GetIngress())
69+
nd, err := computeServiceEndpoint(planner, sch.Server, lst, service)
7070
if err != nil {
7171
return nil, nil, err
7272
}
@@ -148,7 +148,7 @@ func findPort(serverPorts []*schema.Endpoint_Port, name string) *schema.Endpoint
148148
}
149149

150150
// XXX this should be somewhere else.
151-
func computeServiceEndpoint(planner runtime.Planner, server *schema.Server, listener *schema.Listener, pkg *pkggraph.Package, n *schema.Node, t schema.Endpoint_Type) ([]*schema.Endpoint, error) {
151+
func computeServiceEndpoint(planner runtime.Planner, server *schema.Server, listener *schema.Listener, n *schema.Node) ([]*schema.Endpoint, error) {
152152
var endpoints []*schema.Endpoint
153153

154154
exportedPort := n.ExportedPort
@@ -162,15 +162,18 @@ func computeServiceEndpoint(planner runtime.Planner, server *schema.Server, list
162162
name := n.GetIngressServiceName() + "-" + server.Id
163163
short, fqdn := planner.MakeServiceName(name)
164164

165-
endpoints = append(endpoints, &schema.Endpoint{
165+
endpoint := &schema.Endpoint{
166166
ServiceName: name,
167167
AllocatedName: short,
168168
FullyQualifiedName: fqdn,
169169
EndpointOwner: n.GetPackageName(),
170170
ServerOwner: server.GetPackageName(),
171-
Type: t,
171+
Type: n.GetIngress(),
172+
ServiceMetadata: n.GetServiceMetadata(),
172173
Ports: []*schema.Endpoint_PortMap{{ExportedPort: exportedPort, Port: listener.Port}},
173-
})
174+
}
175+
176+
endpoints = append(endpoints, endpoint)
174177
}
175178
} else {
176179
for k, exported := range n.ExportService {
@@ -188,7 +191,8 @@ func computeServiceEndpoint(planner runtime.Planner, server *schema.Server, list
188191
FullyQualifiedName: fqdn,
189192
EndpointOwner: n.GetPackageName(),
190193
ServerOwner: server.GetPackageName(),
191-
Type: t,
194+
Type: n.GetIngress(),
195+
ServiceMetadata: n.GetServiceMetadata(),
192196
Ports: []*schema.Endpoint_PortMap{{ExportedPort: exportedPort, Port: listener.Port}},
193197
}
194198

internal/runtime/kubernetes/deployment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,9 @@ func deployEndpoint(ctx context.Context, r BoundNamespace, deployable runtime.De
11981198
serviceSpec = serviceSpec.WithPorts(applied...)
11991199

12001200
if endpoint.Type == schema.Endpoint_LOAD_BALANCER {
1201-
serviceSpec = serviceSpec.WithType(corev1.ServiceTypeLoadBalancer)
1201+
// Default to LOCAL.
1202+
serviceSpec = serviceSpec.WithType(corev1.ServiceTypeLoadBalancer).
1203+
WithExternalTrafficPolicy(corev1.ServiceExternalTrafficPolicyLocal)
12021204
}
12031205

12041206
if endpoint.Headless {

internal/versions/versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"api_version": 145,
2+
"api_version": 146,
33
"minimum_api_version": 40,
44
"cache_version": 1
5-
}
5+
}

0 commit comments

Comments
 (0)