Processing ${default_secret} as ${SECRET_NAME}"
            kubectl get secret ${default_secret} -n default -o yaml --export | sed "s/name: default-/name: $NAMESPACE-/g" | kubectl -n $NAMESPACE apply -f -

            echo "${INDENT}- name: $SECRET_NAME" >> $DAEMONSET_FILE
        done
    else
        sed -i.bak -e "s|\( *image: \)sysdig/${AGENT_STRING}|\1sysdig/${AGENT_STRING}:${AGENT_VERSION}|g" $DAEMONSET_FILE
    fi
    # Add label for Sysdig instance
    if [! -z "$SYSDIG_INSTANCE_NAME" ]; then
       sed -i.bak -e's/^\( *\)labels:$/&\
\1  sysdig-instance: '$SYSDIG_INSTANCE_NAME'/' $DAEMONSET_FILE
    fi
    rm -f $DAEMONSET_FILE.bak

    echo -e "    new_k8s: true" >> $CONFIG_FILE
    kubectl apply -f $CONFIG_FILE --namespace=$NAMESPACE

    echo "* Deploying the sysdig agent"
    kubectl apply -f $DAEMONSET_FILE --namespace=$NAMESPACE
}

function remove_agent {
    set +e

    echo "* Deleting the Sysdig agent and configurings from namespace $NAMESPACE"

    echo "* Deleting the sysdig-agent daemonset"
    kubectl delete daemonset sysdig-agent --namespace=$NAMESPACE

    echo "* Deleting the sysdig-agent configmap"
    kubectl delete configmap sysdig-agent --namespace=$NAMESPACE

    echo "* Deleting the sysdig-agent serviceacccount"
    kubectl delete serviceaccount -n default sysdig-agent --namespace=$NAMESPACE

    if [ $OPENSHIFT -eq 0 ]; then
        echo "* deleting the sysdig-agent clusterrolebinding"
        kubectl delete clusterrolebinding sysdig-agent --namespace=$NAMESPACE
    else
        echo "* Removing cluster role and security constraints"
        oc adm policy remove-cluster-role-from-user cluster-reader -n $NAMESPACE -z sysdig-agent
        oc adm policy remove-scc-from-user privileged -n $NAMESPACE -z sysdig-agent
    fi

    echo "* Deleting the sysdig-agent secret"
    kubectl delete secret sysdig-agent --namespace=$NAMESPACE

    set -e
}


if [[ ${#} -eq 0 ]]; then
    echo "ERROR: Sysdig Access Key & Collector are mandatory, use -h | --help for $(basename ${0}) Usage"
    exit 1
fi

# Setting the default value for NAMESPACE to be ibm-observe
# Will be over-ridden if the -ns|--namespace flag is provided
NAMESPACE="ibm-observe"
REMOVE_AGENT=0
ENABLE_PROMETHEUS=1
OPENSHIFT=0
AGENT_VERSION="latest"
AWS=0

while [[ ${#} > 0 ]]
do
key="${1}"

case ${key} in
    -a|--access_key)
        if is_valid_value "${2}"; then
            ACCESS_KEY="${2}"
        else
            echo "ERROR: no value provided for access_key option, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -t|--tags)
        if is_valid_value "${2}"; then
            TAGS="${2}"
        else
            echo "ERROR: no value provided for tags option, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -c|--collector)
        if is_valid_value "${2}"; then
            COLLECTOR="${2}"
        else
            echo "ERROR: no value provided for collector endpoint option, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -cp|--collector_port)
        if is_valid_value "${2}"; then
            COLLECTOR_PORT="${2}"
        else
            echo "ERROR: no value provided for collector port option, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -s|--secure)
        if is_valid_value "${2}"; then
            SECURE="${2}"
        else
            echo "ERROR: no value provided for connection security option, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -cc|--check_certificate)
        if is_valid_value "${2}"; then
            CHECK_CERT="${2}"
        else
            echo "ERROR: no value provided for SSL check certificate option, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -ns|--namespace|--project)
        if is_valid_value "${2}"; then
            NAMESPACE="${2}"
        else
            echo "ERROR: no value provided for namespace, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -ac|--additional_conf)
        if is_valid_value "${2}"; then
            ADDITIONAL_CONF="${2}"
        else
            echo "ERROR: no value provided for additional conf option, use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -np|--no-prometheus)
        ENABLE_PROMETHEUS=0
        ;;
    -sn|--sysdig_instance_name)
        if is_valid_value "${2}"; then
            SYSDIG_INSTANCE_NAME="${2}"
        else
            echo "ERROR: no value provided for sysdig instance name use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -av|--agent-version)
	if is_valid_value "${2}"; then
            AGENT_VERSION="${2}"
        else
            echo "ERROR: no value provided for agent version use -h | --help for $(basename ${0}) Usage"
            exit 1
        fi
        shift
        ;;
    -op|--openshift)
        OPENSHIFT=1
        ;;
    -as|--agent-slim)
        AGENT_SLIM=1
        ;;
    -aws|--aws)
        AWS=1
        ;;
    -r|--remove)
        REMOVE_AGENT=1
        ;;
    -h|--help)
        help
        exit 1
        ;;
    *)
        echo "ERROR: Invalid option: ${1}, use -h | --help for $(basename ${0}) Usage"
        exit 1
        ;;
esac
shift
done

CMD_PREF=""
if [ $(id -u)!= 0 ]; then
    if command -v sudo  > /dev/null 2>&1; then
        CMD_PREF="sudo "
    fi
fi

if [ $REMOVE_AGENT -eq 1 ]; then
    remove_agent
    exit 0
fi

if [ -z $ACCESS_KEY  ]; then
    echo "ERROR: Sysdig Access Key argument is mandatory, use -h | --help for $(basename ${0}) Usage"
    exit 1
fi


if [ -z $COLLECTOR ]; then
    echo "ERROR: Sysdig Collector argument is mandatory, use -h | --help for $(basename ${0}) Usage"
    exit 1
fi

echo "* Detecting operating system"

ARCH=$(uname -m)
PLATFORM=$(uname)
if [[! $ARCH = *86 ]] && [! $ARCH = "x86_64" ] && [! $ARCH = "s390x" ]; then
    unsupported
fi

if [ -f /etc/debian_version ]; then
    if [ -f /etc/lsb-release ]; then
       . /etc/lsb-release
        DISTRO=$DISTRIB_ID
        VERSION=${DISTRIB_RELEASE%%.*}
    else
        DISTRO="Debian"
        VERSION=$(cat /etc/debian_version | cut -d'.' -f1)