Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--delete-namespace", type=lambda x: (str(x).lower() == 'true'), default=True)
    parser.add_argument("--delete-pvc", type=lambda x: (str(x).lower() == 'true'), default=False)
    deploy_options = deployment_options.load_deployment_options(parser)

    utils.verify_build_directory(deploy_options.namespace)

    kubectl_cmd = utils.get_kubectl_command(
        target=deploy_options.target,
        profile=deploy_options.profile
    )
    print(utils.check_output(f'{kubectl_cmd} delete all --all -n {deploy_options.namespace} --force --grace-period=0 1> /dev/null ; true'))
    # configmaps are not deleted with `delete all`
    print(utils.check_output(f"{kubectl_cmd} get configmap -o name -n {deploy_options.namespace} | " +
                             f"xargs -r {kubectl_cmd} delete -n {deploy_options.namespace} --force --grace-period=0 1> /dev/null ; true"))
    # ingress is not deleted with `delete all`
    print(utils.check_output(f"{kubectl_cmd} get ingress -o name -n {deploy_options.namespace} | " +
                             f"xargs -r {kubectl_cmd} delete -n {deploy_options.namespace} --force --grace-period=0 1> /dev/null ; true"))

    if deploy_options.delete_pvc:
        print(utils.check_output(f"{kubectl_cmd} delete pvc --all -n {deploy_options.namespace} --force --grace-period=0 1> /dev/null ; true"))

    if deploy_options.delete_namespace is True:
        print(utils.check_output(f"{kubectl_cmd} delete namespace {deploy_options.namespace} --force --grace-period=0 1> /dev/null ; true"))
def main():
    deploy_options = deployment_options.load_deployment_options()
    utils.verify_build_directory(deploy_options.namespace)

    src_file = os.path.join(os.getcwd(), 'deploy/mariadb/mariadb-configmap.yaml')
    dst_file = os.path.join(os.getcwd(), 'build', deploy_options.namespace, 'mariadb-configmap.yaml')
    with open(src_file, "r") as src:
        with open(dst_file, "w+") as dst:
            data = src.read()
            data = data.replace('REPLACE_NAMESPACE', f'"{deploy_options.namespace}"')
            print("Deploying {}".format(dst_file))
            dst.write(data)

    utils.apply(
        target=deploy_options.target,
        namespace=deploy_options.namespace,
        file=dst_file
    )

    src_file = os.path.join(os.getcwd(), 'deploy/mariadb/mariadb-deployment.yaml')
    dst_file = os.path.join(os.getcwd(), 'build', deploy_options.namespace, 'mariadb-deployment.yaml')
    with open(src_file, "r") as src:
        with open(dst_file, "w+") as dst:
            data = src.read()
            data = data.replace('REPLACE_NAMESPACE', f'"{deploy_options.namespace}"')
            print("Deploying {}".format(dst_file))
            dst.write(data)
    utils.apply(
        target=deploy_options.target,
        namespace=deploy_options.namespace,
        file=dst_file
    )

    src_file = os.path.join(os.getcwd(), 'deploy/mariadb/mariadb-storage.yaml')
    dst_file = os.path.join(os.getcwd(), 'build', deploy_options.namespace, 'mariadb-storage.yaml')
    with open(src_file, "r") as src:
        with open(dst_file, "w+") as dst:
            data = src.read()
            data = data.replace('REPLACE_NAMESPACE', f'"{deploy_options.namespace}"')
            try:
                kubectl_cmd = utils.get_kubectl_command(
                    target=deploy_options.target,
                    namespace=deploy_options.namespace
                )
                size = utils.check_output(
                    f'{kubectl_cmd} get persistentvolumeclaims mariadb-pv-claim ' +
                    '-o=jsonpath="{.status.capacity.storage}"')
                print("Using existing disk size", size)
            except:
                size = "10Gi"
                print("Using default size", size)
            data = data.replace("REPLACE_STORAGE", size)
            print("Deploying {}".format(dst_file))
            dst.write(data)

    utils.apply(
        target=deploy_options.target,
        namespace=deploy_options.namespace,
        file=dst_file
    )
def get_current_size_if_exist(target, ns, name):
    kubectl_cmd = utils.get_kubectl_command(target, ns)
    p = sp.Popen(
        f'{kubectl_cmd} get persistentvolumeclaims {name} '
        '-o=jsonpath="{.status.capacity.storage}"',
        shell=True,
        stdout=sp.PIPE,
        stderr=sp.PIPE,
    )
    err = p.stderr.read().decode()
    if 'not found' in err:
        return
    elif err:
        raise RuntimeError(f'failed to get size of pvc {name}: {err}')

    return p.stdout.read().decode()
Ejemplo n.º 4
0
This script deploy Grafana instance of it on K8s and OCP
n the OCP case, it will be integrated automatically with OCP oauth.
'''

import os
import sys
from time import sleep
import secrets
import utils
import deployment_options

deploy_options = deployment_options.load_deployment_options()
utils.verify_build_directory(deploy_options.namespace)

if deploy_options.target != "oc-ingress":
    CMD_BIN = utils.get_kubectl_command(target=deploy_options.target,
                                        profile=deploy_options.profile)
else:
    CMD_BIN = 'oc'


def deploy_oauth_reqs():
    '''oauth Integration in OCP'''
    # Token generation for session_secret
    session_secret = secrets.token_hex(43)
    secret_name = 'grafana-proxy'
    if not utils.check_if_exists(k8s_object='secret',
                                 k8s_object_name=secret_name,
                                 target=deploy_options.target,
                                 namespace=deploy_options.namespace,
                                 profile=deploy_options.profile):
        cmd = "{} -n {} create secret generic {} --from-literal=session_secret={}"\
Ejemplo n.º 5
0
n the OCP case, it will be integrated automatically with OCP oauth.
'''

import os
import sys
from time import sleep
import secrets
import utils
import deployment_options

deploy_options = deployment_options.load_deployment_options()
utils.verify_build_directory(deploy_options.namespace)

if deploy_options.target != "oc-ingress":
    CMD_BIN = utils.get_kubectl_command(
        target=deploy_options.target
    )
    OLM_NS = 'olm'
    CAT_SRC = 'operatorhubio-catalog'
else:
    CMD_BIN = 'oc'
    OLM_NS = 'openshift-marketplace'
    CAT_SRC = 'community-operators'

def deploy_oauth_reqs():
    '''oauth Integration in OCP'''
    ## Token generation for session_secret
    session_secret = secrets.token_hex(43)
    secret_name = 'prometheus-k8s-proxy'
    if not utils.check_if_exists(
            k8s_object='secret',
def main():
    deploy_options = deployment_options.load_deployment_options()
    is_cluster_info_ready(kubectl_cmd=utils.get_kubectl_command(namespace=deploy_options.namespace))