Skip to content

Commit eac654f

Browse files
authored
fix: honor per-service defaultUUID for fallback hostnames (#237)
* fix: honor per-service defaultUUID for fallback public URL and hostnames getPublicUrl() and the internal hostname/grpc host fallback in DeployableService always used the global default UUID, ignoring a service's own defaultUUID override in lifecycle.yaml. Both now resolve through getUUID(), which already respected the per-service value. Adds unit test coverage for the override. * test: cover NO_DEFAULT_ENV_RESOLVE precedence for defaultUUID resolution Adds coverage for the case where the NO_DEFAULT_ENV_RESOLVE feature flag takes priority over a service-level defaultUUID override, for both getPublicUrl() and the deployable hostname/URL fallbacks.
1 parent 42cffcd commit eac654f

4 files changed

Lines changed: 115 additions & 9 deletions

File tree

‎src/server/models/yaml/YamlService.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,9 @@ export const getDockerBuildPipelineId = (service) =>
885885
service?.helm?.docker?.pipelineId || service?.github?.docker?.pipelineId;
886886

887887
export async function getPublicUrl(service: Service, build: Build): Promise<string> {
888-
const { lifecycleDefaults, domainDefaults } = await GlobalConfigService.getInstance().getAllConfigs();
889-
let host = lifecycleDefaults.defaultUUID;
890-
let { http: httpDomain, grpc: grpcDomain } = domainDefaults;
891-
if (build?.enabledFeatures.includes(FeatureFlags.NO_DEFAULT_ENV_RESOLVE)) {
892-
host = NO_DEFAULT_ENV_UUID;
893-
}
888+
const { domainDefaults } = await GlobalConfigService.getInstance().getAllConfigs();
889+
const host = await getUUID(service, build);
890+
const { http: httpDomain, grpc: grpcDomain } = domainDefaults;
894891

895892
if (DeployTypes.HELM === getDeployType(service)) {
896893
const helmService = (service as unknown as HelmService).helm;

‎src/server/models/yaml/tests/YamlService.test.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ mockRedisClient();
1919

2020
import { YamlConfigParser } from 'server/lib/yamlConfigParser';
2121
import { YamlConfigValidator } from 'server/lib/yamlConfigValidator';
22-
import { DeployTypes } from 'shared/constants';
22+
import { Build } from 'server/models';
23+
import { DeployTypes, FeatureFlags, NO_DEFAULT_ENV_UUID } from 'shared/constants';
2324
import * as YamlService from '../index';
2425

2526
const mockGetAllConfigs = jest.fn();
@@ -587,6 +588,40 @@ services:
587588
});
588589
});
589590

591+
describe('getPublicUrl', () => {
592+
beforeEach(() => {
593+
mockGetAllConfigs.mockResolvedValue({
594+
lifecycleDefaults: { defaultUUID: 'dev-0' },
595+
domainDefaults: { http: 'lifecycle.example.com', grpc: 'lifecycle-grpc.example.com' },
596+
});
597+
});
598+
599+
test('falls back to the global default UUID when the service has none configured', async () => {
600+
const service: YamlService.Service = { name: 'my-service' } as YamlService.Service;
601+
const build = { enabledFeatures: [] } as unknown as Build;
602+
603+
await expect(YamlService.getPublicUrl(service, build)).resolves.toEqual('my-service-dev-0.lifecycle.example.com');
604+
});
605+
606+
test('uses the service-level defaultUUID override when configured', async () => {
607+
const service: YamlService.Service = { name: 'my-service', defaultUUID: 'sandbox' } as YamlService.Service;
608+
const build = { enabledFeatures: [] } as unknown as Build;
609+
610+
await expect(YamlService.getPublicUrl(service, build)).resolves.toEqual(
611+
'my-service-sandbox.lifecycle.example.com'
612+
);
613+
});
614+
615+
test('NO_DEFAULT_ENV_RESOLVE takes priority over a service-level defaultUUID override', async () => {
616+
const service: YamlService.Service = { name: 'my-service', defaultUUID: 'sandbox' } as YamlService.Service;
617+
const build = { enabledFeatures: [FeatureFlags.NO_DEFAULT_ENV_RESOLVE] } as unknown as Build;
618+
619+
await expect(YamlService.getPublicUrl(service, build)).resolves.toEqual(
620+
`my-service-${NO_DEFAULT_ENV_UUID}.lifecycle.example.com`
621+
);
622+
});
623+
});
624+
590625
describe('getEnvironmentVariables', () => {
591626
test('GithubService', () => {
592627
const parser = new YamlConfigParser();

‎src/server/services/__tests__/deployable.test.ts‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jest.mock('server/lib/github', () => ({
5252
}));
5353

5454
import * as YamlService from 'server/models/yaml';
55+
import { Build } from 'server/models';
56+
import { FeatureFlags, NO_DEFAULT_ENV_UUID } from 'shared/constants';
5557
import DeployableService, { DeployableAttributes } from '../deployable';
5658

5759
const lifecycleDefaults = {
@@ -260,6 +262,78 @@ describe('Deployable Service', () => {
260262
});
261263
});
262264

265+
test('service-level defaultUUID overrides the global default for hostname/URL fallbacks', async () => {
266+
const githubService: YamlService.GithubService = {
267+
name: 'github-app',
268+
defaultUUID: 'sandbox',
269+
github: {
270+
repository: 'example-org/example-service',
271+
branchName: 'unit-test',
272+
docker: {
273+
defaultTag: 'main',
274+
app: {
275+
dockerfilePath: 'app1/app.Dockerfile',
276+
},
277+
},
278+
},
279+
};
280+
281+
const build = { enabledFeatures: [] } as unknown as Build;
282+
283+
// @ts-ignore
284+
const result: DeployableAttributes = await deployableService.generateAttributesFromYamlConfig(
285+
100,
286+
'unit-test-12345',
287+
1234567890,
288+
'unit-test',
289+
githubService,
290+
false,
291+
'',
292+
build
293+
);
294+
295+
expect(result.defaultUUID).toEqual('sandbox');
296+
expect(result.defaultInternalHostname).toEqual('github-app-sandbox');
297+
expect(result.defaultPublicUrl).toEqual(`github-app-sandbox.${domainDefaults.http}`);
298+
expect(result.defaultGrpcHost).toEqual(`github-app-sandbox.${domainDefaults.grpc}`);
299+
});
300+
301+
test('NO_DEFAULT_ENV_RESOLVE takes priority over a service-level defaultUUID override', async () => {
302+
const githubService: YamlService.GithubService = {
303+
name: 'github-app',
304+
defaultUUID: 'sandbox',
305+
github: {
306+
repository: 'example-org/example-service',
307+
branchName: 'unit-test',
308+
docker: {
309+
defaultTag: 'main',
310+
app: {
311+
dockerfilePath: 'app1/app.Dockerfile',
312+
},
313+
},
314+
},
315+
};
316+
317+
const build = { enabledFeatures: [FeatureFlags.NO_DEFAULT_ENV_RESOLVE] } as unknown as Build;
318+
319+
// @ts-ignore
320+
const result: DeployableAttributes = await deployableService.generateAttributesFromYamlConfig(
321+
100,
322+
'unit-test-12345',
323+
1234567890,
324+
'unit-test',
325+
githubService,
326+
false,
327+
'',
328+
build
329+
);
330+
331+
expect(result.defaultUUID).toEqual(NO_DEFAULT_ENV_UUID);
332+
expect(result.defaultInternalHostname).toEqual(`github-app-${NO_DEFAULT_ENV_UUID}`);
333+
expect(result.defaultPublicUrl).toEqual(`github-app-${NO_DEFAULT_ENV_UUID}.${domainDefaults.http}`);
334+
expect(result.defaultGrpcHost).toEqual(`github-app-${NO_DEFAULT_ENV_UUID}.${domainDefaults.grpc}`);
335+
});
336+
263337
test('Generate config should have httpGet port and path', async () => {
264338
const githubService: YamlService.GithubService = {
265339
name: 'github-app',

‎src/server/services/deployable.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default class DeployableService extends BaseService {
199199
const { serviceDefaults, lifecycleDefaults, domainDefaults, buildDefaults } =
200200
await GlobalConfigService.getInstance().getAllConfigs();
201201
//TODO check and throw error here?
202-
const defaultUUID = lifecycleDefaults.defaultUUID;
202+
const defaultUUID = await YamlService.getUUID(service, build);
203203
const dockerBuildPipelineName =
204204
YamlService.getDockerBuildPipelineId(service) || lifecycleDefaults.buildPipeline;
205205

@@ -262,7 +262,7 @@ export default class DeployableService extends BaseService {
262262
deployment?.network?.grpc?.defaultHost ?? `${service.name}-${defaultUUID}.${domainDefaults.grpc}`,
263263

264264
ingressAnnotations: deployment?.network?.ingressAnnotations ?? {},
265-
defaultUUID: await YamlService.getUUID(service, build),
265+
defaultUUID,
266266
serviceDisksYaml: deployment?.serviceDisks ? JSON.stringify(deployment.serviceDisks) : null,
267267

268268
nodeSelector: deployment?.node_selector ?? null,

0 commit comments

Comments
 (0)