Skip to content

Commit a0a4cea

Browse files
committed
Auto-reload the network dropdown in the Cluster: Create Harvester page
Related to: rancher#13109 Signed-off-by: Volker Theile <[email protected]>
1 parent 1398d96 commit a0a4cea

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

pkg/harvester-manager/machine-config/harvester.vue

+43-19
Original file line numberDiff line numberDiff line change
@@ -204,24 +204,7 @@ export default {
204204
this.networkDataOptions = networkDataOptions;
205205
this.images = res.images.value?.data;
206206
this.storageClass = res.storageClass.value?.data;
207-
this.networkOptions = (res.networks.value?.data || []).filter((O) => O.metadata?.annotations?.[STORAGE_NETWORK] !== 'true').map((O) => {
208-
let value;
209-
let label;
210-
211-
try {
212-
const config = JSON.parse(O.spec.config);
213-
214-
const id = config.vlan;
215-
216-
value = O.id;
217-
label = `${ value } (vlanId=${ id })`;
218-
} catch (err) {}
219-
220-
return {
221-
label,
222-
value
223-
};
224-
});
207+
this.networks = res.networks.value?.data;
225208
226209
let systemNamespaces = (res.settings.value?.data || []).filter((x) => x.id === SETTING.SYSTEM_NAMESPACES);
227210
@@ -391,7 +374,7 @@ export default {
391374
storageClass: [],
392375
namespaces: [],
393376
namespaceOptions: [],
394-
networkOptions: [],
377+
networks: [],
395378
userDataOptions: [],
396379
networkDataOptions: [],
397380
allNodeObjects: [],
@@ -440,6 +423,31 @@ export default {
440423
}
441424
},
442425
426+
networkOptions: {
427+
get() {
428+
return (this.networks || []).filter((O) => O.metadata?.annotations?.[STORAGE_NETWORK] !== 'true').map((O) => {
429+
let value;
430+
let label;
431+
432+
try {
433+
const config = JSON.parse(O.spec.config);
434+
const id = config.vlan;
435+
436+
value = O.id;
437+
label = `${ value } (vlanId=${ id })`;
438+
} catch (err) {}
439+
440+
return {
441+
label,
442+
value
443+
};
444+
});
445+
},
446+
set(neu) {
447+
this.networks = neu;
448+
}
449+
},
450+
443451
namespaceDisabled() {
444452
return this.disabledEdit || this.poolIndex > 0;
445453
},
@@ -738,6 +746,21 @@ export default {
738746
}
739747
},
740748
749+
async getAvailableNetworks() {
750+
try {
751+
const clusterId = get(this.credential, 'decodedData.clusterId');
752+
753+
if (clusterId) {
754+
const url = `/k8s/clusters/${ clusterId }/v1`;
755+
const res = await this.$store.dispatch('cluster/request', { url: `${ url }/k8s.cni.cncf.io.network-attachment-definitions` });
756+
757+
this.networks = res?.data;
758+
}
759+
} catch (e) {
760+
this.errors = exceptionToErrorsArray(e);
761+
}
762+
},
763+
741764
async getAvailableVGpuDevices() {
742765
const clusterId = get(this.credential, 'decodedData.clusterId');
743766
@@ -1400,6 +1423,7 @@ export default {
14001423
:required="true"
14011424
label-key="cluster.credential.harvester.network.networkName"
14021425
:placeholder="t('cluster.harvester.machinePool.network.placeholder')"
1426+
@on-open="getAvailableNetworks"
14031427
@update:value="update"
14041428
/>
14051429
</div>

0 commit comments

Comments
 (0)