def k8s_create(context, tag='latest', namespace=None, filename=None): if filename is None: kubernetes_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % context) else: kubernetes_yml = filename if not os.path.isfile(kubernetes_yml): raise HokusaiError("Yaml file %s does not exist." % kubernetes_yml) ecr = ECR() if not ecr.project_repo_exists(): raise HokusaiError( "ECR repository %s does not exist... did you run `hokusai setup` for this project?" % config.project_name) if not ecr.tag_exists(tag): raise HokusaiError( "Image tag %s does not exist... did you run `hokusai registry push`?" % tag) if tag is 'latest' and not ecr.tag_exists(context): ecr.retag(tag, context) print_green("Updated tag 'latest' -> %s" % context) if filename is None: configmap = ConfigMap(context, namespace=namespace) configmap.create() print_green("Created configmap %s-environment" % config.project_name) kctl = Kubectl(context, namespace=namespace) shout(kctl.command("create --save-config -f %s" % kubernetes_yml), print_output=True) print_green("Created Kubernetes environment %s" % kubernetes_yml)
def k8s_copy_config(context, destination_namespace, name=None): source_configmap = ConfigMap(context, name=name) destination_configmap = ConfigMap(context, name=name, namespace=destination_namespace) source_configmap.load() destination_configmap.struct['data'] = source_configmap.struct['data'] destination_configmap.save()
def k8s_delete(context, namespace=None, filename=None): if filename is None: yaml_template = TemplateSelector().get(os.path.join(CWD, HOKUSAI_CONFIG_DIR, context)) else: yaml_template = TemplateSelector().get(filename) if filename is None: configmap = ConfigMap(context, namespace=namespace) configmap.destroy() print_green("Deleted configmap %s-environment" % config.project_name) kctl = Kubectl(context, namespace=namespace) yaml_spec = YamlSpec(yaml_template).to_file() shout(kctl.command("delete -f %s" % yaml_spec), print_output=True) print_green("Deleted Kubernetes environment %s" % yaml_template)
def set_env(context, environment, namespace=None): configmap = ConfigMap(context, namespace=namespace) configmap.load() for s in environment: if '=' not in s: raise HokusaiError("Error: environment variables must be of the form 'KEY=VALUE'") split = s.split('=', 1) configmap.update(split[0], split[1]) configmap.save()
def k8s_delete(context, namespace=None, filename=None): if filename is None: kubernetes_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % context) else: kubernetes_yml = filename if not os.path.isfile(kubernetes_yml): raise HokusaiError("Yaml file %s does not exist." % kubernetes_yml) if filename is None: configmap = ConfigMap(context, namespace=namespace) configmap.destroy() print_green("Deleted configmap %s-environment" % config.project_name) kctl = Kubectl(context, namespace=namespace) shout(kctl.command("delete -f %s" % kubernetes_yml), print_output=True) print_green("Deleted Kubernetes environment %s" % kubernetes_yml)
def k8s_create(context, tag='latest', namespace=None, filename=None, environment=()): if filename is None: yaml_template = TemplateSelector().get(os.path.join(CWD, HOKUSAI_CONFIG_DIR, context)) else: yaml_template = TemplateSelector().get(filename) ecr = ECR() if not ecr.project_repo_exists(): raise HokusaiError("ECR repository %s does not exist... did you run `hokusai setup` for this project?" % config.project_name) if not ecr.tag_exists(tag): raise HokusaiError("Image tag %s does not exist... did you run `hokusai registry push`?" % tag) if tag == 'latest' and not ecr.tag_exists(context): ecr.retag(tag, context) print_green("Updated tag 'latest' -> %s" % context) if filename is None: configmap = ConfigMap(context, namespace=namespace) for s in environment: if '=' not in s: raise HokusaiError("Error: environment variables must be of the form 'KEY=VALUE'") split = s.split('=', 1) configmap.update(split[0], split[1]) configmap.create() print_green("Created configmap %s-environment" % config.project_name) kctl = Kubectl(context, namespace=namespace) yaml_spec = YamlSpec(yaml_template).to_file() shout(kctl.command("create --save-config -f %s" % yaml_spec), print_output=True) print_green("Created Kubernetes environment %s" % yaml_template)
def get_env(context, environment, namespace=None): configmap = ConfigMap(context, namespace=namespace) configmap.load() if environment: for k, v in configmap.all(): if k in environment: print("%s=%s" % (k, v)) else: for k, v in configmap.all(): print("%s=%s" % (k, v))
def create_env(context, namespace=None): configmap = ConfigMap(context, namespace=namespace) configmap.create() print_green("Created configmap %s-environment" % config.project_name)
def unset_env(context, environment, namespace=None): configmap = ConfigMap(context, namespace=namespace) configmap.load() for s in environment: configmap.delete(s) configmap.save()
def delete_env(context, namespace=None): configmap = ConfigMap(context, namespace=namespace) configmap.destroy() print_green("Deleted configmap %s-environment" % config.project_name)
def test_00_k8s_env_create(self, mocked_sys_exit): configmap = ConfigMap(TEST_KUBE_CONTEXT) configmap.create()
def test_06_k8s_env_destroy(self, mocked_sys_exit): configmap = ConfigMap(TEST_KUBE_CONTEXT) configmap.destroy()
def unset_env(context, environment): configmap = ConfigMap(context) configmap.load() for s in environment: configmap.delete(s) configmap.save()
def get_env(context, environment, namespace=None): configmap = ConfigMap(context, namespace=namespace) configmap.load() for k, v in sorted(configmap.all().items()): if not environment or (environment and k in environment): print_smart("%s=%s" % (k, v))