Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

canonical/interface-ambassador

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This repository hosts code for the Ambassador interface. It currently allows detecting the presence of Ambassador via relations. A Kubernetes charm can use the presence of this relation to know that it should annotate itself with information about which routes it should be reverse-proxied to.

Usage

# metadata.yaml
...
provides:
  ambassador:
    interface: ambassador
# layer.yaml
includes:
  ...
  - "interface:ambassador"
@when('endpoint.ambassador.joined')
def ambassador_available(_):
    config = hookenv.config()
    config['ambassador-available'] = True
    config.save()
    clear_flag('charm.name.started')


@when_not('endpoint.ambassador.joined')
def ambassador_unavailable():
    config = hookenv.config()
    config['ambassador-available'] = False
    config.save()
    clear_flag('charm.name.started')

@when_not('charm.name.started')
def start_charm():
    if config.get('ambassador-available'):
        annotations = {
            'getambassador.io/config': yaml.dump([
                {
                    'apiVersion': 'ambassador/v0',
                    'kind':  'Mapping',
                    'name':  'example_route',
                    'prefix': '/route/',
                    'rewrite': '/route/',
                    'service': f'{hookenv.service_name()}:8080',
                },
            ]),
        }
    else:
        annotations = {}

    ...

    layer.caas_base.pod_spec_set({
        'service': {'annotations': annotations},
        ...
    })

Releases

No releases published

Packages

No packages published

Languages