From b88e9b150686f6b432ef7ef49454c624e69413f1 Mon Sep 17 00:00:00 2001 From: dprotaso Date: Wed, 17 Nov 2021 09:55:23 -0500 Subject: [PATCH] Use annotation helper functions We're going to introduce kebab-casing but we still want to support the old format. --- pkg/reconciler/domainmapping/reconciler.go | 4 ++-- pkg/reconciler/nscert/nscert.go | 2 +- .../route/reconcile_resources_test.go | 2 +- pkg/reconciler/route/resources/ingress.go | 18 +++++++++--------- pkg/reconciler/route/route.go | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/reconciler/domainmapping/reconciler.go b/pkg/reconciler/domainmapping/reconciler.go index 67d2971d6909..8708358e916e 100644 --- a/pkg/reconciler/domainmapping/reconciler.go +++ b/pkg/reconciler/domainmapping/reconciler.go @@ -99,7 +99,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, dm *v1alpha1.DomainMappi dm.Status.Address = &duckv1.Addressable{URL: url} // IngressClass can be set via annotations or in the config map. - ingressClass := dm.Annotations[networking.IngressClassAnnotationKey] + ingressClass := networking.GetIngressClass(dm.Annotations) if ingressClass == "" { ingressClass = config.FromContext(ctx).Network.DefaultIngressClass } @@ -181,7 +181,7 @@ func autoTLSEnabled(ctx context.Context, dm *v1alpha1.DomainMapping) bool { if !config.FromContext(ctx).Network.AutoTLS { return false } - annotationValue := dm.Annotations[networking.DisableAutoTLSAnnotationKey] + annotationValue := networking.GetDisableAutoTLS(dm.Annotations) disabledByAnnotation, err := strconv.ParseBool(annotationValue) if annotationValue != "" && err != nil { logger := logging.FromContext(ctx) diff --git a/pkg/reconciler/nscert/nscert.go b/pkg/reconciler/nscert/nscert.go index e1644deac0f6..6f4d13c7a120 100644 --- a/pkg/reconciler/nscert/nscert.go +++ b/pkg/reconciler/nscert/nscert.go @@ -56,7 +56,7 @@ var _ namespacereconciler.Interface = (*reconciler)(nil) var domainTemplateRegex = regexp.MustCompile(`^\*\..+$`) func certClass(ctx context.Context, r *corev1.Namespace) string { - if class := r.Annotations[networking.CertificateClassAnnotationKey]; class != "" { + if class := networking.GetCertificateClass(r.Annotations); class != "" { return class } return config.FromContext(ctx).Network.DefaultCertificateClass diff --git a/pkg/reconciler/route/reconcile_resources_test.go b/pkg/reconciler/route/reconcile_resources_test.go index 521df64ee800..7e8335bfbf95 100644 --- a/pkg/reconciler/route/reconcile_resources_test.go +++ b/pkg/reconciler/route/reconcile_resources_test.go @@ -608,7 +608,7 @@ func TestReconcileIngressClassAnnotation(t *testing.T) { } updated = getRouteIngressFromClient(ctx, t, r) - updatedClass := updated.Annotations[networking.IngressClassAnnotationKey] + updatedClass := networking.GetIngressClass(updated.Annotations) if expClass != updatedClass { t.Errorf("Unexpected annotation got %q want %q", expClass, updatedClass) } diff --git a/pkg/reconciler/route/resources/ingress.go b/pkg/reconciler/route/resources/ingress.go index e081b3f6976f..a17f56a4100b 100644 --- a/pkg/reconciler/route/resources/ingress.go +++ b/pkg/reconciler/route/resources/ingress.go @@ -195,7 +195,7 @@ func makeIngressSpec( } } - httpOption, err := getHTTPOption(ctx, r.Annotations) + httpProtocol, err := getHTTPProtocol(ctx, r.Annotations) if err != nil { return netv1alpha1.IngressSpec{}, err } @@ -203,20 +203,20 @@ func makeIngressSpec( return netv1alpha1.IngressSpec{ Rules: rules, TLS: tls, - HTTPOption: httpOption, + HTTPOption: httpProtocol, }, nil } -func getHTTPOption(ctx context.Context, annotations map[string]string) (netv1alpha1.HTTPOption, error) { - if len(annotations) != 0 && annotations[networking.HTTPOptionAnnotationKey] != "" { - annotation := annotations[networking.HTTPOptionAnnotationKey] - switch strings.ToLower(annotation) { - case "enabled": +func getHTTPProtocol(ctx context.Context, annotations map[string]string) (netv1alpha1.HTTPOption, error) { + if len(annotations) != 0 && networking.GetHTTPProtocol(annotations) != "" { + protocol := strings.ToLower(networking.GetHTTPProtocol(annotations)) + switch network.HTTPProtocol(protocol) { + case network.HTTPEnabled: return netv1alpha1.HTTPOptionEnabled, nil - case "redirected": + case network.HTTPRedirected: return netv1alpha1.HTTPOptionRedirected, nil default: - return "", fmt.Errorf("incorrect HTTPOption annotation:" + annotation) + return "", fmt.Errorf("incorrect http-protocol annotation:" + protocol) } } diff --git a/pkg/reconciler/route/route.go b/pkg/reconciler/route/route.go index f522e5b4977b..0cfb0816e8bc 100644 --- a/pkg/reconciler/route/route.go +++ b/pkg/reconciler/route/route.go @@ -83,14 +83,14 @@ type Reconciler struct { var _ routereconciler.Interface = (*Reconciler)(nil) func ingressClassForRoute(ctx context.Context, r *v1.Route) string { - if ingressClass := r.Annotations[networking.IngressClassAnnotationKey]; ingressClass != "" { + if ingressClass := networking.GetIngressClass(r.Annotations); ingressClass != "" { return ingressClass } return config.FromContext(ctx).Network.DefaultIngressClass } func certClass(ctx context.Context, r *v1.Route) string { - if class := r.Annotations[networking.CertificateClassAnnotationKey]; class != "" { + if class := networking.GetCertificateClass(r.Annotations); class != "" { return class } return config.FromContext(ctx).Network.DefaultCertificateClass @@ -476,7 +476,7 @@ func autoTLSEnabled(ctx context.Context, r *v1.Route) bool { } logger := logging.FromContext(ctx) - annotationValue := r.Annotations[networking.DisableAutoTLSAnnotationKey] + annotationValue := networking.GetDisableAutoTLS(r.Annotations) disabledByAnnotation, err := strconv.ParseBool(annotationValue) if annotationValue != "" && err != nil {