Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/annotations/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const (
ProtocolHTTPS AppProtocol = "HTTPS"
// ProtocolHTTP2 protocol for a service
ProtocolHTTP2 AppProtocol = "HTTP2"
// ProtocolGRPC protocol for a service
ProtocolGRPC AppProtocol = "GRPC"
// ProtocolGRPCWithTLS protocol for a service
ProtocolGRPCWithTLS AppProtocol = "GRPC_WITH_TLS"
)

// THCAnnotation is the format of the annotation associated with the THCAnnotationKey key.
Expand Down Expand Up @@ -96,8 +100,8 @@ func (svc *Service) ApplicationProtocols() (map[string]AppProtocol, error) {
// Verify protocol is an accepted value
for _, proto := range portToProtos {
switch proto {
case ProtocolHTTP, ProtocolHTTPS:
case ProtocolHTTP2:
case ProtocolHTTP, ProtocolHTTPS, ProtocolHTTP2, ProtocolGRPC, ProtocolGRPCWithTLS:
// accepted
default:
return nil, fmt.Errorf("invalid port application protocol: %v", proto)
}
Expand Down
41 changes: 39 additions & 2 deletions pkg/translator/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ func NewHealthCheck(hc *computealpha.HealthCheck) (*HealthCheck, error) {
return nil, fmt.Errorf(newHealthCheckErrorMessageTemplate, annotations.ProtocolHTTP2, hc.Name)
}
v.HTTPHealthCheck = computealpha.HTTPHealthCheck(*hc.Http2HealthCheck)
case annotations.ProtocolGRPC:
if hc.GrpcHealthCheck == nil {
return nil, fmt.Errorf(newHealthCheckErrorMessageTemplate, annotations.ProtocolGRPC, hc.Name)
}
// Store common fields at outer level for merging later
v.HTTPHealthCheck = computealpha.HTTPHealthCheck{
Port: hc.GrpcHealthCheck.Port,
PortSpecification: hc.GrpcHealthCheck.PortSpecification,
}
case annotations.ProtocolGRPCWithTLS:
if hc.GrpcTlsHealthCheck == nil {
return nil, fmt.Errorf(newHealthCheckErrorMessageTemplate, annotations.ProtocolGRPCWithTLS, hc.Name)
}
v.HTTPHealthCheck = computealpha.HTTPHealthCheck{
Port: hc.GrpcTlsHealthCheck.Port,
PortSpecification: hc.GrpcTlsHealthCheck.PortSpecification,
}
}

// Users should be modifying HTTP(S) specific settings on the embedded
Expand Down Expand Up @@ -196,6 +213,8 @@ func (hc *HealthCheck) merge() error {
hc.HealthCheck.Http2HealthCheck = nil
hc.HealthCheck.HttpsHealthCheck = nil
hc.HealthCheck.HttpHealthCheck = nil
hc.HealthCheck.GrpcHealthCheck = nil
hc.HealthCheck.GrpcTlsHealthCheck = nil

switch hc.Protocol() {
case annotations.ProtocolHTTP:
Expand All @@ -207,9 +226,21 @@ func (hc *HealthCheck) merge() error {
case annotations.ProtocolHTTP2:
http2 := computealpha.HTTP2HealthCheck(hc.HTTPHealthCheck)
hc.HealthCheck.Http2HealthCheck = &http2
case annotations.ProtocolGRPC:
grpc := computealpha.GRPCHealthCheck{
Port: hc.HTTPHealthCheck.Port,
PortSpecification: hc.HTTPHealthCheck.PortSpecification,
}
hc.HealthCheck.GrpcHealthCheck = &grpc
case annotations.ProtocolGRPCWithTLS:
grpcTLS := computealpha.GRPCTLSHealthCheck{
Port: hc.HTTPHealthCheck.Port,
PortSpecification: hc.HTTPHealthCheck.PortSpecification,
}
hc.HealthCheck.GrpcTlsHealthCheck = &grpcTLS
default:
return fmt.Errorf("Protocol %q is not valid, must be one of [%q,%q,%q]",
hc.Protocol(), annotations.ProtocolHTTP, annotations.ProtocolHTTPS, annotations.ProtocolHTTP2,
return fmt.Errorf("Protocol %q is not valid, must be one of [%q,%q,%q,%q,%q]",
hc.Protocol(), annotations.ProtocolHTTP, annotations.ProtocolHTTPS, annotations.ProtocolHTTP2, annotations.ProtocolGRPC, annotations.ProtocolGRPCWithTLS,
)
}
return nil
Expand All @@ -221,9 +252,15 @@ func (hc *HealthCheck) Version() meta.Version {
if hc.ForILB {
return features.L7ILBVersions().HealthCheck
}
// GRPC_WITH_TLS requires Alpha API.
if hc.Protocol() == annotations.ProtocolGRPCWithTLS {
return meta.VersionAlpha
}
// Use Beta for HTTP2 or NEG as before.
if hc.Protocol() == annotations.ProtocolHTTP2 || hc.ForNEG {
return meta.VersionBeta
}
// GRPC is available in GA; fall back to GA otherwise.
return meta.VersionGA
}

Expand Down