Skip to content

Commit

Permalink
Merge pull request #2455 from terascope/teraslice-improvements-jan-2021
Browse files Browse the repository at this point in the history
fixing issue when getting job list from k8s

This is meant to address #2438
  • Loading branch information
godber committed Jan 28, 2021
2 parents f3b12b6 + 6ed0830 commit c3938ab
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 35 deletions.
6 changes: 5 additions & 1 deletion docs/configuration/clustering-k8s.md
Expand Up @@ -6,6 +6,8 @@ sidebar_label: Kubernetes Clustering
Teraslice supports the use of Kubernetes as a cluster manager. The following
versions of Kuberenetes have been used:

* `1.19.*`
* `1.18.*`
* `1.17.*`
* `1.16.*`
* `1.13.2`
Expand Down Expand Up @@ -374,7 +376,9 @@ cd examples/k8s
export NAMESPACE=ts-dev1
export TERASLICE_K8S_IMAGE=teraslice-k8sdev:1
export TERASLICE_MODE=minikube
minikube start --memory 4096 --cpus 4
# Set the version of Kubernetes you want to run
export KUBERNETES_VERSION=v1.19.7
minikube start --memory 4096 --cpus 4 --kubernetes-version=${KUBERNETES_VERSION}
eval $(minikube docker-env)
make build
make setup-all
Expand Down
7 changes: 2 additions & 5 deletions examples/k8s/example-job-labels.json
Expand Up @@ -18,13 +18,10 @@
"_op": "example-op"
},
{
"_op": "elasticsearch_index_selector",
"_op": "elasticsearch_bulk",
"size": 5000,
"index": "terak8s-example-data",
"type": "events"
},
{
"_op": "elasticsearch_bulk",
"size": 5000
}
]
}
7 changes: 2 additions & 5 deletions examples/k8s/example-job-resource.json
Expand Up @@ -17,13 +17,10 @@
"_op": "example-op"
},
{
"_op": "elasticsearch_index_selector",
"_op": "elasticsearch_bulk",
"size": 5000,
"index": "terak8s-example-data",
"type": "events"
},
{
"_op": "elasticsearch_bulk",
"size": 5000
}
]
}
7 changes: 2 additions & 5 deletions examples/k8s/example-job-targets.json
Expand Up @@ -21,13 +21,10 @@
"_op": "example-op"
},
{
"_op": "elasticsearch_index_selector",
"_op": "elasticsearch_bulk",
"size": 5000,
"index": "terak8s-example-data",
"type": "events"
},
{
"_op": "elasticsearch_bulk",
"size": 5000
}
]
}
7 changes: 2 additions & 5 deletions examples/k8s/example-job-volume.json
Expand Up @@ -21,13 +21,10 @@
"_op": "example-op"
},
{
"_op": "elasticsearch_index_selector",
"_op": "elasticsearch_bulk",
"size": 5000,
"index": "terak8s-example-data",
"type": "events"
},
{
"_op": "elasticsearch_bulk",
"size": 5000
}
]
}
7 changes: 2 additions & 5 deletions examples/k8s/example-job-with-image.json
Expand Up @@ -15,13 +15,10 @@
{
"_op": "example-op"
},
{
"_op": "elasticsearch_index_selector",
"index": "terak8s-example-data",
"type": "events"
},
{
"_op": "elasticsearch_bulk",
"index": "terak8s-example-data",
"type": "events",
"size": 5000
}
]
Expand Down
7 changes: 2 additions & 5 deletions examples/k8s/example-job.json
Expand Up @@ -19,13 +19,10 @@
"ms": 30000
},
{
"_op": "elasticsearch_index_selector",
"_op": "elasticsearch_bulk",
"size": 5000,
"index": "terak8s-example-data",
"type": "events"
},
{
"_op": "elasticsearch_bulk",
"size": 5000
}
]
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "teraslice-workspace",
"displayName": "Teraslice",
"version": "0.71.2",
"version": "0.71.3",
"private": true,
"homepage": "https://github.com/terascope/teraslice",
"bugs": {
Expand Down
@@ -1,12 +1,13 @@
'use strict';

const {
TSError, logError, get, cloneDeep
TSError, logError, get, cloneDeep, pRetry
} = require('@terascope/utils');
const { makeLogger } = require('../../../../../workers/helpers/terafoundation');
const K8sResource = require('./k8sResource');
const k8sState = require('./k8sState');
const K8s = require('./k8s');
const { getRetryConfig } = require('./utils');

/*
Execution Life Cycle for _status
Expand Down Expand Up @@ -127,7 +128,9 @@ module.exports = function kubernetesClusterBackend(context, clusterMasterServer)
// because they are not on the schema. So I do this k8s API call
// instead.
const selector = `app.kubernetes.io/component=execution_controller,teraslice.terascope.io/jobId=${execution.job_id}`;
const jobs = await k8s.list(selector, 'jobs');
const jobs = await pRetry(
() => k8s.nonEmptyList(selector, 'jobs'), getRetryConfig
);
execution.k8sName = jobs.items[0].metadata.name;
execution.k8sUid = jobs.items[0].metadata.uid;

Expand Down
Expand Up @@ -197,6 +197,21 @@ class K8s {
return response.body;
}

async nonEmptyList(selector, objType) {
const jobs = await this.list(selector, objType);
if (jobs.items.length === 1) {
return jobs;
} if (jobs.items.length === 0) {
const msg = `Teraslice ${objType} matching the following selector was not found: ${selector} (retriable)`;
this.logger.warn(msg);
throw new TSError(msg, { retryable: true });
} else {
throw new TSError(`Unexpected number of Teraslice ${objType}s matching the following selector: ${selector}`, {
retryable: true
});
}
}

/**
* posts manifest to k8s
* @param {Object} manifest service manifest
Expand Down
2 changes: 1 addition & 1 deletion packages/teraslice/package.json
@@ -1,7 +1,7 @@
{
"name": "teraslice",
"displayName": "Teraslice",
"version": "0.71.2",
"version": "0.71.3",
"description": "Distributed computing platform for processing JSON data",
"homepage": "https://github.com/terascope/teraslice#readme",
"bugs": {
Expand Down
Expand Up @@ -104,6 +104,28 @@ describe('k8s', () => {
});
});

describe('->nonEmptyList', () => {
it('can get list with one item', async () => {
nock(_url)
.get('/apis/batch/v1/namespaces/default/jobs/')
.query({ labelSelector: 'app=teraslice' })
.reply(200, { items: ['one'] });

const jobs = await k8s.nonEmptyList('app=teraslice', 'jobs');
expect(jobs.items[0]).toEqual('one');
});

it('throws with an empty list', async () => {
nock(_url)
.get('/apis/batch/v1/namespaces/default/jobs/')
.query({ labelSelector: 'app=teraslice' })
.reply(200, { items: [] });

await expect(k8s.nonEmptyList('app=teraslice', 'jobs'))
.rejects.toThrowError('Teraslice jobs matching the following selector was not found: app=teraslice (retriable)');
});
});

describe('->post', () => {
it('can post a service', async () => {
nock(_url, { encodedQueryParams: true })
Expand Down

0 comments on commit c3938ab

Please sign in to comment.