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

HARVESTER: Fix HARVESTER v1.0.3 VM issues #6560

Merged
merged 6 commits into from
Aug 3, 2022
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
32 changes: 23 additions & 9 deletions shell/components/form/PodAffinity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export default {
default: () => []
},

hasNodesAndNs: {
type: Boolean,
default: true
}
namespaces: {
type: Array,
default: null
},
},

data() {
Expand Down Expand Up @@ -99,7 +99,7 @@ export default {

allNamespaces() {
const inStore = this.$store.getters['currentStore'](NAMESPACE);
const choices = this.$store.getters[`${ inStore }/all`](NAMESPACE);
const choices = this.namespaces || this.$store.getters[`${ inStore }/all`](NAMESPACE);
const out = sortBy(choices.map((obj) => {
return {
label: obj.nameDisplay,
Expand All @@ -112,7 +112,15 @@ export default {

existingNodeLabels() {
return getUniqueLabelKeys(this.nodes);
}
},

hasNodes() {
return this.nodes.length;
},

hasNamespaces() {
return this.allNamespaces.length;
},
},

created() {
Expand Down Expand Up @@ -190,7 +198,12 @@ export default {
},

updateNamespaces(term, namespaces) {
const nsArray = namespaces.split(',').map(ns => ns.trim()).filter(ns => ns?.length);
let nsArray = namespaces;

// namespaces would be String if there is no namespace
if (!this.hasNamespaces) {
nsArray = namespaces.split(',').map(ns => ns.trim()).filter(ns => ns?.length);
}

this.$set(term, 'namespaces', nsArray);
this.queueUpdate();
Expand Down Expand Up @@ -250,13 +263,14 @@ export default {
<div class="spacer"></div>
<div v-if="!!props.row.value.namespaces || !!get(props.row.value, 'podAffinityTerm.namespaces')" class="row mb-20">
<LabeledSelect
v-if="hasNodesAndNs"
v-if="hasNamespaces"
v-model="props.row.value.namespaces"
:mode="mode"
:multiple="true"
:taggable="true"
:options="allNamespaces"
:label="t('workload.scheduling.affinity.matchExpressions.inNamespaces')"
@input="updateNamespaces(props.row.value, props.row.value.namespaces)"
/>
<LabeledInput
v-else
Expand All @@ -280,7 +294,7 @@ export default {
<div class="row">
<div class="col span-12">
<LabeledSelect
v-if="hasNodesAndNs"
v-if="hasNodes"
v-model="props.row.value.topologyKey"
:taggable="true"
:searchable="true"
Expand Down
22 changes: 8 additions & 14 deletions shell/edit/harvesterhci.io.virtualmachinetemplateversion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { Checkbox } from '@components/Form/Checkbox';
import CruResource from '@shell/components/CruResource';
import NameNsDescription from '@shell/components/form/NameNsDescription';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import UnitInput from '@shell/components/form/UnitInput';

import Volume from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineVolume';
import Network from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineNetwork';
import CpuMemory from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineCpuMemory';
import CloudConfig from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineCloudConfig';
import SSHKey from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineSSHKey';
import NodeScheduling from '@shell/components/form/NodeScheduling';
import Reserved from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineReserved';

import { HCI } from '@shell/config/types';
import { randomStr } from '@shell/utils/string';
Expand All @@ -39,9 +39,9 @@ export default {
CruResource,
CloudConfig,
LabeledSelect,
UnitInput,
NameNsDescription,
NodeScheduling,
Reserved,
},

mixins: [CreateEditView, VM_MIXIN],
Expand Down Expand Up @@ -283,18 +283,12 @@ export default {
<a v-else v-t="'harvester.generic.showMore'" role="button" @click="toggleAdvanced" />
</div>

<div v-if="showAdvanced" class="row mb-20">
<div class="col span-6">
<UnitInput
v-model="reservedMemory"
v-int-number
:label="t('harvester.virtualMachine.input.reservedMemory')"
:mode="mode"
:input-exponent="2"
:increment="1024"
:output-modifier="true"
/>
</div>
<div v-if="showAdvanced" class="mb-20">
<Reserved
:reserved-memory="reservedMemory"
:mode="mode"
@updateReserved="updateReserved"
/>
</div>

<CloudConfig
Expand Down
54 changes: 54 additions & 0 deletions shell/edit/kubevirt.io.virtualmachine/VirtualMachineReserved.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script>
import UnitInput from '@shell/components/form/UnitInput';

export default {
name: 'HarvesterReserved',
components: { UnitInput },

props: {
reservedMemory: {
type: String,
default: null
},
mode: {
type: String,
default: 'create',
},
},

data() {
return { memory: this.reservedMemory };
},

watch: {
reservedMemory(memory) {
this.memory = memory;
},
},

methods: {
change() {
const { memory } = this;

this.$emit('updateReserved', { memory });
},
}
};
</script>

<template>
<div class="row mb-20">
<div class="col span-6">
<UnitInput
v-model="memory"
v-int-number
:label="t('harvester.virtualMachine.input.reservedMemory')"
:mode="mode"
:input-exponent="2"
:increment="1024"
:output-modifier="true"
@input="change"
/>
</div>
</div>
</template>
25 changes: 9 additions & 16 deletions shell/edit/kubevirt.io.virtualmachine/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import CruResource from '@shell/components/CruResource';
import { RadioGroup } from '@components/Form/Radio';
import { LabeledInput } from '@components/Form/LabeledInput';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import UnitInput from '@shell/components/form/UnitInput';
import NameNsDescription from '@shell/components/form/NameNsDescription';

import SSHKey from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineSSHKey';
import Volume from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineVolume';
import Network from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineNetwork';
import CpuMemory from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineCpuMemory';
import Reserved from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineReserved';
import CloudConfig from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineCloudConfig';
import NodeScheduling from '@shell/components/form/NodeScheduling';
import AccessCredentials from '@shell/edit/kubevirt.io.virtualmachine/VirtualMachineAccessCredentials';
Expand Down Expand Up @@ -45,7 +45,6 @@ export default {
CruResource,
LabeledInput,
LabeledSelect,
UnitInput,
NameNsDescription,
Volume,
SSHKey,
Expand All @@ -54,6 +53,7 @@ export default {
CloudConfig,
NodeScheduling,
AccessCredentials,
Reserved,
},

mixins: [CreateEditView, VM_MIXIN],
Expand Down Expand Up @@ -278,12 +278,11 @@ export default {
}

const cloneValue = clone(this.value);

cloneValue.spec.template.spec.nodeSelector = this.spec.template.spec.nodeSelector;
const cloneSpec = clone(this.spec);

for (let i = 1; i <= this.count; i++) {
this.$set(this.value, 'spec', cloneValue.spec);
this.$set(this, 'spec', cloneValue.spec);
this.$set(this, 'spec', cloneSpec);
const suffix = i < 10 ? `0${ i }` : i;

this.value.cleanForNew();
Expand Down Expand Up @@ -545,17 +544,11 @@ export default {
</div>
</div>

<div class="col span-6">
<UnitInput
v-model="reservedMemory"
v-int-number
:label="t('harvester.virtualMachine.input.reservedMemory')"
:mode="mode"
:input-exponent="2"
:increment="1024"
:output-modifier="true"
/>
</div>
<Reserved
:reserved-memory="reservedMemory"
:mode="mode"
@updateReserved="updateReserved"
/>
</div>

<CloudConfig
Expand Down
32 changes: 21 additions & 11 deletions shell/machine-config/harvester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ export default {

if (clusterId && isImportCluster) {
const res = await allHashSettled({
nodes: this.$store.dispatch('cluster/request', { url: `${ url }/${ NODE }s` }),
namespaces: this.$store.dispatch('cluster/request', { url: `${ url }/${ NAMESPACE }s` }),
namespaces: this.$store.dispatch('harvester/findAll', { type: NAMESPACE, opt: { url: `${ url }/${ NAMESPACE }s` } }),
images: this.$store.dispatch('cluster/request', { url: `${ url }/${ HCI.IMAGE }s` }),
configMaps: this.$store.dispatch('cluster/request', { url: `${ url }/${ CONFIG_MAP }s` }),
networks: this.$store.dispatch('cluster/request', { url: `${ url }/k8s.cni.cncf.io.network-attachment-definitions` }),
Expand Down Expand Up @@ -121,9 +120,6 @@ export default {
this.userDataOptions = userDataOptions;
this.networkDataOptions = networkDataOptions;
this.images = res.images.value?.data;
this.allNodeObjects = res.nodes.value?.data || [];
this.allNodes = this.allNodeObjects.map(node => node.id);

this.networkOptions = (res.networks.value?.data || []).map( (O) => {
let value;
let label;
Expand All @@ -143,19 +139,26 @@ export default {
};
});

(res.namespaces.value?.data || []).forEach(async(namespace) => {
const proxyNamespace = await this.$store.dispatch('cluster/create', namespace);

if (!proxyNamespace.isSystem) {
(res.namespaces.value || []).forEach((namespace) => {
if (!namespace.isSystem) {
const value = namespace.metadata.name;
const label = namespace.metadata.name;

this.namespaces.push(namespace);
this.namespaceOptions.push({
label,
value
});
}
});

try {
const { data: nodes } = await this.$store.dispatch('cluster/request', { url: `${ url }/${ NODE }s` });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this request need to move out of the allHashSettled above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to catch the errors of node's request since the response of node may have 404/500 error code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for I missed the link to the issue 2567 that the local cluster owner has no permission to access the node resource.


this.allNodeObjects = nodes;
} catch (err) {
this.allNodeObjects = [];
}
}

if (isEmpty(this.value.cpuCount)) {
Expand Down Expand Up @@ -198,11 +201,11 @@ export default {
userData,
networkData,
images: [],
namespaces: [],
namespaceOptions: [],
networkOptions: [],
userDataOptions: [],
networkDataOptions: [],
allNodes: [],
allNodeObjects: [],
cpuCount: ''
};
Expand Down Expand Up @@ -244,6 +247,7 @@ export default {
if (!this.isEdit) {
this.imageOptions = [];
this.networkOptions = [];
this.namespaces = [];
this.namespaceOptions = [];
this.vmAffinity = { affinity: {} };
this.value.imageName = '';
Expand Down Expand Up @@ -537,7 +541,13 @@ export default {
<h3 class="mt-20">
{{ t("workload.container.titles.podScheduling") }}
</h3>
<PodAffinity :mode="mode" :value="vmAffinity" :nodes="allNodeObjects" :has-nodes-and-ns="isImportCluster" @update="updateScheduling" />
<PodAffinity
:mode="mode"
:value="vmAffinity"
:nodes="allNodeObjects"
:namespaces="namespaces"
@update="updateScheduling"
/>

<h3 class="mt-20">
{{ t("cluster.credential.harvester.userData.title") }}
Expand Down
10 changes: 8 additions & 2 deletions shell/mixins/harvester-vm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,13 @@ export default {
}
});
}
}
},

updateReserved(value = {}) {
const { memory } = value;

this.$set(this, 'reservedMemory', memory);
},
},

watch: {
Expand All @@ -1263,7 +1269,7 @@ export default {

const oldImageId = old[0]?.image;

if (this.isCreate && oldImageId === imageId) {
if (this.isCreate && oldImageId === imageId && imageId) {
this.osType = osType;
}
}
Expand Down