Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable unique ephemeral worker by default #1067

Merged
merged 4 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/test/groovy/WithNodeStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WithNodeStepTests extends ApmBasePipelineTest {
}
printCallStack()
assertTrue(isOK)
assertTrue(assertMethodCallContainsPattern('node', 'foo && extra/'))
assertFalse(assertMethodCallContainsPattern('node', 'foo && extra/'))
assertTrue(assertMethodCallOccurrences('ws', 0))
assertJobStatusSuccess()
}
Expand All @@ -67,6 +67,33 @@ class WithNodeStepTests extends ApmBasePipelineTest {
assertJobStatusSuccess()
}

@Test
void test_with_forced_worker() throws Exception {
helper.registerAllowedMethod('isStaticWorker', [Map.class], { return false })
def isOK = false
script.call(labels: 'foo', forceWorker: true) {
isOK = true
}
printCallStack()
assertTrue(isOK)
assertTrue(assertMethodCallContainsPattern('node', 'foo && extra/'))
assertJobStatusSuccess()
}

@Test
void test_with_forced_static_worker() throws Exception {
helper.registerAllowedMethod('isStaticWorker', [Map.class], { return true })
def isOK = false
script.call(labels: 'arm', forceWorker: true) {
isOK = true
}
printCallStack()
assertTrue(isOK)
assertTrue(assertMethodCallContainsPattern('node', 'arm'))
assertFalse(assertMethodCallContainsPattern('node', 'extra/'))
assertJobStatusSuccess()
}

@Test
void test_with_forced_workspace() throws Exception {
helper.registerAllowedMethod('isStaticWorker', [ Map.class ], { return false })
Expand Down
10 changes: 6 additions & 4 deletions vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1315,8 +1315,8 @@ Wrapper to interact with the gsutil command line. It returns the stdout output.
Check if the author of a GitHub comment has admin or write permissions in the repository.

```
if(!hasCommentAuthorWritePermissions(repoName: "elastic/beats", commentId: env.GT_COMMENT_ID)){
error("Only Elasticians can do this action.")
if(!hasCommentAuthorWritePermissions(repoName: "elastic/kibana", commentId: env.GT_COMMENT_ID)){
error("Only Elasticians can deploy Docker images")
}
```

Expand Down Expand Up @@ -2917,15 +2917,16 @@ Wrap the node call for three reasons:
}

// Use ephemeral worker with a sleep of up to 100 seconds and with a specific workspace.
withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true){
withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true, forceWorker: true){
// block
}
```

* labels: what's the labels to be used. Mandatory
* sleepMin: whether to sleep and for how long at least. Optional.
* sleepMax: whether to sleep and for how long maximum. Optional.
* forceWorkspace: whether to allocate a new unique workspace. Optional.
* forceWorker: whether to allocate a new unique ephemeral worker. Optional. Default false
* forceWorkspace: whether to allocate a new unique workspace. Optional. Default false

## withNpmrc
Wrap the npmrc token
Expand Down Expand Up @@ -3015,3 +3016,4 @@ writeVaultSecret(secret: 'secret/apm-team/ci/temp/github-comment', data: ['secre

* secret: Name of the secret on the the vault root path. Mandatory
* data: What's the data to be written. Mandatory

8 changes: 6 additions & 2 deletions vars/withNode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Wrap the node call for three reasons:
}

// Use ephemeral worker with a sleep of up to 100 seconds and with a specific workspace.
withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true){
withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true, forceWorker: true){
...
}
*/
Expand All @@ -36,13 +36,17 @@ def call(Map args = [:], Closure body) {
def sleepMax = args.get('sleepMax', 0)
def labels = args.containsKey('labels') ? args.labels : error('withNode: labels parameter is required.')
def forceWorkspace = args.get('forceWorkspace', false)
def forceWorker = args.get('forceWorker', false)
def uuid = UUID.randomUUID().toString()

// Sleep to smooth the ram up with the provisioner
sleep(randomNumber(min: sleepMin, max: sleepMax))

// In case of ephemeral workers then use the uuid
def newLabels = isStaticWorker(labels: labels) ? labels : (labels?.trim() ? "${labels} && extra/${uuid}" : "extra/${uuid}")
def newLabels = labels
if (forceWorker) {
newLabels = isStaticWorker(labels: labels) ? labels : (labels?.trim() ? "${labels} && extra/${uuid}" : "extra/${uuid}")
}
log(level: 'INFO', text: "Allocating a worker with the labels '${newLabels}'.")

node("${newLabels}") {
Expand Down
5 changes: 3 additions & 2 deletions vars/withNode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ Wrap the node call for three reasons:
}

// Use ephemeral worker with a sleep of up to 100 seconds and with a specific workspace.
withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true){
withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true, forceWorker: true){
// block
}
```

* labels: what's the labels to be used. Mandatory
* sleepMin: whether to sleep and for how long at least. Optional.
* sleepMax: whether to sleep and for how long maximum. Optional.
* forceWorkspace: whether to allocate a new unique workspace. Optional.
* forceWorker: whether to allocate a new unique ephemeral worker. Optional. Default false
* forceWorkspace: whether to allocate a new unique workspace. Optional. Default false