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

Added support for sidecaraddons API #7934

Open
wants to merge 1 commit into
base: dev
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
2 changes: 2 additions & 0 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FunctionsModule } from './functions/functions.module';
import { DomainsModule } from './domains/domains.module';
import { DeploymentCenterModule } from './deployment-center/deployment-center.module';
import { StacksModule } from './stacks/stacks.module';
import { SidecarAddOnsModule } from './sidecaraddons/sidecaraddons.module';
import { StaticSitesModule } from './staticsites/staticsites.module';
import { WorkflowModule } from './workflows/workflows.module';

Expand All @@ -19,6 +20,7 @@ import { WorkflowModule } from './workflows/workflows.module';
DeploymentCenterModule,
StaticSitesModule,
StacksModule,
SidecarAddOnsModule,
WorkflowModule,
HomeModule,
],
Expand Down
51 changes: 51 additions & 0 deletions server/src/sidecaraddons/models/SidecarAddOnModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export interface AddOnConfig {
addOnAttributes: AddOnAttribute[];
sidecarImages: SidecarImage[];
}

export interface AddOnAttribute {
displayText: string;
id: string;
type: string;
isRequired: boolean;
}

export interface SidecarImage {
releaseChannel: string;
displayText: string;
value: string;
isEarlyAccess: boolean;
deprecated: boolean;
supportedLinuxFxVersions: string[];
sitecontainerMetadata: SitecontainerMetadata;
}

export interface SitecontainerMetadata {
appSettingMappings: AppSettingMapping[];
volumeMappings: VolumeMapping[];
port: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should never be using "any" as a type. I'm guessing this should be "number"? Same comment for all the other instances of "any" below.

startUpCommand: any;
}

export interface AppSettingMapping {
appSettingName: string;
environmentVariableName: any;
}

export interface VolumeMapping {
volumeSubPath: any;
containerMountPath: any;
readOnly: boolean;
}

export interface SidecarAddOn {
id: string;
displayText: string;
organization: string;
legalInformation: string;
value: string;
supportedOs: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

For type-safety, you can limit which string values are possible like so:

supportedOs: "Linux" | "Windows";

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add Os and any other limited sets of values (like supportedFeatures?) as enums.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine too though if you did use an enum, make sure it's a string-based enum and not a regular number-based one. There isn't too much of a difference between a type definition and a string-based enum. The compiler is going to help you with type-safety regardless. If you're doing a lot of values then sure, an enum is probably the better way to go for sure.

supportedFeatures: string[];
additionalInformation: string;
addOnConfig: AddOnConfig;
}
14 changes: 14 additions & 0 deletions server/src/sidecaraddons/service/SidecarAddOnService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@nestjs/common';
import { SidecarAddOn } from '../models/SidecarAddOnModel';
import { redisSidecarAddOn } from '../sidecaraddons/redis';

@Injectable()
export class SidecarAddOnService {
getSidecarAddOns(): SidecarAddOn[] {
const redisSidecarAddOnCopy = JSON.parse(JSON.stringify(redisSidecarAddOn));

let sidecarAddOns: SidecarAddOn[] = [redisSidecarAddOnCopy];

return sidecarAddOns;
}
}
12 changes: 12 additions & 0 deletions server/src/sidecaraddons/sidecaraddons.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Query, Post, Get } from '@nestjs/common';
import { SidecarAddOnService } from './service/SidecarAddOnService';

@Controller('sidecaraddons')
export class SidecarAddOnsController {
constructor(private _sidecarAddOnService: SidecarAddOnService) {}

@Get('')
sideCarAddOns(@Query('api-version') apiVersion: string) {
return this._sidecarAddOnService.getSidecarAddOns();
}
}
11 changes: 11 additions & 0 deletions server/src/sidecaraddons/sidecaraddons.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { SharedModule } from '../shared/shared.module';
import { SidecarAddOnsController } from './sidecaraddons.controller';
import { SidecarAddOnService } from './service/SidecarAddOnService';

@Module({
imports: [SharedModule],
controllers: [SidecarAddOnsController],
providers: [SidecarAddOnService],
})
export class SidecarAddOnsModule {}
53 changes: 53 additions & 0 deletions server/src/sidecaraddons/sidecaraddons/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { SidecarAddOn } from '../models/SidecarAddOnModel';

const getRedisSidecarAddOn: () => SidecarAddOn = () => {
return {
id: 'redis',
displayText: '<ADD_ON_NAME_DISPLAY_TEXT_DESCRIPTION>',
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll have to look into a way to localize strings on our server

organization: 'redis',
legalInformation: '<ADD_ON_LEGAL_INFORMATION>',
value: 'redis',
supportedOs: 'Linux',
supportedFeatures: ['LOGS', 'TRACES'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Is supportedFeatures a limited set of possible values? Or could it be anything that's unpredictable?

additionalInformation: '<Any Extra information for Addon>',
addOnConfig: {
addOnAttributes: [
{
displayText: '<ADD_ON_ATTRIBUTE_DISPLAY_TEXT>',
id: '<ADD_ON_ATTRIBUTE_ID>',
type: '<WELL-DEFINED-TYPE>',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give an example of a "well-defined-type"?

isRequired: true,
},
],
sidecarImages: [
Copy link
Contributor

Choose a reason for hiding this comment

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

Since sidecarImages is an array, I assume this means that when I install an add-on, I may need to configure multiple containers at the same time?

@yoonaoh do our mocks handle that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The mocks don't handle adding multiple containers at one time. I thought the array was meant to store multiple versions of the same image and that we would most likely configure with the latest image.

{
releaseChannel: 'Latest',
displayText: '<VENDOR_IMAGE_1>',
value: '<IMAGE_PATH>',
isEarlyAccess: true,
deprecated: false,
supportedLinuxFxVersions: ['DOTNETCORE|*', 'PYTHON|*'],
sitecontainerMetadata: {
appSettingMappings: [
{
appSettingName: '<ADD_ON_ATTRIBUTE_ID>',
Copy link
Contributor

Choose a reason for hiding this comment

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

So if I understand correctly, appSettingName is just a reference to an existing app setting that's defined on the site itself yes? If so, is the UX supposed to add those app setting values to the site when adding the add-on? And if that's true, how do we know what value to set for the app setting?

environmentVariableName: null,
},
],
volumeMappings: [
{
volumeSubPath: null,
containerMountPath: null,
readOnly: false,
},
],
port: null,
startUpCommand: null,
},
},
],
},
};
};

export const redisSidecarAddOn: SidecarAddOn = getRedisSidecarAddOn();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of returning the result of getRedisSidecarAddOn(), you can just export getRedisSidecarAddon the function. That way you wouldn't need to do a deep copy of the result in the SidecarAddOnService.ts

Loading