Skip to content

Commit

Permalink
Introduce cloud.google.com/app-protocols to replace existing annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
rramkumar1 committed Aug 13, 2018
1 parent a2b5225 commit 8dc8fda
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/annotations/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ import (
)

const (
// ServiceApplicationProtocolKey is a stringified JSON map of port names to
// protocol strings. Possible values are HTTP, HTTPS
// ServiceApplicationProtocolKey and GoogleServiceApplicationProtocolKey
// is a stringified JSON map of port names to protocol strings.
// Possible values are HTTP, HTTPS and HTTP2.
// Example:
// '{"my-https-port":"HTTPS","my-http-port":"HTTP"}'
ServiceApplicationProtocolKey = "service.alpha.kubernetes.io/app-protocols"
// Note: ServiceApplicationProtocolKey will be deprecated.
ServiceApplicationProtocolKey = "service.alpha.kubernetes.io/app-protocols"
GoogleServiceApplicationProtocolKey = "cloud.google.com/app-protocols"

// NEGAnnotationKey is the annotation key to enable GCE NEG.
// The value of the annotation must be a valid JSON string in the format
Expand Down Expand Up @@ -105,9 +108,15 @@ func FromService(obj *v1.Service) *Service {
// ApplicationProtocols returns a map of port (name or number) to the protocol
// on the port.
func (svc *Service) ApplicationProtocols() (map[string]AppProtocol, error) {
val, ok := svc.v[ServiceApplicationProtocolKey]
var val string
var ok bool
// First check the old annotation, then fall back to the new one.
val, ok = svc.v[ServiceApplicationProtocolKey]
if !ok {
return map[string]AppProtocol{}, nil
val, ok = svc.v[GoogleServiceApplicationProtocolKey]
if !ok {
return map[string]AppProtocol{}, nil
}
}

var portToProtos map[string]AppProtocol
Expand Down
21 changes: 21 additions & 0 deletions pkg/annotations/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,27 @@ func TestService(t *testing.T) {
svc: &v1.Service{},
appProtocols: map[string]AppProtocol{},
},
{
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
GoogleServiceApplicationProtocolKey: `{"80": "HTTP", "443": "HTTPS"}`,
},
},
},
appProtocols: map[string]AppProtocol{"80": "HTTP", "443": "HTTPS"},
},
{
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
GoogleServiceApplicationProtocolKey: `{"80": "HTTP", "443": "HTTPS"}`,
ServiceApplicationProtocolKey: `{"81": "HTTP", "444": "HTTPS"}`,
},
},
},
appProtocols: map[string]AppProtocol{"81": "HTTP", "444": "HTTPS"},
},
{
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 8dc8fda

Please sign in to comment.