示例#1
0
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)
示例#2
0
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()
示例#3
0
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)
示例#4
0
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()
示例#5
0
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)
示例#6
0
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)
示例#7
0
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))
示例#8
0
def create_env(context, namespace=None):
  configmap = ConfigMap(context, namespace=namespace)
  configmap.create()
  print_green("Created configmap %s-environment" % config.project_name)
示例#9
0
def unset_env(context, environment, namespace=None):
  configmap = ConfigMap(context, namespace=namespace)
  configmap.load()
  for s in environment:
    configmap.delete(s)
  configmap.save()
示例#10
0
def delete_env(context, namespace=None):
  configmap = ConfigMap(context, namespace=namespace)
  configmap.destroy()
  print_green("Deleted configmap %s-environment" % config.project_name)
示例#11
0
 def test_00_k8s_env_create(self, mocked_sys_exit):
     configmap = ConfigMap(TEST_KUBE_CONTEXT)
     configmap.create()
示例#12
0
 def test_06_k8s_env_destroy(self, mocked_sys_exit):
     configmap = ConfigMap(TEST_KUBE_CONTEXT)
     configmap.destroy()
示例#13
0
文件: env.py 项目: starsirius/hokusai
def unset_env(context, environment):
  configmap = ConfigMap(context)
  configmap.load()
  for s in environment:
    configmap.delete(s)
  configmap.save()
示例#14
0
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))