Skip to content

Commit

Permalink
networking: add support to wire exported http paths with grpc.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugosantos committed Oct 18, 2023
1 parent 959eb5b commit 4a6ddc5
Show file tree
Hide file tree
Showing 11 changed files with 525 additions and 385 deletions.
20 changes: 16 additions & 4 deletions internal/frontend/cuefrontend/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ type cueExportMethods struct {
}

type cueHttpPath struct {
Path string `json:"path"`
Kind string `json:"kind"`
Path string `json:"path"`
Kind string `json:"kind"`
Protocol string `json:"protocol"`
}

type cueServerRef struct {
Expand Down Expand Up @@ -316,10 +317,21 @@ func parseCueNode(ctx context.Context, env *schema.Environment, pl parsing.Early
}

for _, p := range paths {
node.ExportHttp = append(node.ExportHttp, &schema.HttpPath{
path := &schema.HttpPath{
Path: p.Path,
Kind: p.Kind,
})
}

if p.Protocol != "" {
v, ok := schema.IngressFragment_IngressHttpPath_BackendProtocol_value[strings.ToUpper(p.Protocol)]
if !ok {
return fnerrors.NewWithLocation(loc, "unrecognized protocol %q", p.Protocol)
}

path.BackendProtocol = schema.IngressFragment_IngressHttpPath_BackendProtocol(v)
}

node.ExportHttp = append(node.ExportHttp, path)
}
}

Expand Down
9 changes: 5 additions & 4 deletions internal/integrations/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,11 @@ func (impl) PostParseServer(ctx context.Context, sealed *parsing.Sealed) error {
// XXX this should be done upstream.
for _, p := range svc.ExportHttp {
sealed.Result.Server.UrlMap = append(sealed.Result.Server.UrlMap, &schema.Server_URLMapEntry{
PathPrefix: p.Path,
IngressName: svc.IngressServiceName,
Kind: p.Kind,
PackageName: svc.PackageName,
PathPrefix: p.Path,
IngressName: svc.IngressServiceName,
Kind: p.Kind,
PackageName: svc.PackageName,
BackendProtocol: p.BackendProtocol,
})
}
}
Expand Down
14 changes: 11 additions & 3 deletions internal/networking/ingress/define_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func groupByName(ngs []*schema.IngressFragment) []IngressGroup {
}

func generateForSrv(ctx context.Context, ingress kubedef.IngressClass, env *schema.Environment, srv *schema.Stack_Entry, ns string, g IngressGroup) ([]defs.MakeDefinition, error) {
var clearTextGrpcCount, grpcCount, nonGrpcCount int
var clearTextGrpcCount, grpcCount, httpCount int

labels := kubedef.MakeLabels(env, srv.Server)

Expand All @@ -102,7 +102,15 @@ func generateForSrv(ctx context.Context, ingress kubedef.IngressClass, env *sche

var paths []*applynetworkingv1.HTTPIngressPathApplyConfiguration
for _, p := range ng.HttpPath {
nonGrpcCount++
if p.BackendProtocol == schema.IngressFragment_IngressHttpPath_HTTP || p.BackendProtocol == schema.IngressFragment_IngressHttpPath_BACKEND_PROTOCOL_UNKNOWN {
httpCount++
} else if p.BackendProtocol == schema.IngressFragment_IngressHttpPath_GRPC {
clearTextGrpcCount++
} else if p.BackendProtocol == schema.IngressFragment_IngressHttpPath_GRPCS {
grpcCount++
} else {
return nil, fnerrors.InternalError("unrecognized backend protocol %v", p.BackendProtocol)
}

if p.ServicePort == 0 {
return nil, fnerrors.InternalError("%s: ingress definition without port", filepath.Join(p.Path, p.Service))
Expand Down Expand Up @@ -182,7 +190,7 @@ func generateForSrv(ctx context.Context, ingress kubedef.IngressClass, env *sche
}
}

if grpcCount > 0 && nonGrpcCount > 0 {
if (grpcCount > 0 || clearTextGrpcCount > 0) && httpCount > 0 {
return nil, fnerrors.InternalError("can't mix grpc and non-grpc backends in the same ingress")
}

Expand Down
11 changes: 6 additions & 5 deletions internal/runtime/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ func ComputeIngress(ctx context.Context, env cfg.Context, planner Planner, sch *
}

paths = append(paths, &schema.IngressFragment_IngressHttpPath{
Path: u.PathPrefix,
Kind: u.Kind,
Owner: owner,
Service: httpEndpoint.AllocatedName,
ServicePort: httpEndpoint.Ports[0].ExportedPort,
Path: u.PathPrefix,
Kind: u.Kind,
Owner: owner,
Service: httpEndpoint.AllocatedName,
ServicePort: httpEndpoint.Ports[0].ExportedPort,
BackendProtocol: u.BackendProtocol,
})
}

Expand Down
2 changes: 1 addition & 1 deletion internal/versions/versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"api_version": 94,
"api_version": 95,
"minimum_api_version": 40,
"cache_version": 1
}
338 changes: 206 additions & 132 deletions schema/networking.pb.go

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions schema/networking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,20 @@ message IngressFragment {
repeated google.protobuf.Any extension = 5;

message IngressHttpPath {
string path = 1;
string kind = 2;
string owner = 3; // Package name.
string service = 4; // Backend service.
int32 service_port = 6;
string path = 1;
string kind = 2;
string owner = 3; // Package name.
string service = 4; // Backend service.
int32 service_port = 6;
BackendProtocol backend_protocol = 7;
reserved 5;

enum BackendProtocol {
BACKEND_PROTOCOL_UNKNOWN = 0;
HTTP = 1;
GRPC = 2;
GRPCS = 3;
}
}

message IngressGrpcService {
Expand Down
55 changes: 36 additions & 19 deletions schema/node.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions schema/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ message NodeInitializer {
}

message HttpPath {
string path = 1;
string kind = 2;
string path = 1;
string kind = 2;
IngressFragment.IngressHttpPath.BackendProtocol backend_protocol = 3;
}

// XXX needs are at odds with instanced nodes; both provide means for the node to
Expand Down
Loading

0 comments on commit 4a6ddc5

Please sign in to comment.