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()
def get(ctx): '''Get all Kind clusters. ''' args = ctx.obj.get('args') command_args = {} c = config.Config(args, command_args) s = spec.DeploymentSpec(c.kindly_file) d = driver.Kind(c, s) data = {'clusters': d.get()} click.echo(util.safe_dump(data))
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()
def delete(ctx): '''Delete 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) with halo.Halo(text='Deleting cluster', spinner='dots', enabled=c.spinner) as spinner: d.delete() spinner.succeed()
def spec_instance(config_instance): return spec.DeploymentSpec(config_instance.kindly_file)