예제 #1
0
파일: create.py 프로젝트: retr0h/kindly
def create(ctx):
    '''Create a new cluster. '''

    args = ctx.obj.get('args')
    command_args = {}

    c = config.Config(args, command_args)
    s = spec.DeploymentSpec(c.kindly_file)
    d = driver.Kind(c, s)
    p = packager.Helm(c, s)
    o = orchestrator.Kubectl(c, s)

    cluster_name = s.cluster_name
    if d.exists():
        msg = f"Cluster '{cluster_name}' already exists"
        util.abort_with_message(msg)

    with halo.Halo(
            text=f"Creating cluster '{cluster_name}'",
            spinner='dots',
            enabled=c.spinner,
    ) as spinner:
        d.create()
        spinner.succeed()

    if s.template_spec_contains('image'):
        with halo.Halo(
                text=f"Loading image '{s.image}'",
                spinner='dots',
                enabled=c.spinner,
        ) as spinner:
            d.load_image()
            spinner.succeed()

    if s.template_spec_contains('packager'):
        with halo.Halo(
                text=f"Create package namespace '{s.packager_namespace}'",
                spinner='dots',
                enabled=c.spinner,
        ) as spinner:
            o.create_namespace()
            spinner.succeed()

        with halo.Halo(
                text=f"Install package '{s.packager_chart}'",
                spinner='dots',
                enabled=c.spinner,
        ) as spinner:
            p.install()
            spinner.succeed()

    if s.template_spec_contains('configs'):
        with halo.Halo(
                text=
                f"Create objects from yaml definitions in '{s.configs_path}'",
                spinner='dots',
                enabled=c.spinner,
        ) as spinner:
            o.create_objects()
            spinner.succeed()
예제 #2
0
파일: apply.py 프로젝트: retr0h/kindly
def apply(ctx):
    '''Apply configs to an existing cluster. '''

    args = ctx.obj.get('args')
    command_args = {}

    c = config.Config(args, command_args)
    s = spec.DeploymentSpec(c.kindly_file)
    d = driver.Kind(c, s)
    p = packager.Helm(c, s)
    o = orchestrator.Kubectl(c, s)

    if not d.exists():
        msg = (f"Cluster '{s.cluster_name}' does not exist.  "
               "Please execute create subcommand.")
        util.abort_with_message(msg)

    with halo.Halo(
            text="Setting orchestrator's context",
            spinner='dots',
            enabled=c.spinner,
    ) as spinner:
        o.set_context()
        spinner.succeed()

    if s.template_spec_contains('image'):
        with halo.Halo(
                text=f"Loading image '{s.image}'",
                spinner='dots',
                enabled=c.spinner,
        ) as spinner:
            d.load_image()
            spinner.succeed()

    if s.template_spec_contains('packager'):
        with halo.Halo(
                text=f"Upgrade package '{s.packager_chart}'",
                spinner='dots',
                enabled=c.spinner,
        ) as spinner:
            p.upgrade()
            spinner.succeed()

    if s.template_spec_contains('configs'):
        with halo.Halo(
                text=f"Apply updated configs in '{s.configs_path}'",
                spinner='dots',
                enabled=c.spinner,
        ) as spinner:
            o.update_objects()
            spinner.succeed()
예제 #3
0
    def _validate(self, kindly_file):
        # TODO(jodewey): Move validation into a better library.
        assert 'core/v1alpha1' == self._data['apiVersion']
        assert 'KindlyDeployment' == self._data['kind']

        # Template spec validation
        __req_attributes = {
            'packager': {'name', 'chart', 'namespace'},
            'image': {'repository', 'pullPolicy', 'tag'},
            'configs': {'configPath'},
        }
        for attrib in self._template_spec:
            if (not set(self._template_spec[attrib])
                    == __req_attributes[attrib]):
                msg = (
                    f"kindly_file validation failed for template:spec:{attrib}"
                    f" required attribs missing {__req_attributes[attrib]}")
                util.abort_with_message(msg)