Skip to content

Commit 622b6ca

Browse files
committed
Expose Routes externally with front door
Originating issue: [IBMPrivateCloud/roadmap#66643](https://github.ibm.com/IBMPrivateCloud/roadmap/issues/66643) Signed-off-by: Rob Hundley <[email protected]>
1 parent df73bba commit 622b6ca

File tree

3 files changed

+9
-42
lines changed

3 files changed

+9
-42
lines changed

controllers/operator/configmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ func (r *AuthenticationReconciler) generateCNCFClusterInfo(ctx context.Context,
834834
clusterAddress := strings.Join([]string{strings.Join([]string{"cp-console", authCR.Namespace}, "-"), domainName}, ".")
835835
clusterEndpoint := "https://" + clusterAddress
836836
clusterAddressAuth := clusterAddress
837-
if authCR.Spec.Config.ZenFrontDoor && ctrlcommon.ClusterHasZenExtensionGroupVersion(&r.DiscoveryClient) {
837+
if shouldUseCPDHost(authCR, &r.DiscoveryClient) {
838838
zenHost, err = r.getZenHost(ctx, authCR)
839839
if err == nil {
840840
clusterAddressAuth = zenHost
@@ -903,7 +903,7 @@ func (r *AuthenticationReconciler) generateOCPClusterInfo(ctx context.Context, a
903903
clusterAddress := domainName
904904
clusterEndpoint := "https://" + clusterAddress
905905
clusterAddressAuth := clusterAddress
906-
if authCR.Spec.Config.ZenFrontDoor && ctrlcommon.ClusterHasZenExtensionGroupVersion(&r.DiscoveryClient) {
906+
if shouldUseCPDHost(authCR, &r.DiscoveryClient) {
907907
zenHost, err = r.getZenHost(ctx, authCR)
908908
if err == nil {
909909
clusterAddressAuth = zenHost

controllers/operator/routes.go

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (r *AuthenticationReconciler) handleRoutes(ctx context.Context, req ctrl.Re
9393
// traffic.
9494
func (r *AuthenticationReconciler) checkForZenFrontDoor(ctx context.Context, authCR *operatorv1alpha1.Authentication) (result *ctrl.Result, err error) {
9595
reqLogger := logf.FromContext(ctx)
96-
if shouldHaveRoutes(authCR, &r.DiscoveryClient) {
96+
if shouldNotUseCPDHost(authCR, &r.DiscoveryClient) {
9797
reqLogger.Info("IM Routes will be created")
9898
return subreconciler.ContinueReconciling()
9999
}
@@ -320,37 +320,10 @@ func (r *AuthenticationReconciler) reconcileRoute(authCR *operatorv1alpha1.Authe
320320
reqLogger.Info("Reconciling route", "annotations", fields.Annotations, "routeHost", fields.RouteHost, "routePath", fields.RoutePath)
321321

322322
fCtx := logf.IntoContext(ctx, reqLogger)
323-
if fields.Name != IMCrtAuthRouteName {
324-
if shouldNotHaveRoutes(authCR, &r.DiscoveryClient) {
325-
return r.ensureRouteDoesNotExist(fCtx, authCR, fields)
326-
}
327-
}
328-
329323
return r.ensureRouteExists(fCtx, authCR, fields)
330324
}
331325
}
332326

333-
func (r *AuthenticationReconciler) ensureRouteDoesNotExist(ctx context.Context, authCR *operatorv1alpha1.Authentication, fields *reconcileRouteFields) (result *ctrl.Result, err error) {
334-
reqLogger := logf.FromContext(ctx)
335-
reqLogger.Info("Determined Route should not exist; removing if present")
336-
observedRoute := &routev1.Route{}
337-
err = r.Get(ctx, types.NamespacedName{Name: fields.Name, Namespace: authCR.Namespace}, observedRoute)
338-
if k8sErrors.IsNotFound(err) {
339-
return subreconciler.ContinueReconciling()
340-
} else if err != nil {
341-
reqLogger.Error(err, "Failed to get existing route for reconciliation")
342-
return subreconciler.RequeueWithError(err)
343-
}
344-
err = r.Delete(ctx, observedRoute)
345-
if err != nil {
346-
reqLogger.Error(err, "Failed to delete the Route")
347-
return subreconciler.RequeueWithError(err)
348-
}
349-
reqLogger.Info("Successfully deleted the Route")
350-
351-
return subreconciler.RequeueWithDelay(defaultLowerWait)
352-
}
353-
354327
func (r *AuthenticationReconciler) ensureRouteExists(ctx context.Context, authCR *operatorv1alpha1.Authentication, fields *reconcileRouteFields) (result *ctrl.Result, err error) {
355328
reqLogger := logf.FromContext(ctx)
356329
calculatedRoute, err := r.newRoute(authCR, fields)
@@ -436,12 +409,12 @@ func (r *AuthenticationReconciler) ensureRouteExists(ctx context.Context, authCR
436409
return subreconciler.ContinueReconciling()
437410
}
438411

439-
func shouldNotHaveRoutes(authCR *operatorv1alpha1.Authentication, dc *discovery.DiscoveryClient) bool {
412+
func shouldUseCPDHost(authCR *operatorv1alpha1.Authentication, dc *discovery.DiscoveryClient) bool {
440413
return authCR.Spec.Config.ZenFrontDoor && ctrlcommon.ClusterHasZenExtensionGroupVersion(dc)
441414
}
442415

443-
func shouldHaveRoutes(authCR *operatorv1alpha1.Authentication, dc *discovery.DiscoveryClient) bool {
444-
return !shouldNotHaveRoutes(authCR, dc)
416+
func shouldNotUseCPDHost(authCR *operatorv1alpha1.Authentication, dc *discovery.DiscoveryClient) bool {
417+
return !shouldUseCPDHost(authCR, dc)
445418
}
446419

447420
// Use DeepEqual to determine if 2 routes are equal.
@@ -588,6 +561,9 @@ func (r *AuthenticationReconciler) getClusterAddress(authCR *operatorv1alpha1.Au
588561
clusterInfoConfigMap := &corev1.ConfigMap{}
589562

590563
clusterAddressFieldName := "cluster_address"
564+
if shouldUseCPDHost(authCR, &r.DiscoveryClient) {
565+
clusterAddressFieldName = "cluster_address_auth"
566+
}
591567

592568
fns := []subreconciler.Fn{
593569
r.getClusterInfoConfigMap(authCR, clusterInfoConfigMap),

controllers/operator/zenextension.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ location /idprovider/ {
6969
proxy_buffers 4 256k;
7070
proxy_read_timeout 180s;
7171
}
72-
location /login {
73-
proxy_set_header Host $host;
74-
proxy_set_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
75-
proxy_pass https://platform-identity-provider.%[1]s.svc:4300/;
76-
proxy_buffer_size 256k;
77-
proxy_buffers 4 256k;
78-
proxy_read_timeout 180s;
79-
rewrite /login /v1/auth/authorize?client_id=%s&redirect_uri=https://%s/auth/liberty/callback&response_type=code&scope=openid+email+profile&orig=/login break;
80-
}
8172
location /oidc {
8273
proxy_set_header Host $host;
8374
proxy_set_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

0 commit comments

Comments
 (0)