Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move neg annotation to annotations package #62

Merged
merged 1 commit into from
Oct 31, 2017
Merged
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
14 changes: 14 additions & 0 deletions pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ const (
// This is read only for users. Controller will overrite any user updates.
// This is only set for ingresses with ingressClass = "gce-multi-cluster"
InstanceGroupsAnnotationKey = "ingress.gcp.kubernetes.io/instance-groups"

// NetworkEndpointGroupAlphaAnnotation is the annotation key to enable GCE NEG feature for ingress backend services.
// To enable this feature, the value of the annotation must be "true".
// This annotation should be specified on services that are backing ingresses.
// WARNING: The feature will NOT be effective in the following circumstances:
// 1. NEG feature is not enabled in feature gate.
// 2. Service is not referenced in any ingress.
// 3. Adding this annotation on ingress.
NetworkEndpointGroupAlphaAnnotation = "alpha.cloud.google.com/load-balancer-neg"
)

// IngAnnotations represents ingress annotations.
Expand Down Expand Up @@ -135,3 +144,8 @@ func (svc SvcAnnotations) ApplicationProtocols() (map[string]utils.AppProtocol,

return portToProtos, err
}

func (svc SvcAnnotations) NEGEnabled() bool {
v, ok := svc[NetworkEndpointGroupAlphaAnnotation]
return ok && v == "true"
}
2 changes: 1 addition & 1 deletion pkg/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ PortLoop:
SvcName: types.NamespacedName{Namespace: namespace, Name: be.ServiceName},
SvcPort: be.ServicePort,
SvcTargetPort: port.TargetPort.String(),
NEGEnabled: t.negEnabled && utils.NEGEnabled(svc.Annotations),
NEGEnabled: t.negEnabled && annotations.SvcAnnotations(svc.GetAnnotations()).NEGEnabled(),
}
return p, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkendpointgroup/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package networkendpointgroup

import (
"fmt"
"reflect"
"strconv"
"time"

"github.com/golang/glog"
Expand All @@ -31,10 +33,8 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"k8s.io/ingress-gce/pkg/annotations"
"k8s.io/ingress-gce/pkg/context"
"k8s.io/ingress-gce/pkg/utils"
"reflect"
"strconv"
)

const (
Expand Down Expand Up @@ -200,7 +200,7 @@ func (c *Controller) processService(key string) error {
var enabled bool
if exists {
service = svc.(*apiv1.Service)
enabled = utils.NEGEnabled(service.Annotations)
enabled = annotations.SvcAnnotations(service.GetAnnotations()).NEGEnabled()
}

if !enabled {
Expand Down
7 changes: 4 additions & 3 deletions pkg/networkendpointgroup/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/ingress-gce/pkg/annotations"
"k8s.io/ingress-gce/pkg/context"
"k8s.io/ingress-gce/pkg/utils"

Expand Down Expand Up @@ -265,15 +266,15 @@ func newTestIngress() *extensions.Ingress {
}

func newTestService(negEnabled bool) *apiv1.Service {
annotations := map[string]string{}
svcAnnotations := map[string]string{}
if negEnabled {
annotations[utils.NetworkEndpointGroupAlphaAnnotation] = "true"
svcAnnotations[annotations.NetworkEndpointGroupAlphaAnnotation] = "true"
}
return &apiv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: ServiceName,
Namespace: ServiceNamespace,
Annotations: annotations,
Annotations: svcAnnotations,
},
Spec: apiv1.ServiceSpec{
Ports: []apiv1.ServicePort{
Expand Down
8 changes: 0 additions & 8 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ const (
// 63 - 5 (k8s and naming schema version prefix) - 16 (cluster id) - 8 (suffix hash) - 4 (hyphen connector) = 30
maxNEGDescriptiveLabel = 30

// NetworkEndpointGroupAlphaAnnotation is the annotation to enable GCE NEG feature for ingress backend services
NetworkEndpointGroupAlphaAnnotation = "alpha.cloud.google.com/load-balancer-neg"

// schemaVersionV1 is the version 1 naming scheme for NEG
schemaVersionV1 = "1"
)
Expand Down Expand Up @@ -403,11 +400,6 @@ func GetNamedPort(port int64) *compute.NamedPort {
return &compute.NamedPort{Name: fmt.Sprintf("port%v", port), Port: port}
}

func NEGEnabled(annotations map[string]string) bool {
v, ok := annotations[NetworkEndpointGroupAlphaAnnotation]
return ok && v == "true"
}

// trimFieldsEvenly trims the fields evenly and keeps the total length
func trimFieldsEvenly(max int, fields ...string) []string {
if max <= 0 {
Expand Down