Exemplo n.º 1
0
def configure_kubernetes_master():
    """Configure the kubernetes master.

    Sets up the master node and stores the necessary settings inside the node
    instance's runtime properties, which are required by worker nodes in order
    to join the kubernetes cluster.

    """
    ctx.logger.info('Setting up kubernetes master node')
    prepare_kubernetes_script()

    # FIXME Re-think this.
    client = MistConnectionClient().client
    machine = MistConnectionClient().machine

    # Token for secure master-worker communication.
    token = '%s.%s' % (random_string(length=6), random_string(length=16))
    ctx.instance.runtime_properties['master_token'] = token.lower()

    # Store kubernetes dashboard credentials in runtime properties.
    ctx.instance.runtime_properties.update({
        'auth_user':
        ctx.node.properties['auth_user'],
        'auth_pass':
        ctx.node.properties['auth_pass'] or random_string(10),
    })

    ctx.logger.info('Installing kubernetes on master node')

    # Prepare script parameters.
    script_params = "-u '%s' " % ctx.instance.runtime_properties['auth_user']
    script_params += "-p '%s' " % ctx.instance.runtime_properties['auth_pass']
    script_params += "-t '%s' " % ctx.instance.runtime_properties[
        'master_token']  # NOQA
    script_params += "-r 'master'"

    # Run the script.
    script = client.run_script(
        script_id=ctx.instance.runtime_properties['script_id'],
        su=True,
        machine_id=machine.id,
        cloud_id=machine.cloud.id,
        script_params=script_params,
    )
    ctx.instance.runtime_properties['job_id'] = script['job_id']
Exemplo n.º 2
0
def configure_kubernetes_worker():
    """Configure a new kubernetes node.

    Configures a new worker node and connects it to the kubernetes master.

    """
    # Get master node from relationships schema.
    master = ctx.instance.relationships[0]._target.instance
    ctx.instance.runtime_properties.update({
        'script_id':
        master.runtime_properties.get('script_id', ''),
        'master_ip':
        master.runtime_properties.get('master_ip', ''),
        'master_token':
        master.runtime_properties.get('master_token', ''),
    })

    ctx.logger.info('Setting up kubernetes worker')
    prepare_kubernetes_script()

    # FIXME Re-think this.
    client = MistConnectionClient().client
    machine = MistConnectionClient().machine

    ctx.logger.info('Configuring kubernetes node')

    # Prepare script parameters.
    script_params = "-m '%s' " % ctx.instance.runtime_properties['master_ip']
    script_params += "-t '%s' " % ctx.instance.runtime_properties[
        'master_token']  # NOQA
    script_params += "-r 'node'"

    # Run the script.
    script = client.run_script(
        script_id=ctx.instance.runtime_properties['script_id'],
        su=True,
        machine_id=machine.id,
        cloud_id=machine.cloud.id,
        script_params=script_params,
    )
    ctx.instance.runtime_properties['job_id'] = script['job_id']