Skip to content

Commit

Permalink
add clusterclass action to create cluster from class (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis-toboggan-md committed Jan 23, 2024
1 parent d46382d commit 0c5c8ea
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/capi/l10n/en-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
action:
createCluster: Create Cluster
capi:
installation:
title: Rancher Turtles
Expand Down
33 changes: 33 additions & 0 deletions pkg/capi/models/cluster.x-k8s.io.clusterclass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SteveModel from '@shell/plugins/steve/steve-class';
import { CAPI } from '@shell/config/types';
import { BLANK_CLUSTER, QUERY_PARAMS } from '../types/capi';

export default class ClusterClass extends SteveModel {
get _availableActions() {
const out = super._availableActions;

out.unshift({
action: 'goToCreateCluster',
label: this.t('action.createCluster'),
icon: 'icon icon-plus',
enabled: true
});

return out;
}

goToCreateCluster() {
const escapedID = escape(this.id);
const location = {
name: 'c-cluster-product-resource-create',
params: {
cluster: BLANK_CLUSTER,
product: 'manager',
resource: CAPI.CAPI_CLUSTER
},
query: { [QUERY_PARAMS.CLASS]: escapedID }
};

this.currentRouter().push(location);
}
}
2 changes: 2 additions & 0 deletions pkg/capi/types/capi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const CAPI_PRODUCT_NAME = 'capi-turtles';

export const QUERY_PARAMS = { CLASS: 'class' };

export const BLANK_CLUSTER = '_';

export const LABELS = { AUTO_IMPORT: 'cluster-api.cattle.io/rancher-auto-import' };
Expand Down

0 comments on commit 0c5c8ea

Please sign in to comment.