mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 13:11:43 +00:00
feat: Remove guest cluster in Rancher (#391)
* feat: Remove guest cluster in Rancher Signed-off-by: Nick Chung <nick.chung@suse.com> * feat: add feature flag 1.6.0 Signed-off-by: Nick Chung <nick.chung@suse.com> * feat: update for review Signed-off-by: Nick Chung <nick.chung@suse.com> * chore: fix for review Signed-off-by: Nick Chung <nick.chung@suse.com> * chore: fix for review Signed-off-by: Nick Chung <nick.chung@suse.com> * refactor: reduce redundant code Signed-off-by: Andy Lee <andy.lee@suse.com> * chore: change text area to yaml editor Signed-off-by: Nick Chung <nick.chung@suse.com> * refactor: change radio and yaml editor position Signed-off-by: Andy Lee <andy.lee@suse.com> --------- Signed-off-by: Nick Chung <nick.chung@suse.com> Signed-off-by: Andy Lee <andy.lee@suse.com> Co-authored-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
parent
ef2b4d1589
commit
a9fa928912
214
pkg/harvester/components/settings/rancher-cluster.vue
Normal file
214
pkg/harvester/components/settings/rancher-cluster.vue
Normal file
@ -0,0 +1,214 @@
|
||||
<script>
|
||||
import CreateEditView from '@shell/mixins/create-edit-view';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
import { SECRET } from '@shell/config/types';
|
||||
import { exceptionToErrorsArray } from '@shell/utils/error';
|
||||
import FileSelector, { createOnSelected } from '@shell/components/form/FileSelector';
|
||||
import YamlEditor from '@shell/components/YamlEditor';
|
||||
|
||||
export default {
|
||||
name: 'HarvesterRancherCluster',
|
||||
|
||||
components: {
|
||||
RadioGroup,
|
||||
FileSelector,
|
||||
YamlEditor
|
||||
},
|
||||
|
||||
mixins: [CreateEditView],
|
||||
|
||||
props: {
|
||||
value: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
registerBeforeHook: {
|
||||
type: Function,
|
||||
required: false,
|
||||
default: () => {},
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
let parseDefaultValue = {};
|
||||
|
||||
try {
|
||||
const data = this.value.value || this.value.default || '{}';
|
||||
const parsed = JSON.parse(data);
|
||||
|
||||
parseDefaultValue = {
|
||||
kubeConfig: '',
|
||||
removeUpstreamClusterWhenNamespaceIsDeleted: parsed.removeUpstreamClusterWhenNamespaceIsDeleted || false
|
||||
};
|
||||
} catch (error) {
|
||||
parseDefaultValue = {
|
||||
kubeConfig: '',
|
||||
removeUpstreamClusterWhenNamespaceIsDeleted: false
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
parseDefaultValue,
|
||||
errors: [],
|
||||
existingSecret: null,
|
||||
};
|
||||
},
|
||||
|
||||
async created() {
|
||||
await this.checkExistingSecret();
|
||||
if (this.registerBeforeHook) {
|
||||
this.registerBeforeHook(this.willSave, 'willSave');
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onKeySelected: createOnSelected('parseDefaultValue.kubeConfig'),
|
||||
|
||||
update() {
|
||||
if (this.parseDefaultValue.removeUpstreamClusterWhenNamespaceIsDeleted) {
|
||||
this.value['value'] = JSON.stringify({ removeUpstreamClusterWhenNamespaceIsDeleted: true });
|
||||
} else {
|
||||
this.value['value'] = this.value.default || '{}';
|
||||
}
|
||||
},
|
||||
|
||||
async checkExistingSecret() {
|
||||
const inStore = this.$store.getters['currentProduct'].inStore;
|
||||
|
||||
await this.$store.dispatch(`${ inStore }/findAll`, { type: SECRET });
|
||||
const secrets = this.$store.getters[`${ inStore }/all`](SECRET) || [];
|
||||
|
||||
this.existingSecret = secrets.find((secret) => secret.metadata.name === 'rancher-cluster-config' &&
|
||||
secret.metadata.namespace === 'harvester-system'
|
||||
);
|
||||
|
||||
// If the secret exists and has data, populate the kubeConfig
|
||||
if (this.existingSecret?.data?.kubeConfig) {
|
||||
const decodedContent = atob(this.existingSecret.data.kubeConfig);
|
||||
|
||||
this.parseDefaultValue.kubeConfig = decodedContent;
|
||||
this.$nextTick(() => {
|
||||
this.update();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async createOrUpdateRancherKubeConfigSecret() {
|
||||
this.errors = [];
|
||||
// Check if kubeConfig is provided
|
||||
if (!this.parseDefaultValue.kubeConfig) {
|
||||
this.errors.push(this.t('validation.required', { key: this.t('harvester.setting.rancherCluster.kubeConfig') }, true));
|
||||
|
||||
return Promise.reject(this.errors);
|
||||
}
|
||||
|
||||
try {
|
||||
let secret;
|
||||
|
||||
if (this.existingSecret) {
|
||||
secret = this.existingSecret;
|
||||
secret.setData('kubeConfig', this.parseDefaultValue.kubeConfig);
|
||||
} else {
|
||||
const inStore = this.$store.getters['currentProduct'].inStore;
|
||||
|
||||
secret = await this.$store.dispatch(`${ inStore }/create`, {
|
||||
apiVersion: 'v1',
|
||||
kind: 'Secret',
|
||||
metadata: {
|
||||
name: 'rancher-cluster-config',
|
||||
namespace: 'harvester-system'
|
||||
},
|
||||
type: 'secret',
|
||||
data: { kubeConfig: btoa(this.parseDefaultValue.kubeConfig) }
|
||||
});
|
||||
}
|
||||
await secret.save();
|
||||
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
this.errors = exceptionToErrorsArray(err);
|
||||
|
||||
return Promise.reject(this.errors);
|
||||
}
|
||||
},
|
||||
|
||||
async deleteRancherKubeConfigSecret() {
|
||||
if (this.existingSecret) {
|
||||
this.existingSecret.remove();
|
||||
}
|
||||
},
|
||||
|
||||
async willSave() {
|
||||
// Only create or update secret if enabled
|
||||
if (this.parseDefaultValue.removeUpstreamClusterWhenNamespaceIsDeleted) {
|
||||
await this.createOrUpdateRancherKubeConfigSecret();
|
||||
} else {
|
||||
await this.deleteRancherKubeConfigSecret();
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
useDefault() {
|
||||
this.parseDefaultValue = {
|
||||
kubeConfig: '',
|
||||
removeUpstreamClusterWhenNamespaceIsDeleted: false
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'parseDefaultValue.removeUpstreamClusterWhenNamespaceIsDeleted'(val, oldVal) {
|
||||
if (val && !oldVal && this.existingSecret?.data?.kubeConfig) {
|
||||
// Populate kubeConfig with the existing secret value
|
||||
this.parseDefaultValue.kubeConfig = atob(this.existingSecret.data.kubeConfig);
|
||||
}
|
||||
},
|
||||
'parseDefaultValue.kubeConfig'(val) {
|
||||
this.$refs.yaml?.updateValue(val);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="row mt-20">
|
||||
<div class="col span-12">
|
||||
<RadioGroup
|
||||
v-model:value="parseDefaultValue.removeUpstreamClusterWhenNamespaceIsDeleted"
|
||||
:label="t('harvester.setting.rancherCluster.removeUpstreamClusterWhenNamespaceIsDeleted')"
|
||||
name="removeUpstreamClusterWhenNamespaceIsDeleted"
|
||||
:options="[true, false]"
|
||||
:labels="[t('generic.enabled'), t('generic.disabled')]"
|
||||
@update:value="update"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="parseDefaultValue.removeUpstreamClusterWhenNamespaceIsDeleted"
|
||||
class="row mt-20"
|
||||
>
|
||||
<div class="col span-12">
|
||||
<FileSelector
|
||||
class="btn btn-sm bg-primary mb-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
@selected="onKeySelected"
|
||||
/>
|
||||
<YamlEditor
|
||||
ref="yaml"
|
||||
v-model:value="parseDefaultValue.kubeConfig"
|
||||
class="yaml-editor"
|
||||
:editor-mode="mode === 'view' ? 'VIEW_CODE' : 'EDIT_CODE'"
|
||||
@update:value="update"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(textarea) {
|
||||
overflow-y: auto !important;
|
||||
}
|
||||
</style>
|
||||
@ -43,7 +43,8 @@ const FEATURE_FLAGS = {
|
||||
'customSupportBundle',
|
||||
'csiOnlineExpandValidation',
|
||||
'vmNetworkMigration',
|
||||
'kubeovnVpcSubnet'
|
||||
'kubeovnVpcSubnet',
|
||||
'rancherClusterSetting'
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ export const HCI_SETTING = {
|
||||
ADDITIONAL_GUEST_MEMORY_OVERHEAD_RATIO: 'additional-guest-memory-overhead-ratio',
|
||||
UPGRADE_CONFIG: 'upgrade-config',
|
||||
VM_MIGRATION_NETWORK: 'vm-migration-network',
|
||||
RANCHER_CLUSTER: 'rancher-cluster',
|
||||
};
|
||||
|
||||
export const HCI_ALLOWED_SETTINGS = {
|
||||
@ -108,8 +109,8 @@ export const HCI_ALLOWED_SETTINGS = {
|
||||
featureFlag: 'upgradeConfigSetting',
|
||||
docPath: 'UPGRADE_CONFIG_URL'
|
||||
},
|
||||
[HCI_SETTING.VM_MIGRATION_NETWORK]: {
|
||||
kind: 'json', from: 'import', canReset: true, featureFlag: 'vmNetworkMigration',
|
||||
[HCI_SETTING.RANCHER_CLUSTER]: {
|
||||
kind: 'custom', from: 'import', canReset: true, featureFlag: 'rancherClusterSetting'
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -1126,6 +1126,20 @@ harvester:
|
||||
publicCertificate: Public Certificate
|
||||
privateKey: Private Key
|
||||
ca: CA
|
||||
rancherCluster:
|
||||
description: Configure Rancher cluster integration for guest cluster management. This setting allows you to specify a Rancher KubeConfig and configure automatic cleanup behavior.
|
||||
kubeConfig: Rancher KubeConfig
|
||||
kubeConfigPlaceholder: Paste your Rancher KubeConfig content here...
|
||||
removeUpstreamClusterWhenNamespaceIsDeleted: Remove Upstream Cluster When Namespace Is Deleted
|
||||
createSecret: Create Rancher KubeConfig Secret
|
||||
updateSecret: Update Rancher KubeConfig Secret
|
||||
creatingSecret: Creating Secret...
|
||||
updatingSecret: Updating Secret...
|
||||
secretExists: A Rancher KubeConfig secret already exists and will be updated
|
||||
secretCreated: Rancher KubeConfig secret created successfully
|
||||
secretUpdated: Rancher KubeConfig secret updated successfully
|
||||
secretCreationFailed: Failed to create Rancher KubeConfig secret
|
||||
invalidKubeConfig: Invalid KubeConfig format. Please ensure it's a valid JSON kubeConfig file with apiVersion and kind fields.
|
||||
storageNetwork:
|
||||
range:
|
||||
placeholder: e.g. 172.16.0.0/24
|
||||
@ -1708,6 +1722,7 @@ advancedSettings:
|
||||
'harv-additional-guest-memory-overhead-ratio': 'The ratio for kubevirt to adjust the VM overhead memory. The value could be zero, empty value or floating number between 1.0 and 10.0, default to 1.5.'
|
||||
'harv-upgrade-config': 'Configure image preloading and VM restore options for upgrades. See related fields in <a href="{url}" target="_blank" rel="noopener">settings/upgrade-config</a>'
|
||||
'harv-vm-migration-network': 'Segregated network for VM migration traffic.'
|
||||
'harv-rancher-cluster': 'Configure Rancher cluster integration settings for guest cluster management.'
|
||||
|
||||
typeLabel:
|
||||
kubevirt.io.virtualmachine: |-
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user