This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Add juju config and logic for creating traefik routes #3
Closed
natalian98
wants to merge
10
commits into
main
from
IAM-442-implement-logic-for-creating-traefik-routes
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e8e4888
feat: add config options and routes creation logic
natalian98 42e3626
refactor: modify or delete log messages
natalian98 2cc3c17
test: minor unit tests changes
natalian98 52f006b
refactor: minor updates
natalian98 47f4493
docs: update readme
natalian98 b42dbd5
fix: install jsonschema from binary
natalian98 2c8942a
refactor: remove unused methods
natalian98 f78b3cf
test: add unit test for rule rendering
natalian98 014582b
refactor: address review comments
natalian98 31b3710
refactor: rename to traefik_route_types
natalian98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,7 @@ bases: | |
run-on: | ||
- name: "ubuntu" | ||
channel: "22.04" | ||
parts: | ||
charm: | ||
charm-binary-python-packages: | ||
- jsonschema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
options: | ||
access_rules: | ||
description: | | ||
A string containing access rules in json format. | ||
The config value can point to a file if prepended with @. | ||
Example: `access_rules=@access_rules.json` | ||
type: string | ||
headers: | ||
description: | | ||
Comma separated list of headers expected to be returned by Oathkeeper. | ||
Example: `headers=X-User,X-Header` | ||
type: string | ||
default: X-User | ||
rule: | ||
default: | ||
description: | | ||
A Traefik routing rule, see https://doc.traefik.io/traefik/routing/routers/ for | ||
an overview. | ||
|
||
The value of the field is going to be processed as a Jinja2 template, with the | ||
following globals available: | ||
- {{juju_model}} resolves to the model name of the downstream proxied | ||
application. | ||
- {{juju_application}} resolves to the application name of the downstream | ||
proxied application. | ||
- {{juju_unit}} resolves to the unit name of the downstream proxied unit; | ||
to avoid issues when used together with the Host directive or similar, | ||
the slash character between application name and unit index is replaced by a dash. | ||
|
||
For example, given a downstream unit called `prometheus/0` in the `cos` model, the following: | ||
|
||
Host(`foo.bar/{{juju_unit}}-{{juju_model}}`) | ||
|
||
would evaluate to: | ||
|
||
Host(`foo.bar/cos-prometheus-0`) | ||
|
||
If the host is omitted, but the root_url is provided, the charm will | ||
extract the hostname from the url and generate a Host rule for you. | ||
root_url=`http://{{juju_unit}}.bar.baz:80/qux` | ||
--> rule=Host(`{{juju_unit}}.bar.baz`) | ||
type: string | ||
root_url: | ||
description: | | ||
The url to advertise to the unit in need of ingress. | ||
|
||
The value of the field is going to be processed in exactly the same way as | ||
the `rule` field. The assumption is that the url is going to match | ||
the rule; however, we have no way to validate and/or enforce this condition; | ||
so beware! | ||
For example, given a downstream unit called `prometheus/0` in the `cos` model, the | ||
following configuration is valid: | ||
|
||
rule="Host(`{{juju_unit}}.{{juju_model}}.foo.bar`)" | ||
root_url="http://{{juju_unit}}.{{juju_model}}.foo.bar/baz" | ||
|
||
while the following configuration is not: | ||
|
||
rule="Host(`{{juju_model}}-{{juju_unit}}.foo.bar`) || | ||
HostRegexp(`{subdomain:[a-z]+}.foo.bar`) || | ||
Host(`doobadooba.com`)" | ||
root_url="ka-ching.com" | ||
|
||
The reason why this is not valid is that the url does not match the rule: | ||
so the url advertised to the unit will not in fact be routed correctly by Traefik. | ||
Note that Traefik will still work 'correctly', i.e. the application will be | ||
reachable at (for example) `http://doobadooba.com`. | ||
Examples of 'good' root_url values for this case would be: | ||
|
||
root_url="{{juju_model}}-{{juju_unit}}.foo.bar/baz" | ||
root_url="baz.foo.bar" | ||
root_url="doobadooba.com/choo" | ||
type: string |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why those are needed, shouldn't we get those from a relation??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
rule
will be generated fromroot_url
if the first is not provided (with the globals coming from the relation), although if an admin wants to configure the rules differently, this config option provides that possibility. I'm trying to follow the logic of traefik-route-k8s here as the charm is tested against edge cases.It's also a ground for non-charmed workloads as I imagine the rules will have to be supplied via config.