Skip to content

SoFy Documentation
v0.19.1

PDF

Creating a Custom Error Page

Custom Ambassador or Emissary Error Pages Resource

SoFy solutions now have custom error page capability for the included Ambassador or Emissary ingress controller, using a new custom resource called ErrorPage. These pages can be global, applying to all pages in your solution, or they can be configured to apply to individual pages. You'll first add this new ErrorPage to your solution. To create a an ErrorPage inline, run a command following the steps below:

cat << EOF | kubectl apply -f -
apiVersion: "hclsofy.com/v1beta1"
kind: ErrorPage
metadata:
  name: "myerrorpage"
  namespace: "mynamespace"
spec:
  service:
    name: foo3-snoop
    bypass: true
EOF

You can also create the same resource running the following commands:

  • kubectl apply -f myerrorpage.yaml if myerrorpage.yaml is the below:
apiVersion: "hclsofy.com/v1beta1"
kind: ErrorPage
metadata:
  name: "myerrorpage"
  namespace: "mynamespace"
spec:
  service:
    name: foo3-snoop
    bypass: true
  1. To create a new ErrorPage after you've installed your solution, run the following command:
apiVersion: "hclsofy.com/v1beta1"
kind: ErrorPage
metadata:
  name: "myerrorpage"
  namespace: "mynamespace"
spec:
  statusCode: 404
  html: <html><head><title>my custom 404</title></head><body><h1>Oops!</h1></body></html> 
  • This will create a new global ErrorPage that will be shown for all 404 status codes that happen for that specific solution.

  • If you only wish to apply specific ErrorPages to a particular service mapping, follow the steps below:

apiVersion: "hclsofy.com/v1beta1"
kind: ErrorPage
metadata:
  name: "myerrorpage-foo"
  namespace: "mynamespace"
  labels:
    test: errorpages
spec:
  statusCode: 405
  html: <html><head><title>my custom 405 for foo</title></head><body><h1>Foo Oops!</h1></body></html>
  service:
    name: release-foo
  • It's important to understand that a service mapping with a set ErrorPage will ignore all global ErrorPages. In the example directly above, requests mapped to release-foo will only have a custom ErrorPage for status code 405 and not 404 or any other error page status codes set globally.

  • If you want a particular service to ignore any global ErrorPages, you can create a null ErrorPage resource (with no html specified) as follows:

apiVersion: "hclsofy.com/v1beta1"
kind: ErrorPage
metadata:
  name: "myerrorpage-foo"
  namespace: "mynamespace"
  labels:
    test: errorpages
spec:
  service:
    name: release-foo
    bypass: true
  1. To create the custom resource, the following are required: statusCode and html or service (where name is required). Note: You must have either a statusCode and html together or a service that also define the name - the following combinations are accepted:

    • An ErrorPage that defines statusCode and html, without a service.
    • An ErrorPage that does not define statusCode and html, but does define a service (with the name) and bypass property
    • An ErrorPage that defines a statusCode, with html and defines a service (with name)
  2. The following would be example of an invalid ErrorPage:

  3. An ErrorPage that defines a statusCode alone, an html alone