.. versionadded:: 2016.3.0

    Set label to the current node

    CLI Example:

    .. code-block:: bash

        salt '*' k8s.label_present hw/disktype ssd

        salt '*' k8s.label_present hw/disktype ssd kube-node.cluster.local http://kube-master.cluster.local

def label_present(name, value, node=None, apiserver_url=None):
    '''
    .. versionadded:: 2016.3.0

    Set label to the current node

    CLI Example:

    .. code-block:: bash

        salt '*' k8s.label_present hw/disktype ssd

        salt '*' k8s.label_present hw/disktype ssd kube-node.cluster.local http://kube-master.cluster.local

    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}

    # Get salt minion ID
    node = _guess_node_id(node)
    # Try to get kubernetes master
    apiserver_url = _guess_apiserver(apiserver_url)
    if apiserver_url is None:
        return False

    # Get all labels
    labels = _get_labels(node, apiserver_url)

    if name not in labels:
        # This is a new label
        ret['changes'] = {name: value}
        labels[name] = str(value)
        res = _set_labels(node, apiserver_url, labels)
        if res.get('status') == 409:
            # there is an update during operation, need to retry
            log.debug("Got 409, will try later")
            ret['changes'] = {}
            ret['comment'] = "Could not create label {0}, please retry".format(name)
        else:
            ret['comment'] = "Label {0} created".format(name)
    elif labels.get(name) != str(value):
        # This is a old label and we are going to edit it
        ret['changes'] = {name: str(value)}
        labels[name] = str(value)
        res = _set_labels(node, apiserver_url, labels)
        if res.get('status') == 409:
            # there is an update during operation, need to retry
            log.debug("Got 409, will try later")
            ret['changes'] = {}
            ret['comment'] = "Could not update label {0}, please retry".format(name)
        else:
            ret['comment'] = "Label {0} updated".format(name)
    else:
        # This is a old label and it has already the wanted value
        ret['comment'] = "Label {0} already set".format(name)

    return ret