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

add warning for algorithm-queue not created #967

Merged
merged 1 commit into from
Oct 11, 2020
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
8 changes: 6 additions & 2 deletions core/algorithm-operator/lib/helpers/etcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ class Etcd extends EventEmitter {
return this._etcd.algorithms.store.get({ name });
}

getAlgorithmTemplates() {
return this._etcd.algorithms.store.list();
async getAlgorithmTemplates() {
const [algorithms, count] = await Promise.all([
this._etcd.algorithms.store.list(),
this._etcd.algorithms.store.count()
]);
return { algorithms, count };
}

removeAlgorithmData(name) {
Expand Down
13 changes: 10 additions & 3 deletions core/algorithm-operator/lib/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class Operator {
try {
log.debug('Reconcile interval.', { component });
const configMap = await kubernetes.getVersionsConfigMap();
const algorithms = await etcd.getAlgorithmTemplates();
const { algorithms, count } = await etcd.getAlgorithmTemplates();
await Promise.all([
this._algorithmBuilds({ ...configMap }, options),
this._tenosrboards({ ...configMap, boardTimeOut: this._boardTimeOut }, options),
this._algorithmDebug(configMap, algorithms, options),
this._algorithmQueue({ ...configMap, resources: options.resources.algorithmQueue }, algorithms, options),
this._algorithmQueue({ ...configMap, resources: options.resources.algorithmQueue }, algorithms, options, count),
]);
}
catch (e) {
Expand Down Expand Up @@ -121,7 +121,8 @@ class Operator {
});
}

async _algorithmQueue({ versions, registry, clusterOptions, resources }, algorithms, options) {
async _algorithmQueue({ versions, registry, clusterOptions, resources }, algorithms, options, count) {
this._logAlgorithmCountError(algorithms, count);
const deployments = await kubernetes.getDeployments({ labelSelector: `type=${CONTAINERS.ALGORITHM_QUEUE}` });
await algorithmQueueReconciler.reconcile({
deployments,
Expand All @@ -133,6 +134,12 @@ class Operator {
options
});
}

_logAlgorithmCountError(algorithms, count) {
if (algorithms.length < count) {
log.throttle.error(`Only ${algorithms.length} algorithm-queue's can be created, but ${count} algorithms are defined. Please delete unused algorithms`, { component });
}
}
}

module.exports = new Operator();
56 changes: 28 additions & 28 deletions core/algorithm-operator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/algorithm-operator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@hkube/config": "^2.0.7",
"@hkube/consts": "^1.0.21",
"@hkube/etcd": "^5.0.37",
"@hkube/etcd": "^5.0.38",
"@hkube/healthchecks": "^1.0.0",
"@hkube/kubernetes-client": "^1.0.32",
"@hkube/logger": "^1.0.25",
Expand Down
19 changes: 19 additions & 0 deletions core/algorithm-operator/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ describe('bootstrap', () => {
mockery.disable();
decache('../bootstrap');
});
beforeEach(async () => {
await etcd._etcd._client.delete('/algorithms/store', { isPrefix: true })
});
it('should init without error', async () => {

});
Expand All @@ -29,4 +32,20 @@ describe('bootstrap', () => {
const template = await etcd.getAlgorithmTemplate({ name: 'algo2' });
expect(template).to.eql(templateStoreStub[1]);
});

it('should list template store', async () => {
await Promise.all(templateStoreStub.map(a => etcd._etcd.algorithms.store.set(a)));
const { algorithms, count } = await etcd.getAlgorithmTemplates();
expect(algorithms).to.deep.include(templateStoreStub[1]);
expect(algorithms.length).to.eql(count);
});
it('should list template store above limit', async () => {

await Promise.all([...Array(110).keys()].map(i => etcd._etcd.algorithms.store.set({
name: `key-${i}`,
})));
const { algorithms, count } = await etcd.getAlgorithmTemplates();
expect(algorithms).to.deep.include({ name: 'key-99' });
expect(algorithms.length).to.not.eql(count);
});
});