Skip to content

Commit

Permalink
NAS-130481 / 24.10 / Sync App interface (#10413)
Browse files Browse the repository at this point in the history
* NAS-130481: Sync App interface

* NAS-130481: Rename enum key

* NAS-130481: Sync App interface

---------

Co-authored-by: Evgeny Stepanovych <[email protected]>
  • Loading branch information
denysbutenko and undsoft authored Aug 8, 2024
1 parent c7ef6a1 commit 2ae458c
Show file tree
Hide file tree
Showing 38 changed files with 214 additions and 306 deletions.
4 changes: 2 additions & 2 deletions src/app/enums/catalog-app-state.enum.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export enum CatalogAppState {
Active = 'ACTIVE',
Running = 'RUNNING',
Deploying = 'DEPLOYING',
Stopped = 'STOPPED',
}

export const appStateIcons = new Map<CatalogAppState, string>([
[CatalogAppState.Active, 'mdi-check-circle'],
[CatalogAppState.Running, 'mdi-check-circle'],
[CatalogAppState.Deploying, 'mdi-progress-wrench'],
[CatalogAppState.Stopped, 'mdi-stop-circle'],
]);
8 changes: 4 additions & 4 deletions src/app/interfaces/api/api-call-directory.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,14 @@ export interface ApiCallDirectory {
'api_key.update': { params: UpdateApiKeyRequest; response: ApiKey };

// App
'app.query': { params: AppQueryParams; response: App[] };
'app.upgrade_summary': { params: AppUpgradeParams; response: AppUpgradeSummary };
'app.available': { params: QueryParams<AvailableApp>; response: AvailableApp[] };
'app.categories': { params: void; response: string[] };
'app.latest': { params: QueryParams<AvailableApp>; response: AvailableApp[] };
'app.similar': { params: [app_name: string, train: string]; response: AvailableApp[] };
'app.rollback_versions': { params: [app_name: string]; response: string[] };
'app.used_ports': { params: void; response: number[] };

// Audit
'audit.config': { params: void; response: AuditConfig };
Expand Down Expand Up @@ -373,10 +377,6 @@ export interface ApiCallDirectory {
response: CertificateAuthority;
};

// Apps
'app.query': { params: AppQueryParams; response: App[] };
'app.upgrade_summary': { params: AppUpgradeParams; response: AppUpgradeSummary };

// Chart
'chart.release.pod_console_choices': { params: [string]; response: Record<string, string[]> };
'chart.release.pod_logs_choices': { params: [string]; response: Record<string, string[]> };
Expand Down
114 changes: 70 additions & 44 deletions src/app/interfaces/app.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CatalogAppState } from 'app/enums/catalog-app-state.enum';
import { ChartSchemaType } from 'app/enums/chart-schema-type.enum';
import { CodeEditorLanguage } from 'app/enums/code-editor-language.enum';
import { AppMaintainer } from 'app/interfaces/available-app.interface';
import { ChartMetadata } from 'app/interfaces/catalog.interface';
import { HierarchicalObjectMap } from 'app/interfaces/hierarhical-object-map.interface';
import { QueryParams } from 'app/interfaces/query-api.interface';
Expand Down Expand Up @@ -80,38 +81,32 @@ export interface AppContainerVolumes {

export interface AppActiveWorkloads {
containers: number;
user_ports: AppUsedPort[];
used_ports: AppUsedPort[];
container_details: AppContainerDetails[];
volumes: AppContainerVolumes[];
images: string[];
}

export interface App {
name: string;
title: string;
info: ChartInfo;
config: Record<string, ChartFormValue>;
hooks: unknown[];
namespace: string;
app_metadata: AppMetadata;
id: string;
catalog: string;
catalog_train: string;
path: string;
dataset: string;
used_ports: UsedPort[];
pod_status: PodStatus;
active_workloads: AppActiveWorkloads;
state: CatalogAppState;
upgrade_available: boolean;
human_version: string;
human_latest_version: string;
container_images_update_available: boolean;
portals: Record<string, string[]>;
chart_schema: ChartSchema;
history: Record<string, ChartReleaseVersion>;
resources?: ChartResources;
version: number;
metadata: ChartMetadata;
active_workloads: AppActiveWorkloads;
metadata: AppMetadata;
notes: string;
portals: Record<string, string>;
version: string;
migrated: boolean;
/**
* Present with `retrieve_config` query param.
*/
config?: Record<string, ChartFormValue>;
/**
* Presents with `include_app_schema` query param.
*/
version_details?: ChartSchema;
}

export interface ChartStatisticsUpdate {
Expand Down Expand Up @@ -160,11 +155,20 @@ export interface AppUpgrade {

export type AppQueryParams = QueryParams<App, {
extra?: {
/**
* host_ip is a string which can be provided to override portal IP address if it is a wildcard.
*/
host_ip?: string;

/**
* include_app_schema is a boolean which can be set to include app schema in the response.
*/
include_app_schema?: boolean;

/**
* is a boolean which can be set to retrieve app configuration used to install/manage app.
*/
retrieve_config?: boolean;
retrieve_resources?: boolean;
include_chart_schema?: boolean;
history?: boolean;
stats?: boolean;
};
}>;

Expand Down Expand Up @@ -222,17 +226,17 @@ export interface ChartSchemaNode {
}

export interface ChartSchema {
app_readme: string;
app_metadata: ChartMetadata;
readme: string;
changelog: string;
metadata: ChartMetadata;
detailed_readme: string;
human_version: string;
location: string;
required_features: string[];
schema: {
groups: ChartSchemaGroup[];
questions: ChartSchemaNode[];
portals: Record<string, {
portals?: Record<string, {
host: string[];
ports: string[];
protocols: string[];
Expand All @@ -242,22 +246,44 @@ export interface ChartSchema {
values: Record<string, ChartFormValue>;
}

interface HostMount {
description: string;
hostPath: string;
}

interface Capability {
name: string;
description: string;
}

interface AppRunAsContext {
description: string;
gid: number;
group_name: string;
uid: number;
user_name: string;
}

export interface AppMetadata {
runAsContext?: {
description: string;
gid?: number;
groupName?: string;
userName?: string;
uid?: number;
}[];
capabilities?: {
description: string;
name: string;
}[];
hostMounts?: {
description: string;
hostPath: string;
}[];
app_version: string;
capabilities: Capability[];
categories: string[];
description: string;
home: string;
host_mounts: HostMount[];
icon: string;
keywords: string[];
last_update: string;
lib_version: string;
lib_version_hash: string;
maintainers: AppMaintainer[];
name: string;
run_as_context: AppRunAsContext[];
screenshots: string[];
sources: string[];
title: string;
train: string;
version: string;
}

export type AppStartQueryParams = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AppDetailsHeaderComponent {
map((apps) => {
return apps.filter((app) => {
return app.metadata.name === this.app.name
&& app.catalog_train === this.app.train;
&& app.metadata.train === this.app.train;
});
}),
untilDestroyed(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
></ix-dynamic-wizard>

@if (showAppMetadata) {
<ix-app-metadata-card
[appMetadata]="catalogApp.app_metadata"
></ix-app-metadata-card>
<ix-app-metadata-card [appMetadata]="catalogApp.app_metadata"></ix-app-metadata-card>
}
<div class="actions">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ describe('AppWizardComponent', () => {
release_name: 'app_name',
timezone: 'America/Los_Angeles',
} as Record<string, ChartFormValue>,
chart_schema: {
metadata: {},
version_details: {
schema: {
groups: [
{ name: 'Machinaris Configuration' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export class AppWizardComponent implements OnInit, OnDestroy {
this.config = app.config;
this.config.release_name = app.id;

this._pageTitle$.next(app.title || app.name);
this._pageTitle$.next(app.metadata.title || app.name);

this.form.addControl('release_name', new FormControl(app.name, [Validators.required]));

Expand All @@ -411,7 +411,7 @@ export class AppWizardComponent implements OnInit, OnDestroy {
],
});

this.buildDynamicForm(app.chart_schema.schema);
this.buildDynamicForm(app.version_details.schema);
}

private afterAppLoaded(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AppCardComponent {
navigateToAllInstalledPage(): void {
this.installedAppsStore.installedApps$.pipe(
map((apps) => {
return apps.filter((app) => (app.metadata.name === this.app.name && app.catalog_train === this.app.train));
return apps.filter((app) => (app.metadata.name === this.app.name && app.metadata.train === this.app.train));
}),
untilDestroyed(this),
).subscribe((apps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,32 @@ import { AppLoaderModule } from 'app/modules/loader/app-loader.module';
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service';
import { AppBulkUpgradeComponent } from 'app/pages/apps/components/installed-apps/app-bulk-upgrade/app-bulk-upgrade.component';
import { WebSocketService } from 'app/services/ws.service';
import { CatalogAppState } from 'app/enums/catalog-app-state.enum';

const fakeAppOne = {
name: 'test-app-one',
version: 1,
namespace: 'ix-test-app-one',
version: '1',
id: 'test-app-one',
catalog: 'TRUENAS',
catalog_train: 'charts',
path: '/mnt/tank/ix-applications/releases/test-pihole',
dataset: 'tank/ix-applications/releases/test-pihole',
state: 'ACTIVE',
history: {},
state: CatalogAppState.Running,
upgrade_available: true,
human_version: '2022.10_1.0.7',
human_latest_version: '2022.10_1.0.8',
pod_status: { desired: 1, available: 1 },
used_ports: [],
metadata: {
icon: 'path-to-icon',
train: 'charts',
},
container_images_update_available: false,
} as App;

const fakeAppTwo = {
name: 'test-app-two',
version: 1,
namespace: 'ix-test-app-one',
version: '1',
id: 'test-app-two',
catalog: 'TRUENAS',
catalog_train: 'charts',
path: '/mnt/tank/ix-applications/releases/test-nextcloud',
dataset: 'tank/ix-applications/releases/test-nextcloud',
state: 'ACTIVE',
history: {},
state: CatalogAppState.Running,
upgrade_available: true,
human_version: '25_1.6.33',
human_latest_version: '25_1.6.34',
pod_status: { desired: 2, available: 2 },
used_ports: [],
metadata: {
icon: 'path-to-icon',
train: 'charts'
},
container_images_update_available: true,
} as App;

const fakeUpgradeSummary: AppUpgradeSummary = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AppBulkUpgradeComponent {
private snackbar: SnackbarService,
@Inject(MAT_DIALOG_DATA) private apps: App[],
) {
this.apps = this.apps.filter((app) => app.upgrade_available || app.container_images_update_available);
this.apps = this.apps.filter((app) => app.upgrade_available);

this.setInitialValues();
this.detectFormChanges();
Expand Down Expand Up @@ -132,7 +132,7 @@ export class AppBulkUpgradeComponent {
private setInitialValues(): void {
this.apps.forEach((app) => {
this.bulkItems.set(app.name, { state: BulkListItemState.Initial, item: app });
const [, latestVersion] = app.human_latest_version.split('_');
const [, latestVersion] = app.metadata.app_version.split('_');
this.form.addControl(app.name, this.formBuilder.control<string>(latestVersion));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ <h3 mat-card-title>
<div class="details-item">
<div class="label">{{ 'Pods' | translate }}:</div>
<div class="value">
@if (app?.resources?.pods) {
{{ app.resources.pods.length }}
} @else {
@if (true) {
<!-- TODO: Fix app resource pods -->
{{ 'N/A' | translate }}
<!-- {{ app.resources.pods.length }} -->
}
</div>
</div>
<div class="details-item">
<div class="label">{{ 'Used Ports' | translate }}:</div>
<div class="value">
@if (app?.used_ports) {
@if (app?.active_workloads?.used_ports?.length) {
{{ getPorts(app) }}
} @else {
{{ 'N/A' | translate }}
Expand All @@ -33,19 +33,19 @@ <h3 mat-card-title>
<div class="details-item">
<div class="lael">{{ 'Deployments' | translate }}:</div>
<div class="value">
@if (app?.resources?.deployments) {
{{ app.resources.deployments.length }}
} @else {
@if (true) {
<!-- TODO: Fix app resource deployments -->
<!-- {{ app.resources.deployments.length }} -->
{{ 'N/A' | translate }}
}
</div>
</div>
<div class="details-item">
<div class="label">{{ 'Stateful Sets' | translate }}:</div>
<div class="value">
@if (app?.resources?.statefulsets) {
{{ app.resources.statefulsets.length }}
} @else {
@if (true) {
<!-- TODO: Fix app resource statefulsets -->
<!-- {{ app.resources.statefulsets.length }} -->
{{ 'N/A' | translate }}
}
</div>
Expand Down
Loading

0 comments on commit 2ae458c

Please sign in to comment.