Skip to content

Commit

Permalink
Remove legacy annotation support (#3155)
Browse files Browse the repository at this point in the history
This commit removes all trace of the `contour.heptio.com` annotations,
and updates a few `heptio` references I found as well.

This support has been deprecated since Contour v1.8.0 in September.

Closes #2495.

Signed-off-by: Nick Young <ynick@vmware.com>

Co-authored-by: Steve Sloka <slokas@vmware.com>
  • Loading branch information
Nick Young and stevesloka authored Nov 30, 2020
1 parent ed58b12 commit 58359eb
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 836 deletions.
75 changes: 23 additions & 52 deletions internal/annotation/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const DEFAULT_INGRESS_CLASS = "contour"
// IsKnown checks if an annotation is one Contour knows about.
func IsKnown(key string) bool {
// We should know about everything with a Contour prefix.
if strings.HasPrefix(key, "projectcontour.io/") ||
strings.HasPrefix(key, "contour.heptio.com/") {
if strings.HasPrefix(key, "projectcontour.io/") {
return true
}

Expand Down Expand Up @@ -80,33 +79,25 @@ var annotationsByKind = map[string]map[string]struct{}{
// ValidForKind checks if a particular annotation is valid for a given Kind.
func ValidForKind(kind string, key string) bool {
if a, ok := annotationsByKind[kind]; ok {
// Canonicalize the name while we still have legacy support.
key = strings.Replace(key, "contour.heptio.com/", "projectcontour.io/", -1)
_, ok := a[key]
return ok
}

// We should know about every kind with a Contour annotation prefix.
if strings.HasPrefix(key, "projectcontour.io/") ||
strings.HasPrefix(key, "contour.heptio.com/") {
if strings.HasPrefix(key, "projectcontour.io/") {
return false
}

// This isn't a kind we know about so assume it is valid.
return true
}

// CompatAnnotation checks the Object for the given annotation, first with the
// "projectcontour.io/" prefix, and then with the "contour.heptio.com/" prefix
// if that is not found.
func CompatAnnotation(o metav1.ObjectMetaAccessor, key string) string {
// ContourAnnotation checks the Object for the given annotation with the
// "projectcontour.io/" prefix.
func ContourAnnotation(o metav1.ObjectMetaAccessor, key string) string {
a := o.GetObjectMeta().GetAnnotations()

if val, ok := a["projectcontour.io/"+key]; ok {
return val
}

return a["contour.heptio.com/"+key]
return a["projectcontour.io/"+key]
}

// ParseUInt32 parses the supplied string as if it were a uint32.
Expand All @@ -119,24 +110,18 @@ func parseUInt32(s string) uint32 {
return uint32(v)
}

// ParseUpstreamProtocols parses the annotations map for contour.heptio.com/upstream-protocol.{protocol}
// and projectcontour.io/upstream-protocol.{protocol} annotations.
// ParseUpstreamProtocols parses the annotations map for
// projectcontour.io/upstream-protocol.{protocol} annotations.
// 'protocol' identifies which protocol must be used in the upstream.
func ParseUpstreamProtocols(m map[string]string) map[string]string {
annotations := []string{
"contour.heptio.com/upstream-protocol",
"projectcontour.io/upstream-protocol",
}
protocols := []string{"h2", "h2c", "tls"}
up := make(map[string]string)
for _, annotation := range annotations {
for _, protocol := range protocols {
ports := m[fmt.Sprintf("%s.%s", annotation, protocol)]
for _, v := range strings.Split(ports, ",") {
port := strings.TrimSpace(v)
if port != "" {
up[port] = protocol
}
for _, protocol := range protocols {
ports := m[fmt.Sprintf("projectcontour.io/upstream-protocol.%s", protocol)]
for _, v := range strings.Split(ports, ",") {
port := strings.TrimSpace(v)
if port != "" {
up[port] = protocol
}
}
}
Expand Down Expand Up @@ -165,39 +150,29 @@ func WebsocketRoutes(i *v1beta1.Ingress) map[string]bool {
routes[route] = true
}
}
for _, v := range strings.Split(i.Annotations["contour.heptio.com/websocket-routes"], ",") {
route := strings.TrimSpace(v)
if route != "" {
routes[route] = true
}
}
return routes
}

// NumRetries returns the number of retries specified by the "contour.heptio.com/num-retries"
// or "projectcontour.io/num-retries" annotation.
// NumRetries returns the number of retries specified by the
// "projectcontour.io/num-retries" annotation.
func NumRetries(i *v1beta1.Ingress) uint32 {
return parseUInt32(CompatAnnotation(i, "num-retries"))
return parseUInt32(ContourAnnotation(i, "num-retries"))
}

// PerTryTimeout returns the duration envoy will wait per retry cycle.
func PerTryTimeout(i *v1beta1.Ingress) (timeout.Setting, error) {
return timeout.Parse(CompatAnnotation(i, "per-try-timeout"))
return timeout.Parse(ContourAnnotation(i, "per-try-timeout"))
}

// IngressClass returns the first matching ingress class for the following
// annotations:
// 1. projectcontour.io/ingress.class
// 2. contour.heptio.com/ingress.class
// 3. kubernetes.io/ingress.class
// 2. kubernetes.io/ingress.class
func IngressClass(o metav1.ObjectMetaAccessor) string {
a := o.GetObjectMeta().GetAnnotations()
if class, ok := a["projectcontour.io/ingress.class"]; ok {
return class
}
if class, ok := a["contour.heptio.com/ingress.class"]; ok {
return class
}
if class, ok := a["kubernetes.io/ingress.class"]; ok {
return class
}
Expand Down Expand Up @@ -237,39 +212,35 @@ func MinTLSVersion(version string, defaultVal string) string {
// MaxConnections returns the value of the first matching max-connections
// annotation for the following annotations:
// 1. projectcontour.io/max-connections
// 2. contour.heptio.com/max-connections
//
// '0' is returned if the annotation is absent or unparsable.
func MaxConnections(o metav1.ObjectMetaAccessor) uint32 {
return parseUInt32(CompatAnnotation(o, "max-connections"))
return parseUInt32(ContourAnnotation(o, "max-connections"))
}

// MaxPendingRequests returns the value of the first matching max-pending-requests
// annotation for the following annotations:
// 1. projectcontour.io/max-pending-requests
// 2. contour.heptio.com/max-pending-requests
//
// '0' is returned if the annotation is absent or unparsable.
func MaxPendingRequests(o metav1.ObjectMetaAccessor) uint32 {
return parseUInt32(CompatAnnotation(o, "max-pending-requests"))
return parseUInt32(ContourAnnotation(o, "max-pending-requests"))
}

// MaxRequests returns the value of the first matching max-requests
// annotation for the following annotations:
// 1. projectcontour.io/max-requests
// 2. contour.heptio.com/max-requests
//
// '0' is returned if the annotation is absent or unparsable.
func MaxRequests(o metav1.ObjectMetaAccessor) uint32 {
return parseUInt32(CompatAnnotation(o, "max-requests"))
return parseUInt32(ContourAnnotation(o, "max-requests"))
}

// MaxRetries returns the value of the first matching max-retries
// annotation for the following annotations:
// 1. projectcontour.io/max-retries
// 2. contour.heptio.com/max-retries
//
// '0' is returned if the annotation is absent or unparsable.
func MaxRetries(o metav1.ObjectMetaAccessor) uint32 {
return parseUInt32(CompatAnnotation(o, "max-retries"))
return parseUInt32(ContourAnnotation(o, "max-retries"))
}
138 changes: 2 additions & 136 deletions internal/annotation/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,6 @@ func TestParseUpstreamProtocols(t *testing.T) {
"https": "h2",
},
},
"deprecated multiple values": {
a: map[string]string{
"contour.heptio.com/upstream-protocol.h2": "80,http,443,https",
"projectcontour.io/upstream-protocol.h2c": "8080,http",
"projectcontour.io/upstream-protocol.tls": "443,https",
},
want: map[string]string{
"80": "h2",
"8080": "h2c",
"http": "h2c",
"443": "tls",
"https": "tls",
},
},
}

for name, tc := range tests {
Expand Down Expand Up @@ -188,78 +174,6 @@ func TestWebsocketRoutes(t *testing.T) {
"/ws2": true,
},
},
"legacy empty": {
a: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/websocket-routes": "",
},
},
},
want: map[string]bool{},
},
"legacy empty with spaces": {
a: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/websocket-routes": ", ,",
},
},
},
want: map[string]bool{},
},
"legacy single value": {
a: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/websocket-routes": "/ws1",
},
},
},
want: map[string]bool{
"/ws1": true,
},
},
"legacy multiple values": {
a: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/websocket-routes": "/ws1,/ws2",
},
},
},
want: map[string]bool{
"/ws1": true,
"/ws2": true,
},
},
"legacy multiple values with spaces and invalid entries": {
a: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/websocket-routes": " /ws1, , /ws2 ",
},
},
},
want: map[string]bool{
"/ws1": true,
"/ws2": true,
},
},
"mixed": {
a: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/websocket-routes": " /ws1, ",
"projectcontour.io/websocket-routes": " , /ws2 ",
},
},
},
want: map[string]bool{
"/ws1": true,
"/ws2": true,
},
},
}

for name, tc := range tests {
Expand Down Expand Up @@ -336,16 +250,6 @@ func TestAnnotationCompat(t *testing.T) {
},
},
},
"contour.heptio.com/annotation": {
value: "100",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/annotation": "100",
},
},
},
},
"projectcontour.io/annotation": {
value: "200",
svc: &v1.Service{
Expand All @@ -356,22 +260,11 @@ func TestAnnotationCompat(t *testing.T) {
},
},
},
"projectcontour.io takes precedence": {
value: "200",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"contour.heptio.com/annotation": "100",
"projectcontour.io/annotation": "200",
},
},
},
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := CompatAnnotation(tc.svc, "annotation")
got := ContourAnnotation(tc.svc, "annotation")
want := tc.value
if got != want {
t.Fatalf("got: %v, want: %v", got, want)
Expand All @@ -392,12 +285,9 @@ func TestAnnotationKindValidation(t *testing.T) {
"service": {
obj: &v1.Service{},
annotations: map[string]status{
"foo.heptio.com/annotation": {
"foo.invalid.com/annotation": {
known: false, valid: false,
},
"contour.heptio.com/annotation": {
known: true, valid: false,
},
"projectcontour.io/annotation": {
known: true, valid: false,
},
Expand Down Expand Up @@ -482,18 +372,6 @@ func TestMatchIngressClass(t *testing.T) {
},
want: []bool{false, false},
},
"ingress nginx contour.heptio.com/ingress.class": {
fixture: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "incorrect",
Namespace: "default",
Annotations: map[string]string{
"contour.heptio.com/ingress.class": "nginx",
},
},
},
want: []bool{false, false},
},
"ingress nginx projectcontour.io/ingress.class": {
fixture: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -518,18 +396,6 @@ func TestMatchIngressClass(t *testing.T) {
},
want: []bool{true, true},
},
"ingress contour contour.heptio.com/ingress.class": {
fixture: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "incorrect",
Namespace: "default",
Annotations: map[string]string{
"contour.heptio.com/ingress.class": DEFAULT_INGRESS_CLASS,
},
},
},
want: []bool{true, true},
},
"ingress contour projectcontour.io/ingress.class": {
fixture: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Loading

0 comments on commit 58359eb

Please sign in to comment.