aboutsummaryrefslogtreecommitdiffstats
path: root/cloudify/scripts/onap/configure_docker_secret_workaround.py
blob: 6e9deff059fedeff21de13239be141c78a8a62c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from fabric.api import run

from cloudify import ctx
from cloudify.exceptions import NonRecoverableError


def _retrieve_namespace():
    namespace = ctx.node.properties.get(
        'namespace',
        ctx.node.properties
            .get('options', {})
            .get('namespace', None)
    )

    if not namespace:
        raise NonRecoverableError(
            'Namespace is not defined (node={})'.format(ctx.node.name)
        )

    return namespace


def configure_secret():
    namespace = _retrieve_namespace()
    ctx.logger.info(
        'Configuring docker secrets for namespace: {0}'.format(namespace)
    )

    command = 'kubectl create secret ' \
              'docker-registry onap-docker-registry-key ' \
              '--docker-server=nexus3.onap.org:10001 ' \
              '--docker-username=docker ' \
              '--docker-password=docker ' \
              '--docker-email=email@email.com ' \
              '--namespace={0}'.format(namespace)

    ctx.logger.info('Command "{0}" will be executed'.format(command))
    run(command)

    ctx.logger.info('Docker secrets configured successfully')