diff --git a/pkg/harvester/config/feature-flags.js b/pkg/harvester/config/feature-flags.js
index f88e5a84..240ccfda 100644
--- a/pkg/harvester/config/feature-flags.js
+++ b/pkg/harvester/config/feature-flags.js
@@ -89,6 +89,7 @@ const FEATURE_FLAGS = {
'repositoryStorageClass',
'shutdownVMOnMigrationFailure',
'vmListPagination',
+ 'kubeovnBgp',
],
};
diff --git a/pkg/harvester/config/harvester-cluster.js b/pkg/harvester/config/harvester-cluster.js
index b3a7fc03..4e835d26 100644
--- a/pkg/harvester/config/harvester-cluster.js
+++ b/pkg/harvester/config/harvester-cluster.js
@@ -77,6 +77,8 @@ const EXTERNAL_IPS_GROUP = `${ NAT_INTERNET_GROUP }::External IPs`;
const RULES_GROUP = `${ NAT_INTERNET_GROUP }::Rules`;
const SOURCE_RULES_GROUP = `${ RULES_GROUP }::Source Rules`;
const DESTINATION_RULES_GROUP = `${ RULES_GROUP }::Destination Rules`;
+// The BGP speaker part of the Kube-OVN Configuration. If more parts get a form, they can move into a Configuration group.
+const BGP_SPEAKER = 'bgp-speaker';
export const PRODUCT_NAME = 'harvester';
@@ -664,6 +666,11 @@ export function init($plugin, store) {
OVERLAY_NETWORKS_GROUP
);
+ basicType(
+ [BGP_SPEAKER],
+ OVERLAY_NETWORKS_GROUP
+ );
+
basicType(
[HCI.VPC_NAT_GATEWAY, HCI.VPC_EGRESS_GATEWAY],
GATEWAYS_GROUP
@@ -962,6 +969,16 @@ export function init($plugin, store) {
ifHaveType: NETWORK_POLICY,
});
+ virtualType({
+ labelKey: 'harvester.bgp.label',
+ name: BGP_SPEAKER,
+ namespaced: false,
+ weight: 190,
+ route: { name: `${ PRODUCT_NAME }-c-cluster-bgp-speaker` },
+ exact: false,
+ ifHaveType: HCI.KUBEOVN_CONFIG,
+ });
+
configureType(HCI.PROVIDER_NETWORK, { hiddenNamespaceGroupButton: true, canYaml: false });
virtualType({
diff --git a/pkg/harvester/config/labels-annotations.js b/pkg/harvester/config/labels-annotations.js
index 676311c7..9fa784c2 100644
--- a/pkg/harvester/config/labels-annotations.js
+++ b/pkg/harvester/config/labels-annotations.js
@@ -92,6 +92,7 @@ export const HCI = {
NODE_UPGRADE_PAUSE_MAP: 'harvesterhci.io/node-upgrade-pause-map',
CDI_POPULATOR_KIND: 'cdi.kubevirt.io/storage.populator.kind',
CNI_NETWORKS: 'k8s.v1.cni.cncf.io/networks',
+ KUBEOVN_BGP: 'ovn.kubernetes.io/bgp',
WINDOWS_SYSPREP: 'harvesterhci.io/windows-sysprep',
SKIP_MIG_CONFIGURATION: 'harvesterhci.io/skip-mig-configuration',
};
diff --git a/pkg/harvester/edit/kubeovn.io.subnet/__tests__/index.test.js b/pkg/harvester/edit/kubeovn.io.subnet/__tests__/index.test.js
new file mode 100644
index 00000000..1094c83e
--- /dev/null
+++ b/pkg/harvester/edit/kubeovn.io.subnet/__tests__/index.test.js
@@ -0,0 +1,117 @@
+import EditSubnet from '../index.vue';
+
+const BGP_ANNOTATION = 'ovn.kubernetes.io/bgp';
+const { bgpEnabled } = EditSubnet.computed;
+
+function createContext(annotations) {
+ const value = {
+ metadata: annotations ? { annotations: { ...annotations } } : {},
+ setAnnotation(key, val) {
+ if (val) {
+ this.metadata.annotations = { ...this.metadata.annotations, [key]: val };
+ } else if (this.metadata.annotations) {
+ delete this.metadata.annotations[key];
+ }
+ },
+ };
+
+ return {
+ value,
+ get bgpEnabled() {
+ return bgpEnabled.get.call(this);
+ },
+ };
+}
+
+describe('edit: kubeovn.io.subnet BGP', () => {
+ it.each([
+ [undefined, false],
+ [{}, false],
+ [{ [BGP_ANNOTATION]: 'false' }, false],
+ [{ [BGP_ANNOTATION]: 'true' }, true],
+ [{ [BGP_ANNOTATION]: 'cluster' }, true],
+ [{ [BGP_ANNOTATION]: 'local' }, true],
+ ])('should read the annotations %j as BGP enabled = %s', (annotations, expected) => {
+ expect(createContext(annotations).bgpEnabled).toBe(expected);
+ });
+
+ it('should add the BGP annotation when BGP is enabled', () => {
+ const context = createContext();
+
+ bgpEnabled.set.call(context, true);
+
+ expect(context.value.metadata.annotations).toStrictEqual({ [BGP_ANNOTATION]: 'true' });
+ });
+
+ it('should remove the BGP annotation when BGP is disabled', () => {
+ const context = createContext({ [BGP_ANNOTATION]: 'true', other: 'kept' });
+
+ bgpEnabled.set.call(context, false);
+
+ expect(context.value.metadata.annotations).toStrictEqual({ other: 'kept' });
+ });
+
+ it('should keep a "local" annotation set outside the form when BGP stays enabled', () => {
+ const context = createContext({ [BGP_ANNOTATION]: 'local' });
+
+ bgpEnabled.set.call(context, true);
+
+ expect(context.value.metadata.annotations).toStrictEqual({ [BGP_ANNOTATION]: 'local' });
+ });
+});
+
+describe('edit: kubeovn.io.subnet BGP speaker hint', () => {
+ function fetchContext({ featureEnabled = true, configuration } = {}) {
+ const dispatch = jest.fn((action) => {
+ if (action === 'harvester/find') {
+ return configuration instanceof Error ? Promise.reject(configuration) : Promise.resolve(configuration);
+ }
+
+ return Promise.resolve([]);
+ });
+
+ return {
+ bgpFeatureEnabled: featureEnabled,
+ bgpSpeakerOff: false,
+ $store: {
+ dispatch,
+ getters: {
+ currentProduct: { inStore: 'harvester' },
+ 'harvester/schemaFor': () => ({}),
+ },
+ },
+ };
+ }
+
+ it.each([
+ ['no speaker hosts', { bgpSpeakerHosts: [] }, true],
+ ['speaker hosts', { bgpSpeakerHosts: ['node-1'] }, false],
+ ])('should know whether a host runs the BGP speaker: %s', async(_, configuration, speakerOff) => {
+ const context = fetchContext({ configuration });
+
+ await EditSubnet.fetch.call(context);
+
+ expect(context.$store.dispatch).toHaveBeenCalledWith('harvester/find', { type: 'kubeovn.io.configuration', id: 'kube-system/kubeovn' });
+ expect(context.bgpSpeakerOff).toBe(speakerOff);
+ });
+
+ it('should not warn when the Kube-OVN configuration cannot be read', async() => {
+ const context = fetchContext({ configuration: new Error('forbidden') });
+
+ await EditSubnet.fetch.call(context);
+
+ expect(context.bgpSpeakerOff).toBe(false);
+ });
+
+ it('should not read the Kube-OVN configuration on Harvester versions without BGP support', async() => {
+ const context = fetchContext({ featureEnabled: false });
+
+ await EditSubnet.fetch.call(context);
+
+ expect(context.$store.dispatch).not.toHaveBeenCalledWith('harvester/find', expect.anything());
+ });
+
+ it('should link to the BGP Speaker page', () => {
+ expect(EditSubnet.computed.bgpSettingsLocation.call({})).toStrictEqual({ name: 'harvester-c-cluster-bgp-speaker' });
+ });
+});
diff --git a/pkg/harvester/edit/kubeovn.io.subnet/index.vue b/pkg/harvester/edit/kubeovn.io.subnet/index.vue
index b9ed162f..619fb2e3 100644
--- a/pkg/harvester/edit/kubeovn.io.subnet/index.vue
+++ b/pkg/harvester/edit/kubeovn.io.subnet/index.vue
@@ -13,8 +13,12 @@ import { set, remove } from '@shell/utils/object';
import ArrayList from '@shell/components/form/ArrayList';
import { allHash } from '@shell/utils/promise';
import { HCI } from '../../types';
+import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
import ResourceTabs from '@shell/components/form/ResourceTabs/index';
import { Banner } from '@components/Banner';
+import MessageLink from '@shell/components/MessageLink';
+import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../config/harvester';
+import { KUBEOVN_CONFIGURATION_ID } from '../../models/kubeovn.io.configuration';
import AccessControlList from './AccessControlList';
export default {
@@ -33,6 +37,7 @@ export default {
ArrayList,
ResourceTabs,
Loading,
+ MessageLink,
AccessControlList
},
@@ -40,6 +45,10 @@ export default {
inheritAttrs: false,
+ data() {
+ return { bgpSpeakerOff: false };
+ },
+
created() {
const vpc = this.$route.query.vpc || '';
const enableDHCP = this.value?.spec?.enableDHCP || false;
@@ -69,7 +78,16 @@ export default {
vlans: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VLAN }),
};
- await allHash(hash);
+ // BGP on a subnet only has an effect when some host runs the BGP speaker (Overlay Networks > Settings)
+ if (this.bgpFeatureEnabled && this.$store.getters[`${ inStore }/schemaFor`](HCI.KUBEOVN_CONFIG)) {
+ hash.kubeovnConfig = this.$store.dispatch(`${ inStore }/find`, { type: HCI.KUBEOVN_CONFIG, id: KUBEOVN_CONFIGURATION_ID }).catch(() => null);
+ }
+
+ const res = await allHash(hash);
+
+ if (res.kubeovnConfig) {
+ this.bgpSpeakerOff = !res.kubeovnConfig.bgpSpeakerHosts?.length;
+ }
},
computed: {
@@ -133,6 +151,29 @@ export default {
value: n.id,
}));
},
+ bgpFeatureEnabled() {
+ return this.$store.getters['harvester-common/getFeatureEnabled']('kubeovnBgp');
+ },
+
+ bgpSettingsLocation() {
+ return { name: `${ HARVESTER_PRODUCT }-c-cluster-bgp-speaker` };
+ },
+
+ bgpEnabled: {
+ get() {
+ const bgp = this.value?.metadata?.annotations?.[HCI_ANNOTATIONS.KUBEOVN_BGP];
+
+ // Kube-OVN also accepts "cluster" (same as "true") and "local" (only the pod IPs, from the hosts running them)
+ return !!bgp && bgp !== 'false';
+ },
+
+ set(enabled) {
+ if (enabled !== this.bgpEnabled) {
+ this.value.setAnnotation(HCI_ANNOTATIONS.KUBEOVN_BGP, enabled ? 'true' : null);
+ }
+ }
+ },
+
natOutgoingDisabled() {
// Disable the NAT Outgoing option when the subnet belongs to the ovn-cluster VPC and its name is join or ovn-default.
return this.value?.spec?.vpc === 'ovn-cluster' && ['join', 'ovn-default'].includes(this.value?.metadata?.name);
@@ -369,6 +410,40 @@ export default {
/>
+
BGP Speaker.
+ externalGateway: Label the hosts that act as gateways for external traffic with the key "ovn.kubernetes.io/external-gw" and the value "true".
+ speakerOff:
+ prefix: No host runs the BGP speaker yet, so this subnet isn't advertised. Set it up on the
+ middle: BGP Speaker
+ suffix: page under Overlay Networks.
allowSubnet:
label: Allow Subnets
tooltip: You can specify certain subnets which can communicate with this subnet.
@@ -1515,6 +1523,63 @@ harvester:
validation:
ip: '"IP Address" must be an IPv4 address, an IPv6 address, or one of each separated by a comma.'
subnet: '"IP Address" must not be in subnet {subnet} ({cidr}) of this VPC.'
+ bgp:
+ label: BGP Speaker
+ noAddonEnabled:
+ prefix: The kubeovn-operator add-on is not enabled, click
+ middle: here
+ suffix: to enable the add-on before setting up the BGP speaker.
+ unsupported: The BGP speaker requires [[Harvester]] v1.10.0 or later.
+ description: The BGP speaker runs on the selected hosts and advertises every subnet that has BGP enabled to the BGP neighbors. Enable BGP on each subnet that should be reachable from the external network. When the speaker is disabled, no host runs it, and its settings are kept for when you enable it again.
+ sections:
+ advanced: Advanced
+ nodeNames:
+ label: Speaker Hosts
+ placeholder: Select hosts
+ tooltip: The hosts that run the BGP speaker. Each host connects to every neighbor.
+ clusterAS:
+ label: Cluster AS
+ placeholder: e.g. 65000
+ tooltip: The autonomous system (AS) number of this cluster.
+ routerID:
+ label: Router ID
+ placeholder: Each host's own IPv4 address
+ tooltip: Optional. Leave it empty so each host uses its own IPv4 address. Set it only when a single host runs the speaker.
+ neighborAS:
+ label: Neighbor AS
+ placeholder: e.g. 65030
+ tooltip: The autonomous system (AS) number of the neighbors. All neighbors must be in the same AS.
+ neighbors:
+ label: Neighbors
+ description: The addresses of the external BGP routers the speaker connects to. Add at least one, IPv4 or IPv6.
+ neighborsV4:
+ label: IPv4 Address
+ placeholder: e.g. 10.115.53.2
+ add: Add IPv4 Neighbor
+ neighborsV6:
+ label: IPv6 Address
+ placeholder: e.g. 2001:db8::2
+ add: Add IPv6 Neighbor
+ nextHopV4:
+ label: Next Hop (IPv4)
+ placeholder: Each host's own address
+ tooltip: Optional. The IPv4 next hop of the advertised routes. Leave it empty to use each host's own address.
+ nextHopV6:
+ label: Next Hop (IPv6)
+ placeholder: Each host's own address
+ tooltip: Optional. The IPv6 next hop of the advertised routes. Leave it empty to use each host's own address.
+ validation:
+ hostsRequired: Select at least one speaker host, or set the BGP speaker to Disabled.
+ neighborRequired: Add at least one neighbor address, IPv4 or IPv6.
+ neighborV4: '"{ip}" is not an IPv4 address.'
+ neighborV6: '"{ip}" is not an IPv6 address.'
+ placeholderNeighbor: '{ip} is the placeholder address Harvester installs, not a BGP router.'
+ leadingZero: '"{ip}" has a leading zero; write it as {fixed}.'
+ asNumber: '"{key}" must be a whole number from 1 to {max}.'
+ routerID: '"Router ID" must be an IPv4 address.'
+ routerIDMultipleHosts: Leave "Router ID" empty when more than one host runs the speaker, so each host uses its own address.
+ ipv4: '"{key}" must be an IPv4 address.'
+ ipv6: '"{key}" must be an IPv6 address.'
natGateway:
label: NAT Gateways
internalTenantNetwork:
diff --git a/pkg/harvester/models/kubeovn.io.configuration.js b/pkg/harvester/models/kubeovn.io.configuration.js
new file mode 100644
index 00000000..3004cf98
--- /dev/null
+++ b/pkg/harvester/models/kubeovn.io.configuration.js
@@ -0,0 +1,74 @@
+import { isIpv4 } from '@shell/utils/string';
+import { isValidIP } from '@shell/utils/validators/cidr';
+import HarvesterResource from './harvester';
+
+// The kubeovn-operator keeps a single Configuration; the BGP speaker reads its spec.bgp
+export const KUBEOVN_CONFIGURATION_ID = 'kube-system/kubeovn';
+
+// Values Harvester installs before anyone sets up BGP. The addresses are documentation addresses, never a real neighbor.
+const PLACEHOLDER_AS = { neighborAS: 64512, clusterAS: 64513 };
+const PLACEHOLDER_NEIGHBORS = ['192.0.2.1', '2001:db8::1'];
+
+// spec.bgp keeps its lists as comma-separated strings
+const splitList = (value) => `${ value || '' }`.split(',').map((item) => item.trim()).filter(Boolean);
+
+export const isIpv6 = (ip) => isValidIP(ip) && !isIpv4(ip);
+
+export const isPlaceholderNeighbor = (ip) => PLACEHOLDER_NEIGHBORS.includes(`${ ip || '' }`.trim());
+
+// The speaker parses its addresses with Go, which rejects an IPv4 part written with a leading zero (192.0.2.010), so
+// the speaker would not start. Returns the address without those zeros, or null when it has none. An IPv6 address
+// can end in an IPv4 one (::ffff:10.0.0.1), so only its dotted tail is checked.
+export const withoutLeadingZeros = (ip) => {
+ const value = `${ ip || '' }`.trim();
+ const tailStart = value.lastIndexOf(':') + 1;
+ const parts = value.slice(tailStart).split('.');
+
+ if (parts.length !== 4 || !parts.some((part) => /^0\d/.test(part))) {
+ return null;
+ }
+
+ return value.slice(0, tailStart) + parts.map((part) => part.replace(/^0+(?=\d)/, '')).join('.');
+};
+
+export default class KubeOvnConfiguration extends HarvesterResource {
+ get bgp() {
+ return this.spec?.bgp || {};
+ }
+
+ // The speaker only runs on these hosts: none means BGP is off
+ get bgpSpeakerHosts() {
+ return splitList(this.bgp.nodeNames);
+ }
+
+ // The placeholder neighbors are left out: they are never a real BGP router
+ get bgpNeighborsV4() {
+ return splitList(this.bgp.neighborV4Address).filter((ip) => !isPlaceholderNeighbor(ip));
+ }
+
+ get bgpNeighborsV6() {
+ return splitList(this.bgp.neighborV6Address).filter((ip) => !isPlaceholderNeighbor(ip));
+ }
+
+ get bgpNeighbors() {
+ return [...this.bgpNeighborsV4, ...this.bgpNeighborsV6];
+ }
+
+ get bgpNextHops() {
+ return splitList(this.bgp.nextHops);
+ }
+
+ // Nobody has set up BGP yet: only the values Harvester installs. A speaker that was set up and then disabled keeps
+ // its neighbors, so it never matches, even when its AS numbers happen to be the placeholder ones (they are private
+ // AS numbers anyone can pick).
+ get bgpUntouched() {
+ const bgp = this.bgp;
+
+ return !this.bgpSpeakerHosts.length &&
+ !this.bgpNeighbors.length &&
+ !bgp.routerID &&
+ !this.bgpNextHops.length &&
+ bgp.neighborAS === PLACEHOLDER_AS.neighborAS &&
+ bgp.clusterAS === PLACEHOLDER_AS.clusterAS;
+ }
+}
diff --git a/pkg/harvester/pages/c/_cluster/bgp-speaker/__tests__/index.test.js b/pkg/harvester/pages/c/_cluster/bgp-speaker/__tests__/index.test.js
new file mode 100644
index 00000000..c0d4f6ae
--- /dev/null
+++ b/pkg/harvester/pages/c/_cluster/bgp-speaker/__tests__/index.test.js
@@ -0,0 +1,441 @@
+import { shallowMount } from '@vue/test-utils';
+import { Banner } from '@components/Banner';
+import ArrayList from '@shell/components/form/ArrayList';
+import CruResource from '@shell/components/CruResource';
+import { RcSection } from '@components/RcSection';
+import OverlayNetworkSettings from '../index.vue';
+import KubeOvnConfiguration, { withoutLeadingZeros } from '../../../../../models/kubeovn.io.configuration';
+
+// What Harvester installs before anyone sets up BGP
+const PLACEHOLDER_BGP = {
+ neighborV4Address: '192.0.2.1',
+ neighborV6Address: '2001:db8::1',
+ neighborAS: 64512,
+ clusterAS: 64513,
+};
+
+const CONFIGURED_BGP = {
+ nodeNames: 'node-1',
+ neighborV4Address: '10.115.53.2',
+ neighborV6Address: '2001:db8::1',
+ neighborAS: 65030,
+ clusterAS: 65000,
+};
+
+// A real model, so the page reads the same getters as in the app
+function createConfiguration(bgp = PLACEHOLDER_BGP) {
+ const configuration = Object.create(KubeOvnConfiguration.prototype);
+
+ Object.defineProperty(configuration, 'spec', {
+ value: { enableBGP: true, bgp: { ...bgp } }, writable: true, configurable: true
+ });
+ Object.defineProperty(configuration, 'canUpdate', { value: true, configurable: true });
+ Object.defineProperty(configuration, 'save', { value: jest.fn().mockResolvedValue({}), configurable: true });
+
+ return configuration;
+}
+
+// latest: what the API returns at save time, when it differs from the copy loaded with the page
+// findError: the API refuses to return the Configuration
+function mountPage({
+ featureEnabled = true, addonEnabled = true, configuration = createConfiguration(), latest = null, findError = null
+} = {}) {
+ const dispatch = jest.fn((action, payload) => {
+ if (action === 'harvester/find') {
+ return findError ? Promise.reject(findError) : Promise.resolve(latest || configuration);
+ }
+
+ if (action === 'harvester/clone') {
+ return Promise.resolve(payload.resource);
+ }
+
+ if (action === 'harvester/findAll' && payload.type === 'harvesterhci.io.addon') {
+ return Promise.resolve([{ name: 'kubeovn-operator', spec: { enabled: addonEnabled } }]);
+ }
+
+ return Promise.resolve([]);
+ });
+ const router = { push: jest.fn() };
+
+ const wrapper = shallowMount(OverlayNetworkSettings, {
+ data: () => ({ addonEnabled, configuration }),
+ global: {
+ // the section and the form are stubbed, but what they hold is rendered
+ renderStubDefaultSlot: true,
+ mocks: {
+ $fetchState: { pending: false },
+ $router: router,
+ t: (key, args) => (args ? `${ key } ${ JSON.stringify(args) }` : key),
+ $store: {
+ dispatch,
+ getters: {
+ currentProduct: { inStore: 'harvester' },
+ 'harvester/all': () => [],
+ 'harvester-common/getFeatureEnabled': () => featureEnabled,
+ },
+ },
+ },
+ },
+ });
+
+ if (configuration) {
+ wrapper.vm.loadBgp(configuration);
+ }
+
+ return {
+ wrapper, configuration, dispatch, router
+ };
+}
+
+// A valid, enabled form; each case overrides what it checks
+function fill(wrapper, values) {
+ wrapper.setData({
+ bgpEnabled: true,
+ nodeNames: ['node-1'],
+ neighborsV4: ['10.115.53.2'],
+ neighborsV6: [],
+ neighborAS: '65030',
+ clusterAS: '65000',
+ routerID: '',
+ nextHopV4: '',
+ nextHopV6: '',
+ ...values,
+ });
+}
+
+describe('page: Overlay Networks > BGP Speaker', () => {
+ it('should load an untouched install as disabled, without the placeholder values', async() => {
+ const { wrapper, dispatch } = mountPage();
+
+ await OverlayNetworkSettings.fetch.call(wrapper.vm);
+
+ expect(dispatch).toHaveBeenCalledWith('harvester/find', { type: 'kubeovn.io.configuration', id: 'kube-system/kubeovn' });
+ expect(wrapper.vm.formState()).toStrictEqual({
+ enabled: false,
+ nodeNames: [],
+ neighborsV4: [],
+ neighborsV6: [],
+ neighborAS: '',
+ clusterAS: '',
+ routerID: '',
+ nextHopV4: '',
+ nextHopV6: '',
+ });
+ });
+
+ it('should keep the AS numbers of a disabled speaker, even when they are the ones Harvester installs', () => {
+ // set up with the private AS numbers 64512/64513, then disabled: only the hosts are gone
+ const configuration = createConfiguration({ ...PLACEHOLDER_BGP, neighborV4Address: '10.115.53.2' });
+ const { wrapper } = mountPage({ configuration });
+
+ expect(wrapper.vm.formState()).toStrictEqual({
+ enabled: false,
+ nodeNames: [],
+ neighborsV4: ['10.115.53.2'],
+ neighborsV6: [],
+ neighborAS: '64512',
+ clusterAS: '64513',
+ routerID: '',
+ nextHopV4: '',
+ nextHopV6: '',
+ });
+ });
+
+ it('should load a configured speaker, with each neighbor family in its own list', () => {
+ const configuration = createConfiguration({
+ ...CONFIGURED_BGP, nodeNames: 'node-1,node-2', neighborV6Address: '2001:db8::2', nextHops: '10.115.48.1,2001:db8::9'
+ });
+ const { wrapper } = mountPage({ configuration });
+
+ expect(wrapper.vm.formState()).toStrictEqual({
+ enabled: true,
+ nodeNames: ['node-1', 'node-2'],
+ neighborsV4: ['10.115.53.2'],
+ neighborsV6: ['2001:db8::2'],
+ neighborAS: '65030',
+ clusterAS: '65000',
+ routerID: '',
+ nextHopV4: '10.115.48.1',
+ nextHopV6: '2001:db8::9',
+ });
+ });
+
+ it('should edit the BGP speaker on this page, titled BGP Speaker, without a Cancel button', () => {
+ const { wrapper } = mountPage();
+
+ expect(wrapper.find('h1').text()).toBe('harvester.bgp.label');
+ // the page title names it, so the outer section has no header of its own
+ expect(wrapper.findComponent(RcSection).props()).toStrictEqual(expect.objectContaining({ type: 'primary', mode: 'no-header' }));
+ expect(wrapper.findComponent(CruResource).props('showCancel')).toBe(false);
+ });
+
+ it('should name the Enabled/Disabled choice and both neighbor lists for screen readers', async() => {
+ const { wrapper } = mountPage({ configuration: createConfiguration(CONFIGURED_BGP) });
+
+ await wrapper.vm.$nextTick();
+
+ expect(wrapper.find('[data-testid="bgp-enabled"]').attributes('aria-label')).toBe('harvester.bgp.label');
+ expect(wrapper.findAllComponents(ArrayList).map((list) => list.props('a11yLabel'))).toStrictEqual([
+ 'harvester.bgp.neighborsV4.label',
+ 'harvester.bgp.neighborsV6.label',
+ ]);
+ });
+
+ it('should group the neighbors and the advanced options in their own sections when the speaker is enabled', async() => {
+ const { wrapper } = mountPage({ configuration: createConfiguration(CONFIGURED_BGP) });
+
+ await wrapper.vm.$nextTick();
+
+ expect(wrapper.findAllComponents(RcSection).map((section) => [section.props('title'), section.props('type')])).toStrictEqual([
+ ['', 'primary'],
+ ['harvester.bgp.neighbors.label', 'secondary'],
+ ['harvester.bgp.sections.advanced', 'secondary'],
+ ]);
+ });
+
+ it('should say the BGP speaker needs v1.10.0 on older Harvester versions', () => {
+ const { wrapper } = mountPage({ featureEnabled: false, configuration: null });
+
+ expect(wrapper.findComponent(RcSection).exists()).toBe(true);
+ expect(wrapper.findAllComponents(Banner).map((b) => b.props('label'))).toStrictEqual(['harvester.bgp.unsupported']);
+ expect(wrapper.findComponent(CruResource).exists()).toBe(false);
+ });
+
+ it('should only point to the add-on when it is disabled', () => {
+ const { wrapper } = mountPage({ addonEnabled: false, configuration: null });
+ const banners = wrapper.findAllComponents(Banner);
+
+ expect(banners).toHaveLength(1);
+ expect(banners[0].props('color')).toBe('warning');
+ expect(wrapper.findComponent(CruResource).exists()).toBe(false);
+ });
+
+ it('should show why there is no form when the configuration cannot be read', async() => {
+ const findError = Object.assign(new Error('configurations.kubeovn.io "kubeovn" is forbidden'), { status: 403 });
+ const { wrapper } = mountPage({ configuration: null, findError });
+
+ await OverlayNetworkSettings.fetch.call(wrapper.vm);
+ await wrapper.vm.$nextTick();
+
+ expect(wrapper.vm.configuration).toBeNull();
+ expect(wrapper.findAllComponents(Banner).map((b) => b.props('label'))).toStrictEqual(['configurations.kubeovn.io "kubeovn" is forbidden']);
+ });
+
+ it('should link to the kubeovn-operator add-on by route name', () => {
+ const { wrapper } = mountPage();
+
+ expect(wrapper.vm.addonLocation).toStrictEqual({
+ name: 'harvester-c-cluster-resource-namespace-id',
+ params: {
+ resource: 'harvesterhci.io.addon', namespace: 'kube-system', id: 'kubeovn-operator'
+ },
+ query: { mode: 'edit' },
+ });
+ });
+
+ it('should not load the configuration when the add-on is disabled', async() => {
+ const { wrapper, dispatch } = mountPage({ addonEnabled: false, configuration: null });
+
+ await OverlayNetworkSettings.fetch.call(wrapper.vm);
+
+ expect(wrapper.vm.addonEnabled).toBe(false);
+ expect(dispatch).not.toHaveBeenCalledWith('harvester/find', expect.anything());
+ });
+
+ it('should save both neighbor lists without duplicates or empty rows, keep the rest of the configuration and stay on the page', async() => {
+ const { wrapper, configuration, router } = mountPage();
+ const buttonCb = jest.fn();
+
+ fill(wrapper, {
+ nodeNames: ['node-1', 'node-2'],
+ neighborsV4: [' 10.115.53.2 ', '10.115.53.3', '10.115.53.2', ''],
+ neighborsV6: ['2001:db8::2', ''],
+ nextHopV4: '10.115.48.1',
+ nextHopV6: '2001:db8::9',
+ });
+
+ await wrapper.vm.save(buttonCb);
+
+ expect(buttonCb).toHaveBeenCalledWith(true);
+ expect(configuration.save).toHaveBeenCalledTimes(1);
+ expect(configuration.spec).toStrictEqual({
+ enableBGP: true,
+ bgp: {
+ nodeNames: 'node-1,node-2',
+ neighborV4Address: '10.115.53.2,10.115.53.3',
+ neighborV6Address: '2001:db8::2',
+ neighborAS: 65030,
+ clusterAS: 65000,
+ nextHops: '10.115.48.1,2001:db8::9',
+ },
+ });
+ expect(router.push).not.toHaveBeenCalled();
+ // the form now shows what was saved, so saving again without a change writes nothing
+ expect(wrapper.vm.formState()).toStrictEqual(expect.objectContaining({ neighborsV4: ['10.115.53.2', '10.115.53.3'], neighborsV6: ['2001:db8::2'] }));
+
+ await wrapper.vm.save(buttonCb);
+
+ expect(configuration.save).toHaveBeenCalledTimes(1);
+ });
+
+ it('should save on top of the latest copy of the configuration', async() => {
+ // the operator updated the Configuration after the page loaded it
+ const latest = createConfiguration();
+
+ latest.spec = {
+ enableBGP: false, ovnCentral: { replicas: 3 }, bgp: { ...PLACEHOLDER_BGP }
+ };
+ const { wrapper, configuration, dispatch } = mountPage({ latest });
+
+ fill(wrapper);
+
+ await wrapper.vm.save(jest.fn());
+
+ expect(dispatch).toHaveBeenCalledWith('harvester/find', {
+ type: 'kubeovn.io.configuration', id: 'kube-system/kubeovn', opt: { force: true }
+ });
+ expect(configuration.save).not.toHaveBeenCalled();
+ expect(latest.save).toHaveBeenCalledTimes(1);
+ expect(latest.spec).toStrictEqual({
+ enableBGP: false,
+ ovnCentral: { replicas: 3 },
+ bgp: {
+ nodeNames: 'node-1', neighborV4Address: '10.115.53.2', neighborAS: 65030, clusterAS: 65000
+ },
+ });
+ });
+
+ it('should only remove the speaker hosts when BGP is disabled', async() => {
+ const { wrapper, configuration } = mountPage({ configuration: createConfiguration(CONFIGURED_BGP) });
+
+ // invalid values are ignored while disabled
+ fill(wrapper, { bgpEnabled: false, neighborAS: '' });
+
+ expect(wrapper.vm.validationPassed).toBe(true);
+ await wrapper.vm.save(jest.fn());
+
+ const { nodeNames, ...rest } = CONFIGURED_BGP;
+
+ expect(configuration.spec.bgp).toStrictEqual(rest);
+ });
+
+ it.each([
+ ['an untouched install', PLACEHOLDER_BGP],
+ ['a configured speaker', CONFIGURED_BGP],
+ ])('should not save the configuration when nothing changed on %s', async(_, bgp) => {
+ const { wrapper, configuration, router } = mountPage({ configuration: createConfiguration(bgp) });
+ const buttonCb = jest.fn();
+
+ await wrapper.vm.save(buttonCb);
+
+ expect(configuration.save).not.toHaveBeenCalled();
+ expect(buttonCb).toHaveBeenCalledWith(true);
+ expect(router.push).not.toHaveBeenCalled();
+ });
+
+ it('should report a failed save as plain messages and stay on the page', async() => {
+ const { wrapper, configuration, router } = mountPage();
+ const buttonCb = jest.fn();
+
+ configuration.save.mockRejectedValue({ status: 409, message: 'the object has been modified' });
+ fill(wrapper);
+
+ await wrapper.vm.save(buttonCb);
+
+ expect(buttonCb).toHaveBeenCalledWith(false);
+ expect(wrapper.vm.errors).toStrictEqual(['the object has been modified']);
+ expect(router.push).not.toHaveBeenCalled();
+ });
+
+ it.each([
+ ['no speaker hosts', { nodeNames: [] }, 'harvester.bgp.validation.hostsRequired'],
+ ['no neighbor', { neighborsV4: ['', ' '], neighborsV6: [''] }, 'harvester.bgp.validation.neighborRequired'],
+ ['an invalid IPv4 neighbor', { neighborsV4: ['10.115.53.300'] }, 'harvester.bgp.validation.neighborV4'],
+ ['an IPv6 address in the IPv4 neighbors', { neighborsV4: ['2001:db8::2'] }, 'harvester.bgp.validation.neighborV4'],
+ ['an IPv4 address in the IPv6 neighbors', { neighborsV4: [], neighborsV6: ['10.115.53.2'] }, 'harvester.bgp.validation.neighborV6'],
+ ['the IPv4 placeholder neighbor', { neighborsV4: ['192.0.2.1'] }, 'harvester.bgp.validation.placeholderNeighbor'],
+ ['the IPv6 placeholder neighbor', { neighborsV6: ['2001:db8::1'] }, 'harvester.bgp.validation.placeholderNeighbor'],
+ ['an IPv4 neighbor with a leading zero', { neighborsV4: ['192.0.2.010'] }, 'harvester.bgp.validation.leadingZero'],
+ ['an IPv6 neighbor ending in an IPv4 address with a leading zero', { neighborsV6: ['::ffff:10.0.0.010'] }, 'harvester.bgp.validation.leadingZero'],
+ ['a router ID with a leading zero', { routerID: '10.115.048.1' }, 'harvester.bgp.validation.leadingZero'],
+ ['an IPv4 next hop with a leading zero', { nextHopV4: '010.115.48.1' }, 'harvester.bgp.validation.leadingZero'],
+ ['an IPv6 next hop ending in an IPv4 address with a leading zero', { nextHopV6: '::ffff:10.115.48.01' }, 'harvester.bgp.validation.leadingZero'],
+ ['an empty AS number', { neighborAS: '' }, 'harvester.bgp.validation.asNumber'],
+ ['an AS number out of range', { clusterAS: '4294967295' }, 'harvester.bgp.validation.asNumber'],
+ ['a router ID that is not IPv4', { routerID: '2001:db8::1' }, 'harvester.bgp.validation.routerID'],
+ ['a router ID shared by two hosts', { nodeNames: ['node-1', 'node-2'], routerID: '10.115.48.1' }, 'harvester.bgp.validation.routerIDMultipleHosts'],
+ ['an IPv6 address as the IPv4 next hop', { nextHopV4: '2001:db8::9' }, 'harvester.bgp.validation.ipv4'],
+ ['an IPv4 address as the IPv6 next hop', { nextHopV6: '10.115.48.1' }, 'harvester.bgp.validation.ipv6'],
+ ])('should disable Save and not save %s', async(_, values, errorKey) => {
+ const { wrapper, configuration } = mountPage();
+ const buttonCb = jest.fn();
+
+ fill(wrapper, values);
+
+ expect(wrapper.vm.validationPassed).toBe(false);
+
+ await wrapper.vm.save(buttonCb);
+
+ expect(buttonCb).toHaveBeenCalledWith(false);
+ expect(wrapper.vm.errors).toStrictEqual([expect.stringContaining(errorKey)]);
+ expect(configuration.save).not.toHaveBeenCalled();
+ });
+
+ it('should flag missing speaker hosts and neighbors on the fields', async() => {
+ const { wrapper } = mountPage();
+ const [hostsRule] = wrapper.vm.nodeNamesRules;
+ const [v4Rule] = wrapper.vm.neighborV4Rules;
+ const [v6Rule] = wrapper.vm.neighborV6Rules;
+
+ fill(wrapper, {
+ nodeNames: [], neighborsV4: [''], neighborsV6: ['']
+ });
+
+ expect(hostsRule([])).toContain('harvester.bgp.validation.hostsRequired');
+ expect(hostsRule(['node-1'])).toBeUndefined();
+ // no neighbor yet: both lists say so
+ expect(v4Rule('')).toContain('harvester.bgp.validation.neighborRequired');
+ expect(v6Rule('')).toContain('harvester.bgp.validation.neighborRequired');
+
+ await wrapper.setData({ neighborsV6: ['2001:db8::2'] });
+
+ // one neighbor in either list is enough; an address of the wrong family is flagged
+ expect(v4Rule('')).toBeUndefined();
+ expect(v4Rule('2001:db8::2')).toContain('harvester.bgp.validation.neighborV4');
+ expect(v6Rule('10.115.53.2')).toContain('harvester.bgp.validation.neighborV6');
+ expect(v6Rule('2001:db8::1')).toContain('harvester.bgp.validation.placeholderNeighbor');
+ });
+
+ it.each([
+ ['192.0.2.010', '192.0.2.10'],
+ ['010.115.053.002', '10.115.53.2'],
+ ['10.0.0.00', '10.0.0.0'],
+ ['::ffff:10.0.0.010', '::ffff:10.0.0.10'],
+ ['192.0.2.10', null],
+ ['0.0.0.0', null],
+ ['2001:db8::0002', null],
+ ['', null],
+ ])('should find the leading zeros the speaker cannot parse in %j', (ip, fixed) => {
+ expect(withoutLeadingZeros(ip)).toBe(fixed);
+ });
+
+ it('should say how to write an address with a leading zero', () => {
+ const { wrapper } = mountPage();
+ const [rule] = wrapper.vm.neighborV4Rules;
+
+ fill(wrapper);
+
+ expect(rule('192.0.2.010')).toBe('harvester.bgp.validation.leadingZero {"ip":"192.0.2.010","fixed":"192.0.2.10"}');
+ });
+
+ it('should flag a router ID inline as soon as a second host is picked', async() => {
+ const { wrapper } = mountPage();
+ const [rule] = wrapper.vm.routerIDRules;
+
+ fill(wrapper, { routerID: '10.115.48.1' });
+ expect(rule('10.115.48.1')).toBeUndefined();
+
+ await wrapper.setData({ nodeNames: ['node-1', 'node-2'] });
+ expect(rule('10.115.48.1')).toContain('harvester.bgp.validation.routerIDMultipleHosts');
+ });
+});
diff --git a/pkg/harvester/pages/c/_cluster/bgp-speaker/index.vue b/pkg/harvester/pages/c/_cluster/bgp-speaker/index.vue
new file mode 100644
index 00000000..74d5c155
--- /dev/null
+++ b/pkg/harvester/pages/c/_cluster/bgp-speaker/index.vue
@@ -0,0 +1,588 @@
+
+
+
+
+
+
+ {{ t('harvester.bgp.label') }}
+
+
errors = e"
+ >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ t('harvester.bgp.neighbors.description') }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pkg/harvester/routing/harvester-routing.js b/pkg/harvester/routing/harvester-routing.js
index 055c8545..5c3385ab 100644
--- a/pkg/harvester/routing/harvester-routing.js
+++ b/pkg/harvester/routing/harvester-routing.js
@@ -19,6 +19,7 @@ import HarvesterUnsupported from '../pages/c/_cluster/unsupported/index.vue';
import ForkliftDashboard from '../pages/c/_cluster/vm-migration/index.vue';
import ForkliftVmMigrationWizard from '../pages/c/_cluster/vm-migration/vm-migration-wizard.vue';
import ForkliftProviderWizard from '../pages/c/_cluster/vm-migration/provider-wizard.vue';
+import BgpSpeaker from '../pages/c/_cluster/bgp-speaker/index.vue';
const routes = [
{
@@ -98,6 +99,10 @@ const routes = [
name: `${ PRODUCT_NAME }-c-cluster-vm-migration-provider-wizard`,
path: `/:product/c/:cluster/vm-migration/provider-wizard`,
component: ForkliftProviderWizard,
+ }, {
+ name: `${ PRODUCT_NAME }-c-cluster-bgp-speaker`,
+ path: `/:product/c/:cluster/bgp-speaker`,
+ component: BgpSpeaker,
}, {
name: `${ PRODUCT_NAME }-c-cluster-resource`,
path: `/:product/c/:cluster/:resource`,
diff --git a/pkg/harvester/types.ts b/pkg/harvester/types.ts
index 9cfc94e0..e7c7f2cc 100644
--- a/pkg/harvester/types.ts
+++ b/pkg/harvester/types.ts
@@ -33,6 +33,7 @@ export const HCI = {
PROVIDER_NETWORK: 'kubeovn.io.providernetwork',
VPC_NAT_GATEWAY: 'kubeovn.io.vpcnatgateway',
VPC_EGRESS_GATEWAY: 'kubeovn.io.vpcegressgateway',
+ KUBEOVN_CONFIG: 'kubeovn.io.configuration',
VM_IMAGE_DOWNLOADER: 'harvesterhci.io.virtualmachineimagedownloader',
SUPPORT_BUNDLE: 'harvesterhci.io.supportbundle',
NETWORK_ATTACHMENT: 'harvesterhci.io.networkattachmentdefinition',