Skip to content

Commit

Permalink
Fix issues with diplaying rke1 data in home page
Browse files Browse the repository at this point in the history
- includes #12881
  • Loading branch information
richard-cox committed Dec 16, 2024
1 parent 051a144 commit 39c2cd7
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 53 deletions.
13 changes: 9 additions & 4 deletions shell/components/nav/TopLevelMenu.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface TopLevelMenuHelper {

export abstract class BaseTopLevelMenuHelper {
protected $store: VuexStore;
protected hasProvCluster: boolean;

/**
* Filter mgmt clusters by
Expand Down Expand Up @@ -125,6 +126,8 @@ export abstract class BaseTopLevelMenuHelper {
$store: VuexStore,
}) {
this.$store = $store;

this.hasProvCluster = this.$store.getters[`management/schemaFor`](CAPI.RANCHER_CLUSTER);
}

protected convertToCluster(mgmtCluster: MgmtCluster, provCluster: ProvCluster): TopLevelMenuCluster {
Expand Down Expand Up @@ -218,6 +221,12 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme

// ---------- requests ----------
async update(args: UpdateArgs) {
if (!this.hasProvCluster) {
// We're filtering out mgmt clusters without prov clusters, so if the user can't see any prov clusters at all
// exit early
return;
}

this.args = args;
const promises = {
pinned: this.updatePinned(args),
Expand Down Expand Up @@ -372,15 +381,11 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme
* Helper designed to supply non-pagainted results for the top level menu cluster resources
*/
export class TopLevelMenuHelperLegacy extends BaseTopLevelMenuHelper implements TopLevelMenuHelper {
private hasProvCluster: boolean;

constructor({ $store }: {
$store: VuexStore,
}) {
super({ $store });

this.hasProvCluster = this.$store.getters[`management/schemaFor`](CAPI.RANCHER_CLUSTER);

if (this.hasProvCluster) {
$store.dispatch('management/findAll', { type: CAPI.RANCHER_CLUSTER });
}
Expand Down
5 changes: 0 additions & 5 deletions shell/components/nav/TopLevelMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import { TopLevelMenuHelperPagination, TopLevelMenuHelperLegacy } from '@shell/c
import { debounce } from 'lodash';
import { sameContents } from '@shell/utils/array';
// TODO: RC test with rke1/2 cluster
// TODO: RC test vai off (home and side bar)
// TODO: RC test permissions (user-base, standard-user)
// TODO: RC bug - nav from page 1 (no mgmt clusters) --> page 2 (requires mgmt clusters from page, fetches, however model getters for provider do not update...)
export default {
components: {
BrandImage,
Expand Down
9 changes: 5 additions & 4 deletions shell/models/management.cattle.io.nodepool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import HybridModel from '@shell/plugins/steve/hybrid-class';
import { notOnlyOfRole } from '@shell/models/cluster.x-k8s.io.machine';

export default class MgmtNodePool extends HybridModel {
get nodeTemplate() {
const id = (this.spec?.nodeTemplateName || '').replace(/:/, '/');
const template = this.$getters['byId'](MANAGEMENT.NODE_TEMPLATE, id);
get nodeTemplateId() {
return (this.spec?.nodeTemplateName || '').replace(/:/, '/');
}

return template;
get nodeTemplate() {
return this.$getters['byId'](MANAGEMENT.NODE_TEMPLATE, this.nodeTemplateId);
}

get provider() {
Expand Down
2 changes: 1 addition & 1 deletion shell/models/provisioning.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export default class ProvCluster extends SteveModel {
}

get mgmt() {
return this.mgmtClusterId ? this.$rootGetters['management/byId'](MANAGEMENT.CLUSTER, this.mgmtClusterId) : null;
return this.$rootGetters['management/byId'](MANAGEMENT.CLUSTER, this.mgmtClusterId);
}

get isReady() {
Expand Down
49 changes: 26 additions & 23 deletions shell/pages/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default defineComponent({
paginationHeaders: [
STEVE_STATE_COL,
// https://github.com/rancher/dashboard/issues/12890 BUG - rke1 cluster's prov cluster metadata.name is the mgmt cluster id rather than true name
{
...STEVE_NAME_COL,
canBeVariable: true,
Expand Down Expand Up @@ -323,34 +324,36 @@ export default defineComponent({
}
// We need to fetch node pools and node templates in order to correctly show the provider for RKE1 clusters
if ( this.canViewMgmtPools && this.canViewMgmtTemplates) {
const filters = PaginationParamFilter.createMultipleFields(page
if ( this.canViewMgmtPools && this.canViewMgmtTemplates ) {
const nodePoolFilters = PaginationParamFilter.createMultipleFields(page
.filter((p: any) => p.status?.clusterName)
.map((r: any) => new PaginationFilterField({
field: 'spec.clusterName',
value: r.status?.clusterName
})));
const nodePools = await this.$store.dispatch(`management/findPage`, {
type: MANAGEMENT.NODE_POOL,
opt: {
force,
pagination: new FilterArgs({ filters: nodePoolFilters })
}
});
const templateOpt = PaginationParamFilter.createMultipleFields(nodePools
.filter((np: any) => !!np.nodeTemplateId)
.map((np: any) => new PaginationFilterField({
field: 'id',
value: np.nodeTemplateId,
exact: true,
})));
const poolOpt: ActionFindPageArgs = {
force,
// TODO: RC test with rke2 cluster
pagination: new FilterArgs({ filters })
};
this.$store.dispatch(`management/findPage`, { type: MANAGEMENT.NODE_POOL, opt: poolOpt });
const templateOpt: ActionFindPageArgs = {
force,
// TODO: RC test with rke2 cluster
pagination: new FilterArgs({
filters: PaginationParamFilter.createMultipleFields(page.map((r: any) => new PaginationFilterField({
field: 'spec.clusterName',
value: r.status?.clusterName
}))),
})
};
this.$store.dispatch(`management/findPage`, { type: MANAGEMENT.NODE_TEMPLATE, opt: templateOpt });
this.$store.dispatch(`management/findPage`, {
type: MANAGEMENT.NODE_TEMPLATE,
opt: {
force,
pagination: new FilterArgs({ filters: templateOpt })
}
});
}
},
Expand Down Expand Up @@ -539,8 +542,8 @@ export default defineComponent({
v-if="mcm"
class="col span-12"
>
<!-- // TODO: RC test vai off check loading indicator when pagination off -->
<PaginatedResourceTable
v-if="provClusterSchema"
:schema="provClusterSchema"
:table-actions="false"
:row-actions="false"
Expand Down
1 change: 0 additions & 1 deletion shell/plugins/dashboard-store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ export default {
return Promise.reject(e);
}

// TODO: RC Test
await dispatch('unwatch', {
type,
all: true,
Expand Down
4 changes: 2 additions & 2 deletions shell/plugins/dashboard-store/mutations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { markRaw, reactive } from 'vue';
import { reactive } from 'vue';
import { addObject, addObjects, clear, removeObject } from '@shell/utils/array';
import { SCHEMA, COUNT } from '@shell/config/types';
import { normalizeType, keyFieldFor } from '@shell/plugins/dashboard-store/normalize';
Expand Down Expand Up @@ -36,7 +36,7 @@ function registerType(state, type) {
loadCounter: 0,

// Not enumerable so they don't get sent back to the client for SSR
map: markRaw(new Map()),
map: new Map(),
};

state.types[type] = cache;
Expand Down
31 changes: 18 additions & 13 deletions shell/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ const updateActiveNamespaceCache = (state, activeNamespaceCache) => {
}
};

/**
* Are we in the vai enabled world where mgmt clusters are paginated?
*/
const paginateClusters = (rootGetters) => {
return paginationUtils.isEnabled({ rootGetters }, { store: 'management', resource: { id: MANAGEMENT.CLUSTER, context: 'side-bar' } });
};

export const state = () => {
return {
managementReady: false,
Expand Down Expand Up @@ -820,10 +827,9 @@ export const actions = {

res = await allHash(promises);

// TODO: RC test
if (!res.settings && !paginationUtils.isEnabled({ rootGetters }, { store: 'management', resource: { id: MANAGEMENT.CLUSTER, context: 'side-bar' } })) {
// This introduces a synchronous request, however we need settings to determine if pagination is enabled
// Eventually it will be removed when pagination is always on
if (!res.settings || !paginateClusters(rootGetters)) {
// This introduces a synchronous request, however we need settings to determine if SSP is enabled
// Eventually it will be removed when SSP is always on
res.clusters = await dispatch('management/findAll', { type: MANAGEMENT.CLUSTER, opt: { watch: false } });
toWatch.push(MANAGEMENT.CLUSTER);
}
Expand Down Expand Up @@ -988,8 +994,8 @@ export const actions = {
// Try and wait until the schema exists before proceeding
await dispatch('management/waitForSchema', { type: MANAGEMENT.CLUSTER });

// Do we need to wait on loadManagement to fetch required resources?
if (!paginationUtils.isEnabled({ rootGetters }, { store: 'management', resource: { id: MANAGEMENT.CLUSTER, context: 'side-bar' } })) {
// If SSP is on we won't have requested all clusters
if (!paginateClusters(rootGetters)) {
await dispatch('management/waitForHaveAll', { type: MANAGEMENT.CLUSTER });
}

Expand Down Expand Up @@ -1088,15 +1094,14 @@ export const actions = {
commit('updateNamespaces', { filters: ids, getters });
},

async cleanNamespaces({ getters, dispatch, rootGetters}) {
if (paginationUtils.isEnabled({ rootGetters }, { store: 'management', resource: { id: MANAGEMENT.CLUSTER, context: 'side-bar' } })) {
async cleanNamespaces({ getters, dispatch, rootGetters }) {
if (paginateClusters(rootGetters)) {
// See https://github.com/rancher/dashboard/issues/12864
// old world..
// old world...
// - loadManagement makes a request to fetch all mgmt clusters
// - we would block on that that request above before getting here (otherwise x2 requests were made)
// new world..
// - we won't have all mgmt clusters, this is another place that needs updating (see issue)

// - we would block on that that request above before getting here (otherwise x2 requests for all clusters were made)
// new world...
// - we won't have all mgmt clusters, so this whole function needs updating (see issue)
return;
}

Expand Down

0 comments on commit 39c2cd7

Please sign in to comment.