mirror of https://github.com/rancher/dashboard.git
add ownerref to harvester kubeconfig secret
This commit is contained in:
parent
8a81add775
commit
5550ac6501
|
|
@ -312,6 +312,9 @@ export default {
|
|||
userChartValuesTemp: {},
|
||||
addonsRev: 0,
|
||||
clusterIsAlreadyCreated: !!this.value.id,
|
||||
// this is used to store the harvester cluster kubeconfig when using an 'imported' harvester cloud cred
|
||||
// made in saveOverride and given an ownerref in afterSaveHook
|
||||
harvesterKubeconfigSecret: null,
|
||||
fvFormRuleSets: [{
|
||||
path: 'metadata.name', rules: ['subDomain'], translationKey: 'nameNsDescription.name.label'
|
||||
}]
|
||||
|
|
@ -1189,7 +1192,6 @@ export default {
|
|||
const isUpgrade = this.isEdit && this.liveValue?.spec?.kubernetesVersion !== this.value?.spec?.kubernetesVersion;
|
||||
|
||||
if (this.agentConfig['cloud-provider-name'] === HARVESTER && clusterId && (this.isCreate || isUpgrade)) {
|
||||
// Create a secret to reference kubeconfig
|
||||
const namespace = this.machinePools?.[0]?.config?.vmNamespace;
|
||||
|
||||
const res = await this.$store.dispatch('management/request', {
|
||||
|
|
@ -1203,16 +1205,18 @@ export default {
|
|||
});
|
||||
|
||||
const kubeconfig = res.data;
|
||||
const configSecret = await this.createKubeconfigSecret(kubeconfig);
|
||||
|
||||
set(this.agentConfig, 'cloud-provider-config', `//secret:fleet-default:${ configSecret?.metadata?.name }`);
|
||||
this.harvesterKubeconfigSecret = await this.createKubeconfigSecret(kubeconfig);
|
||||
this.registerAfterHook(this.updateKubeconfigSecret, 'update-harvester-secret');
|
||||
|
||||
set(this.agentConfig, 'cloud-provider-config', `secret://fleet-default:${ this.harvesterKubeconfigSecret?.metadata?.name }`);
|
||||
set(this.chartValues, `${ HARVESTER_CLOUD_PROVIDER }.clusterName`, this.value.metadata.name);
|
||||
set(this.chartValues, `${ HARVESTER_CLOUD_PROVIDER }.cloudConfigPath`, '/var/lib/rancher/rke2/etc/config-files/cloud-provider-config');
|
||||
}
|
||||
|
||||
await this.save(btnCb);
|
||||
},
|
||||
|
||||
// create a secret to reference the harvester cluster kubeconfig in rkeConfig
|
||||
async createKubeconfigSecret(kubeconfig = '') {
|
||||
const secret = await this.$store.dispatch('management/create', {
|
||||
type: SECRET, metadata: { namespace: 'fleet-default', generateName: 'harvesterconfig' }, data: { credential: base64Encode(kubeconfig) }
|
||||
|
|
@ -1220,6 +1224,27 @@ export default {
|
|||
|
||||
return secret.save({ url: '/v1/secrets', method: 'POST' });
|
||||
},
|
||||
// add ownerRef to harvester secret to ensure clean up when the cluster deleted
|
||||
async updateKubeconfigSecret() {
|
||||
if (!this.harvesterKubeconfigSecret) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ownerRef = {
|
||||
apiVersion: this.value.apiVersion,
|
||||
controller: true,
|
||||
kind: this.value.kind,
|
||||
name: this.value.metadata.name,
|
||||
uid: this.value.metadata.uid
|
||||
};
|
||||
|
||||
if (!this.harvesterKubeconfigSecret.metadata?.ownerReferences) {
|
||||
this.$set(this.harvesterKubeconfigSecret.metadata, 'ownerReferences', []);
|
||||
}
|
||||
this.harvesterKubeconfigSecret.metadata.ownerReferences.push(ownerRef);
|
||||
|
||||
return await this.harvesterKubeconfigSecret.save();
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.$router.push({
|
||||
|
|
|
|||
Loading…
Reference in New Issue