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

Option to enable Cilium Ingress for user clusters #6490

Merged
merged 1 commit into from
Feb 2, 2024
Merged
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
60 changes: 58 additions & 2 deletions modules/web/src/app/wizard/step/cluster/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Validators,
} from '@angular/forms';
import {MatDialog} from '@angular/material/dialog';
import {ApplicationService} from '@app/core/services/application';
import {DynamicModule} from '@app/dynamic/module-registry';
import {
IPV4_CIDR_PATTERN_VALIDATOR,
Expand Down Expand Up @@ -109,6 +110,7 @@ enum Controls {
NodePortsAllowedIPRanges = 'nodePortsAllowedIPRanges',
KubeLB = 'kubelb',
DisableCSIDriver = 'disableCSIDriver',
CiliumIngress = 'ciliumIngress',
}

@Component({
Expand Down Expand Up @@ -166,6 +168,7 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
private readonly _minNameLength = 5;
private readonly _canalDualStackMinimumSupportedVersion = '3.22.0';
private readonly _cniInitialValuesMinimumSupportedVersion = '1.13.0';
private readonly _cniCiliumApplicationName = 'cilium';

get isKubernetesDashboardEnabled(): boolean {
return this._settings.enableDashboard;
Expand All @@ -180,6 +183,7 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
private readonly _clusterSpecService: ClusterSpecService,
private readonly _datacenterService: DatacenterService,
private readonly _settingsService: SettingsService,
private readonly _applicationService: ApplicationService,
wizard: WizardService
) {
super(wizard);
Expand Down Expand Up @@ -348,6 +352,20 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
.pipe(takeUntil(this._unsubscribe))
.subscribe(_ => (this._clusterSpecService.cluster = this._getClusterEntity()));

if (!this.cniApplicationValues) {
this._applicationService
.getApplicationDefinition(this._cniCiliumApplicationName)
.pipe(takeUntil(this._unsubscribe))
.subscribe(appDef => (this.cniApplicationValues = this.initializeCiliumValues(appDef.spec.defaultValues)));
}

this.control(Controls.CiliumIngress)
.valueChanges.pipe(takeUntil(this._unsubscribe))
.subscribe(_ => {
this.updateCiliumCNIValues();
this._clusterSpecService.cluster = this._getClusterEntity();
});

this._handleClusterSpecChanges();
this._handleCNIPluginChanges();
this._updateAvailableProxyModes();
Expand Down Expand Up @@ -388,7 +406,6 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
isPodSecurityPolicyEnforced(): boolean {
return AdmissionPluginUtils.isPodSecurityPolicyEnforced(this._datacenterSpec);
}

getPluginName(name: string): string {
return AdmissionPluginUtils.getPluginName(name);
}
Expand All @@ -405,6 +422,10 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
return this.form.get(Controls.CNIPlugin).value !== CNIPlugin.None;
}

isCiliumSelected(): boolean {
return this.form.get(Controls.CNIPlugin).value === CNIPlugin.Cilium;
}

isAllowedIPRangeSupported(): boolean {
return [NodeProvider.AWS, NodeProvider.AZURE, NodeProvider.GCP, NodeProvider.OPENSTACK].includes(
this._clusterSpecService.provider
Expand Down Expand Up @@ -458,6 +479,7 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
[Controls.KubernetesDashboardEnabled]: this._builder.control(clusterSpec?.kubernetesDashboard?.enabled ?? true),
[Controls.KubeLB]: this._builder.control(clusterSpec?.kubelb?.enabled ?? false),
[Controls.DisableCSIDriver]: this._builder.control(clusterSpec?.disableCsiDriver ?? false),
[Controls.CiliumIngress]: this._builder.control(false),
[Controls.MLAMonitoring]: this._builder.control(clusterSpec?.mla?.monitoringEnabled ?? false),
[Controls.AdmissionPlugins]: this._builder.control(clusterSpec?.admissionPlugins ?? []),
[Controls.EventRateLimitConfig]: this._builder.control(clusterSpec?.eventRateLimitConfig ?? ''),
Expand Down Expand Up @@ -600,7 +622,10 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
this._updateAvailableProxyModes();
this._fetchCNIPlugins();
this._defaultProxyMode = clusterSpec?.clusterNetwork?.proxyMode;
this.cniApplicationValues = cluster.annotations?.[ClusterAnnotation.InitialCNIValuesRequest];

if (cluster.annotations?.[ClusterAnnotation.InitialCNIValuesRequest]) {
this.cniApplicationValues = cluster.annotations[ClusterAnnotation.InitialCNIValuesRequest];
}
this.loadingClusterDefaults = false;
this._cdr.detectChanges();
});
Expand Down Expand Up @@ -742,6 +767,27 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
}
}

private updateCiliumCNIValues(): void {
const ciliumIngress = this.controlValue(Controls.CiliumIngress);
if (ciliumIngress) {
let cniApplicationValues = JSON.parse(this.cniApplicationValues);
cniApplicationValues = {
...cniApplicationValues,
ingressController: {
enabled: true,
loadbalancerMode: 'shared',
default: true,
enforceHttps: false,
},
};
this.cniApplicationValues = JSON.stringify(cniApplicationValues);
} else {
const cniApplicationValues = JSON.parse(this.cniApplicationValues);
delete cniApplicationValues.ingressController;
this.cniApplicationValues = JSON.stringify(cniApplicationValues);
}
}

private _getExtraCloudSpecOptions(): ExtraCloudSpecOptions {
return (
this._clusterSpecService.cluster?.spec?.cloud[this._clusterSpecService.provider] || ({} as ExtraCloudSpecOptions)
Expand Down Expand Up @@ -832,4 +878,14 @@ export class ClusterStepComponent extends StepBase implements OnInit, ControlVal
} as ClusterSpec,
} as Cluster;
}

private initializeCiliumValues(valuesConfig: string | object): string {
if (typeof valuesConfig === 'string') {
return valuesConfig;
}
if (!_.isEmpty(valuesConfig)) {
return JSON.stringify(valuesConfig);
}
return null;
}
}
3 changes: 3 additions & 0 deletions modules/web/src/app/wizard/step/cluster/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
href="https://docs.kubermatic.com/kubermatic/{{editionVersion}}/tutorials-howtos/networking/expose-strategies/#configure-the-expose-strategy">here <i class="km-icon-external-link"></i></a>.
</mat-hint>
</mat-form-field>
<mat-checkbox *ngIf="isCiliumSelected()"
[formControlName]="Controls.CiliumIngress">Ingress <i class="km-icon-info km-pointer"
matTooltip="Enable Cilium kubernetes ingress supoort"></i></mat-checkbox>
<km-chip-list *ngIf="isExposeStrategyLoadBalancer()"
class="tag-list"
label="Allowed IP Ranges for API server"
Expand Down