Skip to content

Commit

Permalink
Fix editing rke2/k3s clusters in 'pending' state (rancher#12694)
Browse files Browse the repository at this point in the history
* fix cluster isImported check to account for clusters in the process of provisioning

* remove tests
  • Loading branch information
mantis-toboggan-md authored Dec 2, 2024
1 parent 26cd5cc commit e64e3da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 67 deletions.
42 changes: 0 additions & 42 deletions shell/models/__tests__/management.cattle.io.cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,6 @@ jest.mock('@shell/utils/clipboard', () => {
return { copyTextToClipboard: jest.fn(() => Promise.resolve({})) };
});

const importedRKE2ClusterInfo = { status: { driver: 'rke2', provider: 'rke2' } };

const provisionedRKE2ClusterInfo = { status: { driver: 'rke2', provider: 'imported' } };

const importedK3sClusterInfo = { status: { driver: 'k3s', provider: 'k3s' } };

const provisionedK3sClusterInfo = { status: { driver: 'k3s', provider: 'imported' } };

const importedAksClusterInfo = { spec: { aksConfig: { imported: true } }, status: { provider: 'aks', driver: 'AKS' } };

const provisionedAksClusterInfo = { spec: { aksConfig: { imported: false } }, status: { provider: 'aks', driver: 'AKS' } };

const importedRKE1ClusterInfo = { status: { provider: 'rke', driver: 'imported' } };

const provisionedRKE1ClusterInfo = { status: { provider: 'rke', driver: 'rancherKubernetesEngine' } };

const localRKE1ClusterInfo = { status: { provider: 'rke', driver: 'imported' } };

const localRKE2ClusterInfo = { status: { provider: 'rke2', driver: 'rke2' } };

const localEKSClusterInfo = { status: { provider: 'eks', driver: 'imported' } };

describe('class MgmtCluster', () => {
describe('provisioner', () => {
const testCases = [
Expand All @@ -42,24 +20,4 @@ describe('class MgmtCluster', () => {
}
);
});

describe('isImported', () => {
it.each([
[importedRKE2ClusterInfo, true],
[provisionedRKE2ClusterInfo, false],
[importedK3sClusterInfo, true],
[provisionedK3sClusterInfo, false],
[importedAksClusterInfo, true],
[provisionedAksClusterInfo, false],
[importedRKE1ClusterInfo, true],
[provisionedRKE1ClusterInfo, false],
[localRKE1ClusterInfo, true],
[localRKE2ClusterInfo, true],
[localEKSClusterInfo, true]
])('should return isImported based on props data', (clusterData, expected) => {
const cluster = new MgmtCluster(clusterData);

expect(cluster.isImported).toBe(expected);
});
});
});
24 changes: 0 additions & 24 deletions shell/models/management.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,6 @@ export default class MgmtCluster extends SteveModel {
return pools.filter((x) => x.spec?.clusterName === this.id);
}

get isImported() {
if (this.isLocal) {
return false;
}
// imported rke2 and k3s have status.driver === rke2 and k3s respectively
// Provisioned rke2 and k3s have status.driver === imported
if (this.status?.provider === 'k3s' || this.status?.provider === 'rke2') {
return this.status?.driver === this.status?.provider;
}

// imported KEv2
const kontainerConfigs = ['aksConfig', 'eksConfig', 'gkeConfig'];

const isImportedKontainer = kontainerConfigs.filter((key) => {
return this.spec?.[key]?.imported === true;
}).length;

if (isImportedKontainer) {
return true;
}

return this.provisioner === 'imported';
}

get provisioner() {
// For imported K3s clusters, this.status.driver is 'k3s.'
return this.status?.driver ? this.status.driver : 'imported';
Expand Down
24 changes: 23 additions & 1 deletion shell/models/provisioning.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,29 @@ export default class ProvCluster extends SteveModel {
}

get isImported() {
return this.mgmt?.isImported;
if (this.isLocal) {
return false;
}

// imported rke2 and k3s have status.driver === rke2 and k3s respectively
// Provisioned rke2 and k3s have status.driver === imported
if (this.mgmt?.status?.provider === 'k3s' || this.mgmt?.status?.provider === 'rke2') {
return this.mgmt?.status?.driver === this.mgmt?.status?.provider;
}

// imported KEv2
// we can't rely on this.provisioner to determine imported-ness for these clusters, as it will return 'aks' 'eks' 'gke' for both provisioned and imported clusters
const kontainerConfigs = ['aksConfig', 'eksConfig', 'gkeConfig'];

const isImportedKontainer = kontainerConfigs.filter((key) => {
return this.mgmt?.spec?.[key]?.imported === true;
}).length;

if (isImportedKontainer) {
return true;
}

return this.provisioner === 'imported';
}

get isCustom() {
Expand Down

0 comments on commit e64e3da

Please sign in to comment.