diff --git a/Jenkinsfile b/Jenkinsfile index 24f0e3fadc..cabc82ad2f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,4 @@ -GKERegion="us-central1-a" +region="us-central1-a" testUrlPrefix="https://percona-jenkins-artifactory-public.s3.amazonaws.com/cloud-psmdb-operator" tests=[] @@ -6,21 +6,19 @@ void createCluster(String CLUSTER_SUFFIX) { withCredentials([string(credentialsId: 'GCP_PROJECT_ID', variable: 'GCP_PROJECT'), file(credentialsId: 'gcloud-key-file', variable: 'CLIENT_SECRET_FILE')]) { sh """ export KUBECONFIG=/tmp/$CLUSTER_NAME-${CLUSTER_SUFFIX} - export USE_GKE_GCLOUD_AUTH_PLUGIN=True - source $HOME/google-cloud-sdk/path.bash.inc ret_num=0 while [ \${ret_num} -lt 15 ]; do ret_val=0 gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE gcloud config set project $GCP_PROJECT - gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $GKERegion --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $GKERegion --quiet || true - gcloud container clusters create --zone $GKERegion $CLUSTER_NAME-${CLUSTER_SUFFIX} --cluster-version=1.24 --machine-type=n1-standard-4 --preemptible --num-nodes=3 --network=jenkins-vpc --subnetwork=jenkins-${CLUSTER_SUFFIX} --no-enable-autoupgrade --cluster-ipv4-cidr=/21 --labels delete-cluster-after-hours=6 --enable-ip-alias --workload-pool=cloud-dev-112233.svc.id.goog && \ + gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $region --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $region --quiet || true + gcloud container clusters create --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX} --cluster-version=1.25 --machine-type=n1-standard-4 --preemptible --num-nodes=3 --network=jenkins-vpc --subnetwork=jenkins-${CLUSTER_SUFFIX} --no-enable-autoupgrade --cluster-ipv4-cidr=/21 --labels delete-cluster-after-hours=6 --enable-ip-alias --workload-pool=cloud-dev-112233.svc.id.goog && \ kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user jenkins@"$GCP_PROJECT".iam.gserviceaccount.com || ret_val=\$? if [ \${ret_val} -eq 0 ]; then break; fi ret_num=\$((ret_num + 1)) done if [ \${ret_num} -eq 15 ]; then - gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $GKERegion --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $GKERegion --quiet || true + gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $region --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $region --quiet || true exit 1 fi """ @@ -31,8 +29,6 @@ void shutdownCluster(String CLUSTER_SUFFIX) { withCredentials([string(credentialsId: 'GCP_PROJECT_ID', variable: 'GCP_PROJECT'), file(credentialsId: 'gcloud-key-file', variable: 'CLIENT_SECRET_FILE')]) { sh """ export KUBECONFIG=/tmp/$CLUSTER_NAME-${CLUSTER_SUFFIX} - export USE_GKE_GCLOUD_AUTH_PLUGIN=True - source $HOME/google-cloud-sdk/path.bash.inc gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE gcloud config set project $GCP_PROJECT for namespace in \$(kubectl get namespaces --no-headers | awk '{print \$1}' | grep -vE "^kube-|^openshift" | sed '/-operator/ s/^/1-/' | sort | sed 's/^1-//'); do @@ -44,7 +40,7 @@ void shutdownCluster(String CLUSTER_SUFFIX) { kubectl delete pods --all -n \$namespace --force --grace-period=0 || true done kubectl get svc --all-namespaces || true - gcloud container clusters delete --zone $GKERegion $CLUSTER_NAME-${CLUSTER_SUFFIX} + gcloud container clusters delete --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX} """ } } @@ -52,9 +48,7 @@ void shutdownCluster(String CLUSTER_SUFFIX) { void deleteOldClusters(String FILTER) { withCredentials([string(credentialsId: 'GCP_PROJECT_ID', variable: 'GCP_PROJECT'), file(credentialsId: 'gcloud-key-file', variable: 'CLIENT_SECRET_FILE')]) { sh """ - if [ -f $HOME/google-cloud-sdk/path.bash.inc ]; then - export USE_GKE_GCLOUD_AUTH_PLUGIN=True - source $HOME/google-cloud-sdk/path.bash.inc + if gcloud --version > /dev/null 2>&1; then gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE gcloud config set project $GCP_PROJECT for GKE_CLUSTER in \$(gcloud container clusters list --format='csv[no-heading](name)' --filter="$FILTER"); do @@ -70,7 +64,7 @@ void deleteOldClusters(String FILTER) { break fi done - gcloud container clusters delete --async --zone $GKERegion --quiet \$GKE_CLUSTER || true + gcloud container clusters delete --async --zone $region --quiet \$GKE_CLUSTER || true done fi """ @@ -208,7 +202,6 @@ void runTest(Integer TEST_ID) { export DEBUG_TESTS=1 fi export KUBECONFIG=/tmp/$CLUSTER_NAME-$clusterSuffix - source $HOME/google-cloud-sdk/path.bash.inc ./e2e-tests/$testName/run """ } @@ -278,35 +271,35 @@ pipeline { } } } - sh ''' - sudo yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm || true - sudo percona-release enable-only tools - sudo yum install -y | true + sh """ + sudo curl -s -L -o /usr/local/bin/kubectl https://dl.k8s.io/release/\$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl + kubectl version --client --output=yaml - if [ ! -d $HOME/google-cloud-sdk/bin ]; then - rm -rf $HOME/google-cloud-sdk - curl https://sdk.cloud.google.com | bash - fi + curl -fsSL https://get.helm.sh/helm-v3.12.3-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm - source $HOME/google-cloud-sdk/path.bash.inc - gcloud components install alpha - gcloud components install kubectl + sudo sh -c "curl -s -L https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64 > /usr/local/bin/yq" + sudo chmod +x /usr/local/bin/yq - curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash - curl -s -L https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz \ - | sudo tar -C /usr/local/bin --strip-components 1 --wildcards -zxvpf - '*/oc' + sudo sh -c "curl -s -L https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64 > /usr/local/bin/jq" + sudo chmod +x /usr/local/bin/jq - curl -s -L https://github.com/mitchellh/golicense/releases/latest/download/golicense_0.2.0_linux_x86_64.tar.gz \ - | sudo tar -C /usr/local/bin --wildcards -zxvpf - + sudo tee /etc/yum.repos.d/google-cloud-sdk.repo << EOF +[google-cloud-cli] +name=Google Cloud CLI +baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64 +enabled=1 +gpgcheck=1 +repo_gpgcheck=0 +gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg +EOF + sudo yum install -y google-cloud-cli google-cloud-cli-gke-gcloud-auth-plugin + + curl -sL https://github.com/mitchellh/golicense/releases/latest/download/golicense_0.2.0_linux_x86_64.tar.gz | sudo tar -C /usr/local/bin -xzf - golicense + """ - sudo sh -c "curl -s -L https://github.com/mikefarah/yq/releases/download/v4.34.1/yq_linux_amd64 > /usr/local/bin/yq" - sudo chmod +x /usr/local/bin/yq - sudo sh -c "curl -s -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 > /usr/local/bin/jq" - sudo chmod +x /usr/local/bin/jq - ''' withCredentials([file(credentialsId: 'cloud-secret-file', variable: 'CLOUD_SECRET_FILE')]) { sh ''' - cp $CLOUD_SECRET_FILE ./e2e-tests/conf/cloud-secret.yml + cp $CLOUD_SECRET_FILE e2e-tests/conf/cloud-secret.yml ''' } deleteOldClusters("jen-psmdb-$CHANGE_ID") @@ -498,9 +491,8 @@ pipeline { } deleteOldClusters("$CLUSTER_NAME") sh """ - sudo docker system prune -fa - sudo rm -rf ./* - sudo rm -rf $HOME/google-cloud-sdk + sudo docker system prune --volumes -af + sudo rm -rf * """ deleteDir() }