Skip to content

Commit

Permalink
When auth is disabled, annotations are no longer set
Browse files Browse the repository at this point in the history
  • Loading branch information
alb-car committed Jan 24, 2024
1 parent ab06baa commit fb6aedc
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions internal/controller/apigw_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func (r *ApiGwReconciler) ingressForApiGw(ctx context.Context, apigw *operatorv1
}},
}

// Add TLS to the spec, if enabled
enableTls, found := os.LookupEnv(envEnableTls)
if found && strings.EqualFold(enableTls, "true") {
tls := networkingv1.IngressTLS{
Expand All @@ -405,17 +406,23 @@ func (r *ApiGwReconciler) ingressForApiGw(ctx context.Context, apigw *operatorv1
ingressSpec.TLS = []networkingv1.IngressTLS{tls}
}

objectMeta := metav1.ObjectMeta{
Name: formatResourceName(apigw.Name),
Namespace: apigw.Namespace,
Labels: labelsForApiGw(apigw.Name),
}

// Add auth annotations to metadata, if enabled
if apigw.Spec.Auth.Type != "" && apigw.Spec.Auth.Type != "none" {
objectMeta.Annotations = map[string]string{
"nginx.ingress.kubernetes.io/auth-type": apigw.Spec.Auth.Type,
"nginx.ingress.kubernetes.io/auth-secret": formatResourceName(apigw.Name),
}
}

ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: formatResourceName(apigw.Name),
Namespace: apigw.Namespace,
Labels: labelsForApiGw(apigw.Name),
Annotations: map[string]string{
"nginx.ingress.kubernetes.io/auth-type": apigw.Spec.Auth.Type,
"nginx.ingress.kubernetes.io/auth-secret": formatResourceName(apigw.Name),
},
},
Spec: ingressSpec,
ObjectMeta: objectMeta,
Spec: ingressSpec,
}

// Set the ownerRef for the Ingress
Expand Down

0 comments on commit fb6aedc

Please sign in to comment.