Skip to content

Commit

Permalink
Generate favicon Route if a custom logo is configured
Browse files Browse the repository at this point in the history
When the OCP console is customized, the default favicon is not served,
which is an intentional design decision, as documented in
https://bugzilla.redhat.com/show_bug.cgi?id=1844883#c1.

However, that bugzilla provides a workaround to restore the default
favicon when the console is customized, cf.
https://bugzilla.redhat.com/show_bug.cgi?id=1844883#c3.

We implement this workaround in this commit if the console logo is
customized, and a custom hostname is configured, as we otherwise can't
configure `spec.hostname` for the additional route.

Ideally, we'd like to allow users to configure a custom favicon if
they're customizing the logo, but that's currently not possible.

Fixes #27
  • Loading branch information
simu committed Jun 10, 2022
1 parent b0e29d3 commit a995157
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
34 changes: 34 additions & 0 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ local consoleSpec =
{}
);

local faviconRoute =
if logoFileName != '' && hostname != null then
kube._Object('route.openshift.io/v1', 'Route', 'console-favicon') {
metadata+: {
namespace: 'openshift-console',
labels+: {
app: 'console',
},
annotations+: {
'haproxy.router.openshift.io/rewrite-target':
'/static/assets/openshift-favicon.png',
},
},
spec: {
host: hostname,
path: '/favicon.ico',
to: {
kind: 'Service',
name: 'console',
weight: 100,
},
port: {
targetPort: 'https',
},
tls: {
termination: 'reencrypt',
insecureEdgeTerminationPolicy: 'Redirect',
},
wildcardPolicy: 'None',
},
};

// Create ResourceLocker patch to configure console route in
// ingress.config.openshift.io/cluster object
local consoleRoutePatch =
Expand Down Expand Up @@ -224,6 +256,8 @@ local openshiftConfigNsAnnotationPatch =
'10_console': kube._Object(versionGroup, 'Console', 'cluster') {
spec+: consoleSpec,
},
[if faviconRoute != null then '10_console_favicon_route']:
faviconRoute,
[if !oldConfig && consoleRoutePatch != null then '20_ingress_config_patch']:
consoleRoutePatch,
[if openshiftConfigNsAnnotationPatch != null then '20_openshift_config_ns_annotation_patch']:
Expand Down
7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ The filename needs to have a filename extension which matches the image format.
For SVG logos the file must *not* be base64 encoded, but inserted directly as a string.
====

By default, OCP will not serve a favicon if a custom logo is configured for the console.
This is an intentional design decision as documented in this https://bugzilla.redhat.com/show_bug.cgi?id=1844883#c1[bug report].

The component tries to ensure that a favicon is served even if a custom logo is configured.
However, because the current workaround for the missing favicon requires an additional custom route for the console hostname, it can only be implemented for configurations which use a custom console hostname.
Otherwise, the component is unable to correctly configure `spec.hostname` for the console.

== `secrets`

[horizontal]
Expand Down
13 changes: 13 additions & 0 deletions tests/custom-logo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
parameters:
kapitan:
dependencies:
- type: https
source: https://raw.githubusercontent.com/projectsyn/component-resource-locker/v2.1.0/lib/resource-locker.libjsonnet
output_path: vendor/lib/resource-locker.libjsonnet

resource_locker:
namespace: syn-resource-locker

openshift4_console:
config:
route:
hostname: console.company.cloud
secret:
name: console-company-cloud-tls
customization:
customProductName: Company Cloud
custom_logo:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
annotations:
haproxy.router.openshift.io/rewrite-target: /static/assets/openshift-favicon.png
labels:
app: console
name: console-favicon
name: console-favicon
namespace: openshift-console
spec:
host: console.company.cloud
path: /favicon.ico
port:
targetPort: https
tls:
insecureEdgeTerminationPolicy: Redirect
termination: reencrypt
to:
kind: Service
name: console
weight: 100
wildcardPolicy: None
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
name: cluster-manager
name: cluster-manager
namespace: syn-resource-locker
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
name: syn-resource-locker-cluster-manager
name: syn-resource-locker-cluster-manager
rules:
- apiGroups:
- config.openshift.io
resources:
- ingresses
verbs:
- get
- list
- patch
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
name: syn-resource-locker-cluster-manager
name: syn-resource-locker-cluster-manager
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: syn-resource-locker-cluster-manager
subjects:
- kind: ServiceAccount
name: cluster-manager
namespace: syn-resource-locker
---
apiVersion: redhatcop.redhat.io/v1alpha1
kind: ResourceLocker
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/sync-wave: '10'
labels:
name: cluster
name: cluster
namespace: syn-resource-locker
spec:
patches:
- id: patch1
patchTemplate: "\"spec\":\n \"componentRoutes\":\n - \"hostname\": \"console.company.cloud\"\
\n \"name\": \"console\"\n \"namespace\": \"openshift-console\"\n \
\ \"servingCertKeyPairSecret\":\n \"name\": \"console-company-cloud-tls\""
patchType: application/merge-patch+json
targetObjectRef:
apiVersion: config.openshift.io/v1
kind: Ingress
name: cluster
serviceAccountRef:
name: cluster-manager

0 comments on commit a995157

Please sign in to comment.