def spec_to_request_dict(namespace: str, name: str, spec: dict) -> dict:
        k8s = K8s()

        # convert all keys from camel to snake case
        request_dict = {camel_to_snake_case(k): v for k, v in spec.items()}
        request_dict['friendly_name'] = request_dict.get('friendly_name', name)
        request_dict['type'] = MonitorType[spec['type']].value

        if 'http_auth_secret' in request_dict:
            secret = k8s.get_secret(namespace,
                                    request_dict['http_auth_secret'])

            request_dict['http_username'] = base64.b64decode(
                secret.data['username']).decode()
            request_dict['http_password'] = base64.b64decode(
                secret.data['password']).decode()
            request_dict.pop('http_auth_secret')

        # map enum values
        for key, enum_class in {
                'sub_type': MonitorSubType,
                'keyword_type': MonitorKeywordType,
                'http_auth_type': MonitorHttpAuthType,
                'http_method': MonitorHttpMethod,
                'post_type': MonitorPostType,
                'post_content_type': MonitorPostContentType
        }.items():
            request_dict[key] = enum_class[
                request_dict[key]].value if key in request_dict else None

        # drop None entries

        return {k: v for k, v in request_dict.items() if v is not None}
def startup(logger, **_):
    if config.DISABLE_INGRESS_HANDLING:
        logger.info('handling of Ingress resources has been disabled')

    global k8s
    k8s = K8s()
    init_uptimerobot_api(logger)
    create_crds(logger)
Beispiel #3
0
    def __init__(self):

        # init k8s connectivity
        self.k8s = K8s()

        # init tiller channel
        self.channel = self.get_channel()

        # init timeout for all requests
        # and assume eventually this will
        # be fed at runtime as an override
        self.timeout = TILLER_TIMEOUT
 def factory(workload_manager):
     if workload_manager == "SLURM":
         from slurm import Slurm
         return Slurm()
     if workload_manager == "TORQUE":
         from torque import Torque
         return Torque()
     if workload_manager == "BASH":
         from bash import Bash
         return Bash()
     if workload_manager == "K8S":
         from k8s import K8s
         return K8s()
     return None
Beispiel #5
0
 def main(self):
     while True:
         self._show()
         op = raw_input("command: ").strip()
         if op == "c":
             self.zookeeper.create()
             self.kafka.create()
         elif op == "r":
             K8s.status()
         elif op.startswith("k "):
             replicas = int(op.split()[1])
             self.kafka.scale(replicas)
         elif op.startswith("z "):
             replicas = int(op.split()[1])
             self.zookeeper.scale(replicas)
         elif op == "d":
             print warn("do want to delete the zookeeper+kafka cluster? (y/n)"),
             yn = raw_input("").strip()
             if yn != "Y" and yn != "y": continue
             self.kafka.delete()
             self.zookeeper.delete()
         elif op.startswith("des"):
             resource = op.split()[1]
             os.system("kubectl describe " + resource)
         elif op.startswith("log"):
             resource = op.split()[1]
             os.system("kubectl logs " + resource)
         elif op == "h":
             if K8s.oke:
                 os.system("kubectl get svc -l release=kafka -o=jsonpath='{range .items[*]} "
                           "{.status.loadBalancer.ingress[0].ip}{\"\\t\"}{.metadata.labels.pod}"
                           "{\".example.com\\n\"}' | grep kafka")
         elif op == "q":
             exit()
         else:
             print red("Invalid command.")
         print
Beispiel #6
0
    def spec_to_request_dict(namespace: str, name: str, spec: dict) -> dict:
        k8s = K8s()

        # convert all keys from camel to snake case
        request_dict = {camel_to_snake_case(k): v for k, v in spec.items()}
        request_dict['friendly_name'] = request_dict.get('friendly_name', name)

        if 'password_secret' in request_dict:
            secret = k8s.get_secret(namespace, request_dict['password_secret'])

            request_dict['password'] = base64.b64decode(
                secret.data['password']).decode()
            request_dict.pop('password_secret')

        # map enum values
        for key, enum_class in {'sort': PspSort, 'status': PspStatus}.items():
            request_dict[key] = enum_class[
                request_dict[key]].value if key in request_dict else None

        # drop None entries
        return {k: v for k, v in request_dict.items() if v is not None}
Beispiel #7
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from util.style import warn, red, style
from k8s import K8s, KafkaClient

K8s.init()

from chart import KafkaChart, ZookeeperChart
import re
import os


class Menu:
    title = ""
    items = []

    @staticmethod
    def __replace(matched):
        op = matched.group('op')
        return style(op[1:len(op) - 1], mode="bold", fore="yellow")

    @staticmethod
    def __style_item(title):
        return re.sub("(?P<op>\([a-z]+\))", Menu.__replace, title)

    def _show(self):
        print
        stars = 40
        print "-" * stars + self.title + "-" * stars
        for item in self.items:
Beispiel #8
0
 def __init__(self):
     self.values = K8s.read_yaml(self.path + "/values.yaml")
     self.pvSize = self.values["persistence"]["size"]
Beispiel #9
0
 def scale(self, replicas):
     for i in range(replicas):
         K8s.create_external_svc(i)
     Chart.scale(self, replicas)
Beispiel #10
0
 def scale(self, replicas):
     for i in range(replicas):
         if not K8s.oke:
             K8s.create_pv(self.name, i, self.values["persistence"]["size"])
     os.system("kubectl scale --replicas=" + str(replicas) +
               " statefulset/" + self.name)
Beispiel #11
0
 def delete(self):
     os.system("helm delete --purge " + self.name)
     if not K8s.oke:
         K8s.delete_pv(self.name)
Beispiel #12
0
 def create(self):
     for i in range(self.replicas):
         if not K8s.oke:
             K8s.create_pv(self.name, i, self.values["persistence"]["size"])
     os.system("helm install --name {0} ../{0}".format(self.name))