GithubHelp home page GithubHelp logo

isabella232 / layer-caas-base Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juju-solutions/layer-caas-base

0.0 0.0 0.0 38 KB

Base layer for CaaS charms

License: Apache License 2.0

Python 100.00%

layer-caas-base's Introduction

Overview

Apache 2.0 License

This is the base layer for all CAAS reactive Charms. It provides all of the standard Juju hooks and starts the reactive framework when these hooks get executed.

Usage

Any CAAS or Kubernetes charm should include this in its layer.yaml. It is also recommended to include layer:docker-resource:

includes:
  - 'layer:caas-base'
  - 'layer:docker-resource'

The charm can then define its container image as a resource in metadata.yaml:

name: my-charm
resources:
  my-image:
    description: 'Image for this charm'
    type: oci-image
    auto-fetch: true

When ready, the charm should call pod_spec_set with the relevant data structure:

from charmhelpers.core import hookenv
from charms.reactive import set_flag, when, when_not

from charms import layer


@when('layer.docker-resource.my-image.available')
@when_not('charm.my-charm.started')
def create_container():
    layer.status.maintenance('configuring container')

    image_info = layer.docker_resource.get_info('my-image')
    config = hookenv.config()

    success = layer.caas_base.pod_spec_set({
        'containers': [
            {
                'name': 'my-charm',
                'imageDetails': {
                    'imagePath': image_info.registry_path,
                    'username': image_info.username,
                    'password': image_info.password,
                },
                'ports': [
                    {
                        'name': 'service',
                        'containerPort': 80,
                    },
                ],
                'config': {
                    'SOME_VALUE': config['some-option'],
                },
                'files': [
                    {
                        'name': 'configs',
                        'mountPath': '/etc/config',
                        'files': {
                            'my-charm.conf': Path('files/my-charm.conf').read_text(),
                        },
                    },
                ],
            },
        ],
    })
    if success:
        layer.status.maintenance('creating container')
        set_flag('charm.my-charm.started')
    else:
        layer.status.blocked('k8s spec failed to deploy')

layer-caas-base's People

Contributors

johnsca avatar knkski avatar wallyworld avatar ycliuhw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.