Skip to content

Commit

Permalink
Change cluster naming convention for e2e CI/PR jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamjvs committed Apr 16, 2018
1 parent 5167070 commit cbb1934
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 13 additions & 6 deletions scenarios/kubernetes_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,21 @@ def start(self, args):
check_env(env, self.command, *args)


def cluster_name(cluster, build):
def cluster_name(cluster):
"""Return or select a cluster name."""
if cluster:
return cluster
# Create a suffix based on the build number. Append a random string to it for
# avoiding potential conflicts across different jobs' runs (see issue #7592).
suffix = build if len(build) < 10 else hashlib.md5(build).hexdigest()[:10]
return 'e2e-%s-%s' % (suffix, os.urandom(3).encode('hex'))
# Create a suffix based on the build number and job name.
# This ensures no conflict across runs of different jobs (see #7592).
# For PR jobs, we use PR number instead of build number to ensure the
# name is constant across different runs of the presubmit on the PR.
# This helps clean potentially leaked resources from earlier run that
# could've got evicted midway (see #7673).
suffix = os.getenv('BUILD_NUMBER', 0)
suffix = os.getenv('PULL_NUMBER', suffix)
suffix = suffix if len(suffix) <= 10 else hashlib.md5(suffix).hexdigest()[:10]
suffix = suffix + '-' + hashlib.md5(os.getenv('JOB_NAME', '')).hexdigest()[:5]
return 'e2e-%s' % suffix


# TODO(krzyzacy): Move this into kubetest
Expand Down Expand Up @@ -515,7 +522,7 @@ def main(args):
if args.provider:
runner_args.append('--provider=%s' % args.provider)

cluster = cluster_name(args.cluster, os.getenv('BUILD_NUMBER', 0))
cluster = cluster_name(args.cluster)
runner_args.append('--cluster=%s' % cluster)
runner_args.append('--gcp-network=%s' % cluster)
runner_args.extend(args.kubetest_args)
Expand Down
9 changes: 6 additions & 3 deletions scenarios/kubernetes_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def test_name_filled(self):
"""Return the cluster name if set."""
name = 'foo'
build = '1984'
actual = kubernetes_e2e.cluster_name(name, build)
os.environ['BUILD_NUMBER'] = build
actual = kubernetes_e2e.cluster_name(name)
self.assertTrue(actual)
self.assertIn(name, actual)
self.assertNotIn(build, actual)
Expand All @@ -118,15 +119,17 @@ def test_name_empty_short_build(self):
"""Return the build number if name is empty."""
name = ''
build = '1984'
actual = kubernetes_e2e.cluster_name(name, build)
os.environ['BUILD_NUMBER'] = build
actual = kubernetes_e2e.cluster_name(name)
self.assertTrue(actual)
self.assertIn(build, actual)

def test_name_empty_long_build(self):
"""Return a short hash of a long build number if name is empty."""
name = ''
build = '0' * 63
actual = kubernetes_e2e.cluster_name(name, build)
os.environ['BUILD_NUMBER'] = build
actual = kubernetes_e2e.cluster_name(name)
self.assertTrue(actual)
self.assertNotIn(build, actual)
if len(actual) > 32: # Some firewall names consume half the quota
Expand Down

0 comments on commit cbb1934

Please sign in to comment.