+
{{ t('cluster.provider.imported') }}
diff --git a/shell/components/formatter/__tests__/ClusterProvider.test.ts b/shell/components/formatter/__tests__/ClusterProvider.test.ts
deleted file mode 100644
index 3f144a87682..00000000000
--- a/shell/components/formatter/__tests__/ClusterProvider.test.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { mount } from '@vue/test-utils';
-import ClusterProvider from '@shell/components/formatter/ClusterProvider.vue';
-
-describe('component: ClusterProvider', () => {
- const importedGkeClusterInfo = { mgmt: { spec: { gkeConfig: { imported: true } } } };
- const importedAksClusterInfo = { mgmt: { spec: { aksConfig: { imported: true } } } };
- const importedEksClusterInfo = { mgmt: { spec: { eksConfig: { imported: true } } } };
- const notImportedGkeClusterInfo = { mgmt: { spec: { gkeConfig: { imported: false } } } };
- const importedClusterInfoWithProviderForEmberParam = { mgmt: { providerForEmberParam: 'import' } };
-
- describe('isImported', () => {
- const testCases = [
- [importedGkeClusterInfo, true],
- [importedAksClusterInfo, true],
- [importedEksClusterInfo, true],
- [notImportedGkeClusterInfo, false],
- [importedClusterInfoWithProviderForEmberParam, true],
- [{}, false],
- ];
-
- it.each(testCases)('should return the isImported value properly based on the props data', (row, expected) => {
- const wrapper = mount(ClusterProvider, { propsData: { row } });
-
- expect(wrapper.vm.$data.isImported).toBe(expected);
- }
- );
- });
-});
diff --git a/shell/models/__tests__/management.cattle.io.cluster.test.ts b/shell/models/__tests__/management.cattle.io.cluster.test.ts
new file mode 100644
index 00000000000..4d2ab1260e3
--- /dev/null
+++ b/shell/models/__tests__/management.cattle.io.cluster.test.ts
@@ -0,0 +1,19 @@
+import MgmtCluster from '@shell/models/management.cattle.io.cluster';
+
+describe('class MgmtCluster', () => {
+ describe('provisioner', () => {
+ const testCases = [
+ [{ provider: 'rke', driver: 'imported' }, 'rke'],
+ [{ provider: 'k3s', driver: 'K3S' }, 'k3s'],
+ [{ provider: 'aks', driver: 'AKS' }, 'aks'],
+ [{}, 'imported'],
+ ];
+
+ it.each(testCases)('should return provisioner value properly based on the props data', (clusterData: Object, expected: String) => {
+ const cluster = new MgmtCluster({ status: clusterData });
+
+ expect(cluster.provisioner).toBe(expected);
+ }
+ );
+ });
+});
diff --git a/shell/models/__tests__/provisioning.cattle.io.cluster.test.ts b/shell/models/__tests__/provisioning.cattle.io.cluster.test.ts
new file mode 100644
index 00000000000..8c785666f75
--- /dev/null
+++ b/shell/models/__tests__/provisioning.cattle.io.cluster.test.ts
@@ -0,0 +1,90 @@
+import ProvCluster from '@shell/models/provisioning.cattle.io.cluster';
+
+describe('class ProvCluster', () => {
+ const importedClusterInfo = {
+ clusterName: 'test', provisioner: 'imported', mgmt: { spec: { gkeConfig: {} } }, spec: {}
+ };
+ const importedGkeClusterInfo = {
+ clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { gkeConfig: { imported: true } } }
+ };
+ const importedAksClusterInfo = {
+ clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { aksConfig: { imported: true } } }
+ };
+ const importedEksClusterInfo = {
+ clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { eksConfig: { imported: true } } }
+ };
+ const notImportedGkeClusterInfo = {
+ clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { gkeConfig: { imported: false } }, rkeConfig: {} }
+ };
+ const importedClusterInfoWithProviderForEmberParam = {
+ clusterName: 'test', provisioner: 'rke2', mgmt: { providerForEmberParam: 'import' }
+ };
+ const localClusterInfo = {
+ clusterName: 'test', provisioner: 'imported', mgmt: { isLocal: true, spec: { gkeConfig: {} } }, spec: {}
+ };
+ const doRke2Info = {
+ clusterName: 'test', provisioner: 'rke2', mgmt: { isLocal: false, providerForEmberParam: 'import' }, spec: { rkeConfig: {} }
+ };
+
+ describe('isImported', () => {
+ const testCases = [
+ [importedClusterInfo, true],
+ [importedGkeClusterInfo, true],
+ [importedAksClusterInfo, true],
+ [importedEksClusterInfo, true],
+ [notImportedGkeClusterInfo, false],
+ [importedClusterInfoWithProviderForEmberParam, true],
+ [localClusterInfo, false],
+ [doRke2Info, false],
+ [{}, false],
+ ];
+ const resetMocks = () => {
+ // Clear all mock function calls:
+ jest.clearAllMocks();
+ };
+
+ it.each(testCases)('should return the isImported value properly based on the props data', (clusterData: Object, expected: Boolean) => {
+ const cluster = new ProvCluster({ spec: clusterData.spec });
+
+ jest.spyOn(cluster, 'mgmt', 'get').mockReturnValue(
+ clusterData.mgmt
+ );
+ jest.spyOn(cluster, 'provisioner', 'get').mockReturnValue(
+ clusterData.provisioner
+ );
+
+ expect(cluster.isImported).toBe(expected);
+ resetMocks();
+ }
+ );
+ });
+
+ describe('mgmt', () => {
+ const testCases = [
+ [importedClusterInfo, importedClusterInfo.mgmt],
+ [importedGkeClusterInfo, importedGkeClusterInfo.mgmt],
+ [importedAksClusterInfo, importedAksClusterInfo.mgmt],
+ [importedEksClusterInfo, importedEksClusterInfo.mgmt],
+ [notImportedGkeClusterInfo, notImportedGkeClusterInfo.mgmt],
+ [importedClusterInfoWithProviderForEmberParam, importedClusterInfoWithProviderForEmberParam.mgmt],
+ [localClusterInfo, localClusterInfo.mgmt],
+ [doRke2Info, doRke2Info.mgmt],
+ [{}, null],
+ ];
+
+ const resetMocks = () => {
+ // Clear all mock function calls:
+ jest.clearAllMocks();
+ };
+
+ it.each(testCases)('should return the isImported value properly based on the props data', (clusterData: Object, expected: Object) => {
+ const clusterMock = jest.fn(() => clusterData.mgmt);
+ const ctx = { rootGetters: { 'management/byId': clusterMock } };
+ const cluster = new ProvCluster({ status: { clusterName: clusterData.clusterName } }, ctx);
+
+ expect(cluster.mgmt).toBe(expected);
+ resetMocks();
+ }
+ );
+ });
+});
diff --git a/shell/models/management.cattle.io.cluster.js b/shell/models/management.cattle.io.cluster.js
index 0db28ad7fb4..ad7a8f901a9 100644
--- a/shell/models/management.cattle.io.cluster.js
+++ b/shell/models/management.cattle.io.cluster.js
@@ -88,6 +88,10 @@ export default class MgmtCluster extends HybridModel {
}
get provisioner() {
+ if (this.status?.provider ) {
+ return this.status.provider;
+ }
+
// For imported K3s clusters, this.status.driver is 'k3s.'
return this.status?.driver ? this.status.driver : 'imported';
}
diff --git a/shell/models/provisioning.cattle.io.cluster.js b/shell/models/provisioning.cattle.io.cluster.js
index bb6004594c2..0952359c6e6 100644
--- a/shell/models/provisioning.cattle.io.cluster.js
+++ b/shell/models/provisioning.cattle.io.cluster.js
@@ -239,10 +239,24 @@ export default class ProvCluster extends SteveModel {
return providers.includes(this.provisioner);
}
+ get isLocal() {
+ return this.mgmt?.isLocal;
+ }
+
get isImported() {
// As of Rancher v2.6.7, this returns false for imported K3s clusters,
// in which this.provisioner is `k3s`.
- return this.provisioner === 'imported';
+
+ const isImportedProvisioner = this.provisioner === 'imported';
+ const isImportedSpecialCases = this.mgmt?.providerForEmberParam === 'import' ||
+ // when imported cluster is GKE
+ !!this.mgmt?.spec?.gkeConfig?.imported ||
+ // or AKS
+ !!this.mgmt?.spec?.aksConfig?.imported ||
+ // or EKS
+ !!this.mgmt?.spec?.eksConfig?.imported;
+
+ return !this.isLocal && (isImportedProvisioner || (!this.isRke2 && !this.mgmt?.machineProvider && isImportedSpecialCases));
}
get isCustom() {
@@ -262,8 +276,6 @@ export default class ProvCluster extends SteveModel {
}
get isImportedK3s() {
- // As of Rancher v2.6.7, this returns false for imported K3s clusters,
- // in which this.provisioner is `k3s`.
return this.isImported && this.isK3s;
}
@@ -280,7 +292,7 @@ export default class ProvCluster extends SteveModel {
}
get isRke1() {
- return !!this.mgmt?.spec?.rancherKubernetesEngineConfig;
+ return !!this.mgmt?.spec?.rancherKubernetesEngineConfig || this.labels['provider.cattle.io'] === 'rke';
}
get isHarvester() {