Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.
Section
Painel
Deck of Cards
idTools
Card
id01
labelenvs

Listar todas as topologias de um cluster:

Bloco de código
#!/bin/bash
set -e
kubectl get ns --no-headers -L UpdaterDesiredVersion,BaseVersion,Owner,External_id,Topology_id,Extra -l External_id --sort-by=.metadata.creationTimestamp

Card
id02
labelns

Mudar o contexto de um NS dentro do KUBECONFIG

Bloco de código
#!/bin/bash

echo ""
if [ ! "$1" == "" ]; then
        kubectl config set-context --current --namespace=$1
fi

echo "+--------------------------------------------"
echo "| Cluster: "$(kubectl config view --minify -o json | jq -r '.contexts[0].context.cluster')
echo "| Namespace: "$(kubectl config view --minify -o json | jq -r '.contexts[0].context.namespace')
echo "+--------------------------------------------"

echo ""

Card
id03
labelalias

Utilizados como encurtador de comandos. Adicionar no ~/.bash do seu terminal.

Bloco de código
alias k="kubectl"

alias po="kubectl get pods -o wide"
alias ing="kubectl get ing"
alias svc="kubectl get svc"
alias delpo="kubectl delete pods --force --grace-period=0"

alias kk="kubectl2"

Card
id04
labelci-smartsre

Aplicação para execução do CI das soluções SmartSRE


Informações

exportar o DRONE_TOKEN (Pegar na ferramenta do DRONE) antes de executar a ferramenta.

Bloco de código
#!/bin/bash

THIS=$(basename $0)
NOW=$(date '+%Y%m%d')

function usage() {
    echo -e "$THIS 0.2\t\nAuthor: Renato Campos <[email protected]>\t"
    echo -e "\n$THIS [option] [-j backoffice|taf|release|sistemico]" 
    echo -e "\nOptions:"
    echo -e "\t-r, build rpo "
    echo -e "\t-i, build image"
    echo -e "\t-u, flag upddistr"
    echo -e "\t-v, new version (12.1.2310). If empty, build version will be 12.1.2210"
    echo -e "\n$THIS -h (shows this help)"
    echo -e "If used without options, this script will return fail\n"
    echo -e "Remember export DRONE_TOKEN in your environment\n"

    exit -1
}

function getJobId() {
	DroneAPI=$1
	numberBuild=$2

	curl --request GET -s \
		 --url "$DroneAPI/builds/$numberBuild" \
		 --header 'Authorization: Bearer '$DRONE_TOKEN \
		 --header 'Content-Type: application/json' | jq -r '. | select( .status == "running")' | jq -r .number
}

function getJobSTEP() {
	DroneAPI=$1
	numberBuild=$2
	
	curl --request GET -s \
		 --url "$DroneAPI/builds/$numberBuild" \
		 --header 'Authorization: Bearer '$DRONE_TOKEN \
		 --header 'Content-Type: application/json' | jq -r '.stages | .[].steps | .[] | select ( .status == "running" )' | jq -r .name
}

function waitProcJob(){
	DroneAPI=$1
	numberBuild=$2

	echo "Job $numberBuild started in $DroneAPI"
	while [[ "$(getJobId $DroneAPI $numberBuild)" != "" ]]; do
		echo "Job $numberBuild - STEP: "$(getJobSTEP $DroneAPI $numberBuild)" - running..." 
		sleep 10
	done
}

function buildWithParameters(){
	DroneAPI=$1
	param=$2

	curl --request POST -s \
	     --url "$DroneAPI/builds?$param" \
 		 --header 'Authorization: Bearer '$DRONE_TOKEN \
		 --header 'Content-Type: application/json' | jq -r .number
}

function gerarpo() {
	branch=$1
	release=$2

	DroneAPI="https://drone.engpro.totvs.com.br/api/repos/smarterp/pipeline-rpo"
	param="branch=$branch&RELEASE=$release&BUILDIMAGE=false"

	numberBuild=$(buildWithParameters $DroneAPI $param)
	sleep 10

	waitProcJob $DroneAPI $numberBuild
}


function geraimage() {
	branch=$1
	release=$2
	upddistr=$3

	DroneAPI="https://drone.engpro.totvs.com.br/api/repos/smarterp/pipeline-imagem"
	param="branch=$branch&RELEASE=$release&UPDDISTR=$upddistr&GERA_IMAGEM=true&GERA_CHART=true"

	numberBuild=$(buildWithParameters $DroneAPI $param)
	sleep 10

	waitProcJob $DroneAPI $numberBuild
}


# check whether user had supplied -h or --help . If yes display usage
if [[ ( $# == "--help") ||  $# == "-h" ]] ;then
    usage
fi

if [ $# -le 1 ]; then
    usage
fi

if [ $# -ge 2 ]; then
    rpo="false"
    image="false"
	upddistr="false"
	JOB=""
	VERSION="12.1.2210"

    while getopts ": hriu j:" opt; do
        case $opt in
            "h") usage;;
            "r") rpo="true" ;;
            "i") image="true" ;;
			"u") upddistr="true" ;;
			"v") VERSION="12.1.2310" ;;
			"j") JOB=${OPTARG} # defina $ JOB para o valor especificado.
			;;
		    :) 
		       echo "Erro: - $ {OPTARG} requer um argumento."
		       usage
		       ;;

		    *)
		       usage
		       ;;
        esac
    done


    if [ "$rpo" == "true" ]; then
    	echo "Starting CI SmartAPI - RPO: $JOB - $VERSION"
    	gerarpo $JOB $VERSION
    fi

    if [ "$image" == "true" ]; then

        if [ "$upddistr" == "true" ]; then
    		echo "Starting CI SmartBuild - IMAGE: $JOB - with UPDDISTR"
		else
    		echo "Starting CI SmartBuild - IMAGE: $JOB - without UPDDISTR"
    	fi

		geraimage $JOB $VERSION $upddistr
    fi

	echo "SmartERP-CI terminate. See file /tmp/ci-smarterp-xxxx.txt"
fi

exit 0
Section
Painel
borderStylesolid
titleBase de Conhecimento

Page Tree
expandCollapseAlltrue
rootSRE - Ferramentas de trabalho
searchBoxtrue