Skip to content

Commit

Permalink
Add a script for running e2e tests for kubetest2 gke deployer
Browse files Browse the repository at this point in the history
  • Loading branch information
chizhg committed Jul 19, 2021
1 parent a3bc949 commit 6dad142
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 9 deletions.
80 changes: 80 additions & 0 deletions kubetest2-gke/ci-tests/buildupdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Copyright 2021 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}" &> /dev/null || exit 1

make install
make install-deployer-gke

# currently equivalent to /home/prow/go/src/github.com/kubernetes/kubernetes
REPO_ROOT="${REPO_ROOT}/../../kubernetes/kubernetes"

function main() {
CLUSTER_TOPOLOGY="sc"
BUILD_STRATEGY="make"

while [ $# -gt 0 ]; do
case "$1" in
--cluster-topology)
shift
CLUSTER_TOPOLOGY="$1"
;;
--build-strategy)
shift
BUILD_STRATEGY="$1"
;;
*)
echo "Invalid argument"
exit 1
;;
esac
shift
done

NUM_CLUSTERS=0
case "${CLUSTER_TOPOLOGY}" in
"sc")
NUM_CLUSTERS=1
;;
"mc")
NUM_CLUSTERS=2
;;
*)
echo "Invalid cluster topology ${CLUSTER_TOPOLOGY}"
exit 1
;;
esac

kubetest2 gke \
-v 2 \
--repo-root "$REPO_ROOT" \
--strategy "${BUILD_STRATEGY}" \
--stage gs://kubernetes-jenkins/ci \
--num-clusters "${NUM_CLUSTERS}" \
--num-nodes 1 \
--zone us-central1-c,us-west1-a,us-east1-b \
--build \
--up \
--down
}

main "$@"
21 changes: 12 additions & 9 deletions kubetest2-gke/deployer/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,22 @@ func (d *Deployer) CreateClusters() error {
totalTryCount := math.Max(len(d.Regions), len(d.Zones))
for retryCount := 0; retryCount < totalTryCount; retryCount++ {
d.retryCount = retryCount
if err := d.tryCreateClusters(retryCount); err != nil {
err, shouldRetry := d.tryCreateClusters(retryCount)
if !shouldRetry {
return err
}
}

return nil
}

func (d *Deployer) tryCreateClusters(retryCount int) error {
if err := d.CreateSubnets(); err != nil {
return err
func (d *Deployer) tryCreateClusters(retryCount int) (err error, shouldRetry bool) {
shouldRetry = false
if err = d.CreateSubnets(); err != nil {
return
}
if err := d.SetupNetwork(); err != nil {
return err
if err = d.SetupNetwork(); err != nil {
return
}

eg := new(errgroup.Group)
Expand All @@ -113,23 +115,24 @@ func (d *Deployer) tryCreateClusters(retryCount int) error {
}
}

if err := eg.Wait(); err != nil {
if err = eg.Wait(); err != nil {
// If the error is retryable and it is not the last region/zone that
// can be retried, perform cleanups in the background and retry
// cluster creation in the next available region/zone.
if d.isRetryableError(err) && retryCount != d.totalTryCount-1 {
shouldRetry = true
go func() {
d.DeleteClusters(retryCount)
if err := d.DeleteSubnets(retryCount); err != nil {
log.Printf("Warning: error encountered deleting subnets: %v", err)
}
}()
} else {
return fmt.Errorf("error creating clusters: %v", err)
err = fmt.Errorf("error creating clusters: %v", err)
}
}

return nil
return
}

// isRetryableError checks if the error happens during cluster creation can be potentially solved by retrying or not.
Expand Down

0 comments on commit 6dad142

Please sign in to comment.