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

fix(fleet): image override might contain the commitId tag #3292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
63 changes: 53 additions & 10 deletions packages/fleet/lib/supervisor/supervisor.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,65 @@ describe('Supervisor', () => {
const nodeAfter = (await nodes.get(dbClient.db, node.id)).unwrap();
expect(nodeAfter.state).toBe('OUTDATED');
});
it('should mark nodes with config override as OUTDATED', async () => {
it('should mark nodes with resource override as OUTDATED', async () => {
const node = await createNodeWithAttributes(dbClient.db, { state: 'RUNNING', deploymentId: activeDeployment.id });
(
await nodeConfigOverrides.create(dbClient.db, {
routingId: node.routingId,
image: 'new-image',
cpuMilli: 10000,
memoryMb: 1234,
storageMb: 567890
})
).unwrap();
await nodeConfigOverrides.create(dbClient.db, {
routingId: node.routingId,
image: node.image,
cpuMilli: 10000,
memoryMb: 1234,
storageMb: 567890
});

await supervisor.tick();

const nodeAfter = (await nodes.get(dbClient.db, node.id)).unwrap();
expect(nodeAfter.state).toBe('OUTDATED');

await supervisor.tick();

const newNode = (await nodes.search(dbClient.db, { states: ['PENDING'] })).unwrap().nodes.get(node.routingId)?.PENDING[0];
expect(newNode).toMatchObject({
state: 'PENDING',
routingId: node.routingId,
deploymentId: activeDeployment.id,
image: node.image,
cpuMilli: 10000,
memoryMb: 1234,
storageMb: 567890,
error: null
});
});

it('should mark nodes with image override as OUTDATED', async () => {
const node = await createNodeWithAttributes(dbClient.db, { state: 'RUNNING', deploymentId: activeDeployment.id });
const imageOverride = `${mockNodeProvider.defaultNodeConfig.image}:12345`;
await nodeConfigOverrides.create(dbClient.db, {
routingId: node.routingId,
image: imageOverride,
cpuMilli: node.cpuMilli,
memoryMb: node.memoryMb,
storageMb: node.storageMb
});

await supervisor.tick();

const nodeAfter = (await nodes.get(dbClient.db, node.id)).unwrap();
expect(nodeAfter.state).toBe('OUTDATED');

await supervisor.tick();

const newNode = (await nodes.search(dbClient.db, { states: ['PENDING'] })).unwrap().nodes.get(node.routingId)?.PENDING[0];
expect(newNode).toMatchObject({
state: 'PENDING',
routingId: node.routingId,
deploymentId: activeDeployment.id,
image: imageOverride,
cpuMilli: node.cpuMilli,
memoryMb: node.memoryMb,
storageMb: node.storageMb,
error: null
});
});

it('should create new nodes if only OUTDATED', async () => {
Expand Down
30 changes: 15 additions & 15 deletions packages/fleet/lib/supervisor/supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Err, Ok, retryWithBackoff } from '@nangohq/utils';
import type { Result } from '@nangohq/utils';
import { FleetError } from '../utils/errors.js';
import type { Node, NodeConfigOverride } from '../types.js';
import type { Deployment, NodeConfig } from '@nangohq/types';
import type { Deployment } from '@nangohq/types';
import { setTimeout } from 'node:timers/promises';
import type { NodeProvider } from '../node-providers/node_provider.js';
import { envs } from '../env.js';
Expand Down Expand Up @@ -182,8 +182,11 @@ export class Supervisor {
if (!configOverride) {
return false;
}
// image override might have a commitId
// so we need to check if the image override with commitId is the same as the node's image
// or if the image override (without commitId) + current deployment commitId is the same as the node's image
return !(
node.image === `${configOverride.image}:${deployment.commitId}` &&
(configOverride.image === node.image || `${configOverride.image}:${deployment.commitId}` === node.image) &&
node.cpuMilli === configOverride.cpuMilli &&
node.memoryMb === configOverride.memoryMb &&
node.storageMb === configOverride.storageMb
Expand Down Expand Up @@ -320,31 +323,28 @@ export class Supervisor {
db: Knex,
{
routingId,
deployment,
nodeConfig
deployment
}: {
type: 'CREATE';
routingId: Node['routingId'];
deployment: Deployment;
nodeConfig?: NodeConfig | undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this change but it was not used anymore

}
): Promise<Result<Node>> {
let newNodeConfig = this.nodeProvider.defaultNodeConfig;
if (!nodeConfig) {
const nodeConfigOverride = await nodeConfigOverrides.search(db, { routingIds: [routingId] });
if (nodeConfigOverride.isErr()) {
return Err(nodeConfigOverride.error);
}
const nodeConfigOverrideValue = nodeConfigOverride.value.get(routingId);
if (nodeConfigOverrideValue) {
newNodeConfig = nodeConfigOverrideValue;
}

const nodeConfigOverride = await nodeConfigOverrides.search(db, { routingIds: [routingId] });
if (nodeConfigOverride.isErr()) {
return Err(nodeConfigOverride.error);
}
const nodeConfigOverrideValue = nodeConfigOverride.value.get(routingId);
if (nodeConfigOverrideValue) {
newNodeConfig = nodeConfigOverrideValue;
}

return nodes.create(db, {
routingId,
deploymentId: deployment.id,
image: `${newNodeConfig.image}:${deployment.commitId}`,
image: newNodeConfig.image.includes(':') ? newNodeConfig.image : `${newNodeConfig.image}:${deployment.commitId}`,
cpuMilli: newNodeConfig.cpuMilli,
memoryMb: newNodeConfig.memoryMb,
storageMb: newNodeConfig.storageMb
Expand Down
Loading