Skip to content

Commit

Permalink
Make Domain field optional when using application credentials for O…
Browse files Browse the repository at this point in the history
…penstack provider (#7044)
  • Loading branch information
Waseem826 authored Dec 16, 2024
1 parent 43d85fa commit e1f2fd3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class OpenstackSettingsComponent extends BaseFormValidator implements OnI
private _update(): void {
this._presetDialogService.preset.spec.openstack = {
...this._presetDialogService.preset.spec.openstack,
domain: this.form.get(Controls.Domain).value,
domain: this.form.get(Controls.Domain).value || null,
network: this.form.get(Controls.Network).value,
securityGroups: this.form.get(Controls.SecurityGroups).value,
floatingIPPool: this.form.get(Controls.FloatingIPPool).value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
ViewChild,
} from '@angular/core';
import {FormBuilder, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validators} from '@angular/forms';
import {OpenstackCredentialsTypeService} from '@app/wizard/step/provider-settings/provider/extended/openstack/service';
import {
CredentialsType,
OpenstackCredentialsTypeService,
} from '@app/wizard/step/provider-settings/provider/extended/openstack/service';
import {ClusterSpecService} from '@core/services/cluster-spec';
import {DatacenterService} from '@core/services/datacenter';
import {PresetsService} from '@core/services/wizard/presets';
Expand Down Expand Up @@ -91,7 +94,7 @@ export class OpenstackProviderBasicComponent extends BaseFormValidator implement

ngOnInit(): void {
this.form = this._builder.group({
[Controls.Domain]: this._builder.control('', Validators.required),
[Controls.Domain]: this._builder.control(''),
[Controls.Credentials]: this._builder.control(''),
[Controls.FloatingIPPool]: this._builder.control('', Validators.required),
});
Expand Down Expand Up @@ -139,6 +142,15 @@ export class OpenstackProviderBasicComponent extends BaseFormValidator implement
.pipe(filter(_ => this._clusterSpecService.provider === NodeProvider.OPENSTACK))
.pipe(switchMap(_ => this._datacenterService.getDatacenter(this._clusterSpecService.datacenter).pipe(take(1))))
.pipe(tap(dc => (this._isFloatingPoolIPEnforced = dc?.spec.openstack.enforceFloatingIP)))
.pipe(
tap(_ => {
if (this._credentialsTypeService.credentialsType === CredentialsType.Default) {
this.form.get(Controls.Domain).setValidators(Validators.required);
} else {
this.form.get(Controls.Domain).clearValidators();
}
})
)
.pipe(takeUntil(this._unsubscribe))
.subscribe(_ => this.form.reset());
}
Expand All @@ -150,6 +162,8 @@ export class OpenstackProviderBasicComponent extends BaseFormValidator implement

isRequired(control: Controls): boolean {
switch (control) {
case Controls.Domain:
return this.form.get(Controls.Domain).hasValidator(Validators.required);
case Controls.FloatingIPPool:
return this._isFloatingPoolIPEnforced;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
[formControlName]="Controls.Domain"
[name]="Controls.Domain"
[matAutocomplete]="autoDomain"
required>
[required]="isRequired(Controls.Domain)">
<mat-autocomplete #autoDomain="matAutocomplete">
<mat-option *ngFor="let domain of domains"
[value]="domain.name">
Expand Down

0 comments on commit e1f2fd3

Please sign in to comment.