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 18, 2018
1 parent 5167070 commit cca348b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
25 changes: 19 additions & 6 deletions scenarios/kubernetes_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,27 @@ 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).
job_type = os.getenv('JOB_TYPE')
if job_type == 'batch':
suffix = 'batch-%s' % os.getenv('BUILD_NUMBER', 0)
elif job_type == 'presubmit':
suffix = '%s' % os.getenv('PULL_NUMBER', 0)
else:
suffix = '%s' % os.getenv('BUILD_NUMBER', 0)
if len(suffix) > 10:
suffix = hashlib.md5(suffix).hexdigest()[:10]
job_hash = hashlib.md5(os.getenv('JOB_NAME', '')).hexdigest()[:5]
return 'e2e-%s-%s' % (suffix, job_hash)


# TODO(krzyzacy): Move this into kubetest
Expand Down Expand Up @@ -515,7 +528,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 cca348b

Please sign in to comment.