Skip to content

Commit

Permalink
Use annotation helper functions
Browse files Browse the repository at this point in the history
We're going to introduce kebab-casing but we still want to support
the old format.
  • Loading branch information
dprotaso committed Nov 17, 2021
1 parent fd81a61 commit b88e9b1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/reconciler/domainmapping/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/nscert/nscert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/route/reconcile_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/reconciler/route/resources/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,28 +195,28 @@ func makeIngressSpec(
}
}

httpOption, err := getHTTPOption(ctx, r.Annotations)
httpProtocol, err := getHTTPProtocol(ctx, r.Annotations)
if err != nil {
return netv1alpha1.IngressSpec{}, err
}

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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b88e9b1

Please sign in to comment.