Skip to content

Commit

Permalink
Merge pull request #11318 from richard-cox/2.8-limit-bindings
Browse files Browse the repository at this point in the history
Add conditional depagination by native api, apply to bindings
  • Loading branch information
richard-cox authored Jul 2, 2024
2 parents a1aaa5b + 1bf35fb commit d378bda
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
15 changes: 11 additions & 4 deletions shell/config/product/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '@shell/config/table-headers';

import { DSL } from '@shell/store/type-map';
import { configureConditionalDepaginate } from '@shell/store/type-map.utils';

export const NAME = 'explorer';

Expand Down Expand Up @@ -49,7 +50,9 @@ export function init(store) {
typeStoreMap: {
[MANAGEMENT.PROJECT]: 'management',
[MANAGEMENT.CLUSTER_ROLE_TEMPLATE_BINDING]: 'management',
[MANAGEMENT.PROJECT_ROLE_TEMPLATE_BINDING]: 'management'
[MANAGEMENT.PROJECT_ROLE_TEMPLATE_BINDING]: 'management',
[NORMAN.CLUSTER_ROLE_TEMPLATE_BINDING]: 'rancher',
[NORMAN.PROJECT_ROLE_TEMPLATE_BINDING]: 'rancher',
}
});

Expand Down Expand Up @@ -156,12 +159,16 @@ export function init(store) {
mapGroup(/^(.*\.)?cluster\.x-k8s\.io$/, 'clusterProvisioning');
mapGroup(/^(aks|eks|gke|rke|rke-machine-config|rke-machine|provisioning)\.cattle\.io$/, 'clusterProvisioning');

const dePaginateBindings = configureConditionalDepaginate({ maxResourceCount: 5000 });
const dePaginateNormanBindings = configureConditionalDepaginate({ maxResourceCount: 5000, isNorman: true }) ;

configureType(NODE, { isCreatable: false, isEditable: true });
configureType(WORKLOAD_TYPES.JOB, { isEditable: false, match: WORKLOAD_TYPES.JOB });
configureType(MANAGEMENT.CLUSTER_ROLE_TEMPLATE_BINDING, { isEditable: false });
configureType(MANAGEMENT.PROJECT_ROLE_TEMPLATE_BINDING, { isEditable: false, depaginate: true });
configureType(MANAGEMENT.CLUSTER_ROLE_TEMPLATE_BINDING, { isEditable: false, depaginate: dePaginateBindings });
configureType(MANAGEMENT.PROJECT_ROLE_TEMPLATE_BINDING, { isEditable: false, depaginate: dePaginateBindings });
configureType(MANAGEMENT.PROJECT, { displayName: store.getters['i18n/t']('namespace.project.label') });
configureType(NORMAN.PROJECT_ROLE_TEMPLATE_BINDING, { depaginate: true });
configureType(NORMAN.CLUSTER_ROLE_TEMPLATE_BINDING, { depaginate: dePaginateNormanBindings });
configureType(NORMAN.PROJECT_ROLE_TEMPLATE_BINDING, { depaginate: dePaginateNormanBindings });

configureType(EVENT, { limit: 500 });
weightType(EVENT, -1, true);
Expand Down
2 changes: 1 addition & 1 deletion shell/config/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const NORMAN = {
ETCD_BACKUP: 'etcdbackup',
CLUSTER: 'cluster',
CLUSTER_TOKEN: 'clusterregistrationtoken',
CLUSTER_ROLE_TEMPLATE_BINDING: 'clusterRoleTemplateBinding',
CLUSTER_ROLE_TEMPLATE_BINDING: 'clusterroletemplatebinding',
CLOUD_CREDENTIAL: 'cloudcredential',
FLEET_WORKSPACES: 'fleetworkspace',
GLOBAL_ROLE: 'globalRole',
Expand Down
5 changes: 3 additions & 2 deletions shell/plugins/dashboard-store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { normalizeType } from './normalize';
import garbageCollect from '@shell/utils/gc/gc';
import { addSchemaIndexFields } from '@shell/plugins/steve/schema.utils';
import { addParam } from '@shell/utils/url';
import { conditionalDepaginate } from '@shell/store/type-map.utils';

export const _ALL = 'all';
export const _MERGE = 'merge';
Expand Down Expand Up @@ -188,7 +189,7 @@ export default {
opt = opt || {};
opt.url = getters.urlFor(type, null, opt);
opt.stream = opt.stream !== false && load !== _NONE;
opt.depaginate = typeOptions?.depaginate;
opt.depaginate = conditionalDepaginate(typeOptions?.depaginate, { ctx, args: { type, opt } });

let skipHaveAll = false;

Expand Down Expand Up @@ -367,7 +368,7 @@ export default {
opt = opt || {};
opt.labelSelector = selector;
opt.url = getters.urlFor(type, null, opt);
opt.depaginate = typeOptions?.depaginate;
opt.depaginate = conditionalDepaginate(typeOptions?.depaginate, { ctx, args: { type, opt } });

const res = await dispatch('request', { opt, type });

Expand Down
44 changes: 44 additions & 0 deletions shell/store/type-map.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { VuexStoreGetters } from '@shell/types/store/vuex';
import { COUNT } from '@shell/config/types';
import { ActionFindAllArgs } from '@shell/types/store/dashboard-store.types';

type conditionalDepaginateArgs ={
ctx: { rootGetters: VuexStoreGetters},
args: { type: string, opt: ActionFindAllArgs},
};
type conditionalDepaginateFn = (args: conditionalDepaginateArgs) => boolean

/**
* Conditionally determine if a resource should use naive kube pagination api to fetch all results
* (not just first page)
*/
export const conditionalDepaginate = (
depaginate?: conditionalDepaginateFn | boolean,
depaginateArgs?: conditionalDepaginateArgs
): boolean => {
if (typeof depaginate === 'function') {
return !!depaginateArgs ? depaginate(depaginateArgs) : false;
}

return depaginate as boolean;
};

/**
* Setup a function that will determine if a resource should use native kube pagination api to fetch all resources
* (not just the first page)
*/
export const configureConditionalDepaginate = (
{ maxResourceCount, isNorman = false }: { maxResourceCount: number, isNorman: boolean },
): conditionalDepaginateFn => {
return (fnArgs: conditionalDepaginateArgs ): boolean => {
const { rootGetters } = fnArgs.ctx;
const { type } = fnArgs.args;
const safeType = isNorman ? `management.cattle.io.${ type }` : type;

const inStore = rootGetters['currentStore'](safeType);
const resourceCounts = rootGetters[`${ inStore }/all`](COUNT)[0]?.counts[safeType];
const resourceCount = resourceCounts?.summary?.count;

return resourceCount !== undefined ? resourceCount < maxResourceCount : false;
};
};
23 changes: 23 additions & 0 deletions shell/types/store/dashboard-store.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Properties on all findX actions
*/
export type ActionCoreFindArgs = {
force?: boolean,
}

/**
* Args used for findAll action
*/
export interface ActionFindAllArgs extends ActionCoreFindArgs {
watch?: boolean,
namespaced?: string[],
incremental?: boolean,
hasManualRefresh?: boolean,
limit?: number,
/**
* Iterate over all pages and return all resources.
*
* This is done via the native kube pagination api, not steve
*/
depaginate?: boolean,
}
9 changes: 9 additions & 0 deletions shell/types/store/vuex.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Unfortunately there's no current way to type the vuex store, however we have ts files that references it
// Until we bring that in, this file can contain the interfaces and types used by ts files in place of `any`

/**
* Generic interface for Vuex getters
*/
export interface VuexStoreGetters {
[name: string]: Function;
}

0 comments on commit d378bda

Please sign in to comment.