Skip to content

Commit

Permalink
Tidy up checking of virtual cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed May 20, 2024
1 parent fe1c02a commit 4708b10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
4 changes: 4 additions & 0 deletions pkg/virtual-clusters/provisioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export class VClustersProvisioner implements IClusterProvisioner {
return 'vCluster';
}

parentCluster(cluster: ICluster): string {
return cluster.metadata?.annotations?.['ui.rancher/parent-cluster'];
}

async postDelete(cluster: ICluster): Promise<any> {
const parentClusterId = cluster.metadata?.annotations?.['ui.rancher/parent-cluster'];
const namespace = cluster.metadata?.annotations?.['ui.rancher/vcluster-namespace'];
Expand Down
31 changes: 12 additions & 19 deletions shell/models/provisioning.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import { CAPI as CAPI_ANNOTATIONS } from '@shell/config/labels-annotations';
* @extends SteveModel
*/
export default class ProvCluster extends SteveModel {
/**
* customProvisionerHelper returns a custom helper if applicable for this cluster
*

Check warning on line 21 in shell/models/provisioning.cattle.io.cluster.js

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
* This is cached after the first time
*/
get customProvisionerHelper() {
const fromAnnotation = this.annotations?.[CAPI_ANNOTATIONS.UI_CUSTOM_PROVIDER];

Expand All @@ -39,6 +44,7 @@ export default class ProvCluster extends SteveModel {
}
}

// Helper, of undefined if no helper for this cluster
return this.customProvisionerHelperObject;
}

Expand Down Expand Up @@ -935,36 +941,23 @@ export default class ProvCluster extends SteveModel {
}

// If this cluster has a custom provisioner, allow it to do custom deletion
const customProvisionerCls = this.$rootState.$plugin.getDynamic('provisioner', this.machineProvider);

if (customProvisionerCls) {
const context = {
dispatch: this.$dispatch,
getters: this.$getters,
$plugin: this.$rootState.$plugin,
$t: this.t
};

const customProv = new customProvisionerCls(context);

if (customProv?.postDelete) {
await customProv.postDelete(this);
}
if (this.customProvisionerHelper?.postDelete) {
return this.customProvisionerHelper?.postDelete(this);
}
}

get groupByParent() {
return this.metadata.annotations?.['ui.rancher/parent-cluster'];
// Customer helper can report if the cluster has a parent cluster
return this.customProvisionerHelper?.parentCluster(this);
}

get groupByLabel() {
const name = this.groupByParent;

if (name) {
// return this.$rootGetters['i18n/t']('resourceTable.groupLabel.project', { name: escapeHtml(name) });
return `Cluster: ${ name }`;
return this.$rootGetters['i18n/t']('resourceTable.groupLabel.cluster', { name: escapeHtml(name) });

Check warning on line 958 in shell/models/provisioning.cattle.io.cluster.js

View workflow job for this annotation

GitHub Actions / lint

'escapeHtml' is not defined
} else {
return 'Real Clusters';
return this.$rootGetters['i18n/t']('resourceTable.groupLabel.realCluster');
}
}

Expand Down

0 comments on commit 4708b10

Please sign in to comment.