Skip to content

Commit 19d56c9

Browse files
authored
check datacenter selector (#7679)
1 parent d767563 commit 19d56c9

File tree

2 files changed

+54
-35
lines changed

2 files changed

+54
-35
lines changed

modules/web/src/app/wizard/component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class WizardComponent implements OnInit, OnDestroy {
133133
this.project.id = this._route.snapshot.paramMap.get(PathParam.ProjectID);
134134

135135
if (this.clusterTemplateID) {
136-
this.loadClusterTemplate();
136+
this._loadClusterTemplate();
137137
} else {
138138
this.loadingClusterTemplate = false;
139139
}
@@ -333,7 +333,7 @@ export class WizardComponent implements OnInit, OnDestroy {
333333
// Template is already loaded at this point and we don't need to reload it unless the project ID has changed.
334334
if (this.clusterTemplateID && project.id !== this.project.id) {
335335
this.project = project;
336-
this.loadClusterTemplate();
336+
this._loadClusterTemplate();
337337
}
338338
this.project = project;
339339
});
@@ -352,7 +352,7 @@ export class WizardComponent implements OnInit, OnDestroy {
352352
this.form = this._formBuilder.group(controls);
353353
}
354354

355-
private loadClusterTemplate(): void {
355+
private _loadClusterTemplate(): void {
356356
this._clusterTemplateService
357357
.get(this.project.id, this.clusterTemplateID)
358358
// We just need to load the cluster template once. Usage of `takeUntil` will cause an endless chain of update that

modules/web/src/app/wizard/step/applications/component.ts

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import {FormBuilder, NG_VALIDATORS, NG_VALUE_ACCESSOR} from '@angular/forms';
1717
import {ClusterSpecService} from '@app/core/services/cluster-spec';
1818
import {StepRegistry} from '@app/wizard/config';
1919
import {StepBase} from '@app/wizard/step/base';
20+
import {WizardMode} from '@app/wizard/types/wizard-mode';
2021
import {ApplicationService} from '@core/services/application';
2122
import {WizardService} from '@core/services/wizard/wizard';
2223
import {ApplicationsListView} from '@shared/components/application-list/component';
2324
import {Application, ApplicationSettings, createApplicationInstallation} from '@shared/entity/application';
24-
import _, {merge} from 'lodash';
25-
import {forkJoin, takeUntil} from 'rxjs';
25+
import _ from 'lodash';
26+
import {forkJoin, switchMap, takeUntil} from 'rxjs';
2627

2728
enum Controls {
2829
Applications = 'applications',
@@ -49,6 +50,7 @@ export class ApplicationsStepComponent extends StepBase implements OnInit, OnDes
4950
readonly ApplicationsListView = ApplicationsListView;
5051

5152
applications: Application[] = [];
53+
wizardMode: WizardMode;
5254

5355
private _applicationSettings: ApplicationSettings;
5456

@@ -62,6 +64,8 @@ export class ApplicationsStepComponent extends StepBase implements OnInit, OnDes
6264
}
6365

6466
ngOnInit(): void {
67+
this.wizardMode = window.history.state?.mode;
68+
6569
this.form = this._builder.group({
6670
[Controls.Applications]: this._builder.control(''),
6771
});
@@ -81,45 +85,60 @@ export class ApplicationsStepComponent extends StepBase implements OnInit, OnDes
8185
}
8286
return application;
8387
}) || [];
84-
85-
merge(this._clusterSpecService.datacenterChanges, this._applicationService.applicationChanges)
86-
.pipe(takeUntil(this._unsubscribe))
87-
.subscribe(_ => {
88-
this.loadDefaultAndEnforcedApplications();
88+
this._loadDefaultAndEnforcedApplications();
89+
if (this.wizardMode !== WizardMode.CustomizeClusterTemplate && this.wizardMode !== WizardMode.EditClusterTemplate) {
90+
this._clusterSpecService.datacenterChanges.pipe(takeUntil(this._unsubscribe)).subscribe(_ => {
91+
this._applicationService.applications = [];
92+
this.applications = [];
93+
this._loadDefaultAndEnforcedApplications();
8994
});
95+
}
9096
}
9197

92-
private loadDefaultAndEnforcedApplications() {
93-
const defaultAndEnforcedApplications = this._applicationService.applicationDefinitions.filter(
94-
application => application.spec.default || application.spec.enforced
95-
);
96-
97-
// Fetch individual application definitions and create ApplicationInstallations
98-
forkJoin(
99-
defaultAndEnforcedApplications.map(application =>
100-
this._applicationService.getApplicationDefinition(application.name)
98+
private _loadDefaultAndEnforcedApplications() {
99+
this._applicationService
100+
.listApplicationDefinitions()
101+
.pipe(
102+
switchMap(apps => {
103+
const defaultAndEnforcedApplications = apps.filter(application => {
104+
return (
105+
(application.spec.default || application.spec.enforced) &&
106+
(!application.spec.selector?.datacenters ||
107+
application.spec.selector?.datacenters?.includes(this._clusterSpecService.datacenter))
108+
);
109+
});
110+
return forkJoin(
111+
defaultAndEnforcedApplications.map(application =>
112+
this._applicationService.getApplicationDefinition(application.name)
113+
)
114+
);
115+
})
101116
)
102-
).subscribe(applicationDefinitions => {
103-
applicationDefinitions.forEach(appDef => {
104-
if (appDef.name === 'k8sgpt') {
105-
appDef.spec.enforced = true;
106-
}
107-
108-
if (appDef.name === 'cert-manager') {
109-
appDef.spec.default = true;
110-
}
111-
112-
const applicationInstallation = createApplicationInstallation(
113-
appDef,
114-
this._applicationSettings?.defaultNamespace
115-
);
116-
this.onApplicationAdded(applicationInstallation);
117+
// Fetch individual application definitions and create ApplicationInstallations
118+
.subscribe(applicationDefinitions => {
119+
applicationDefinitions.forEach(appDef => {
120+
if (appDef.name === 'k8sgpt') {
121+
appDef.spec.enforced = true;
122+
}
123+
124+
if (appDef.name === 'cert-manager') {
125+
appDef.spec.default = true;
126+
}
127+
128+
const applicationInstallation = createApplicationInstallation(
129+
appDef,
130+
this._applicationSettings?.defaultNamespace
131+
);
132+
this.onApplicationAdded(applicationInstallation);
133+
});
117134
});
118-
});
119135
}
120136

121137
onApplicationAdded(application: Application): void {
122138
application.id = `${application.name}/${application.spec.namespace.name}`;
139+
if (this.applications.find(app => app.id === application.id)) {
140+
return;
141+
}
123142
this.applications = [...this.applications, application];
124143
this._onApplicationsChanged();
125144
}

0 commit comments

Comments
 (0)