Skip to content

Commit

Permalink
sdfdsf
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Feb 3, 2025
1 parent 4d3e233 commit df2a4db
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 115 deletions.
10 changes: 2 additions & 8 deletions shell/components/form/ResourceSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
import { Banner } from '@components/Banner';
import MatchExpressions from '@shell/components/form/MatchExpressions';
import ResourceTable from '@shell/components/ResourceTable';
import { allHash } from '@shell/utils/promise';
import { _EDIT } from '@shell/config/query-params';
import { convert, findMatchingResources, matching, simplify } from '@shell/utils/selector';
import { convert, simplify } from '@shell/utils/selector';
import throttle from 'lodash/throttle';
import { FilterArgs } from '@shell/types/store/pagination.types';
import { COUNT } from '@shell/config/types';
import { findMatchingResources } from '@shell/utils/selector-typed';
export default {
name: 'ResourceSelector',
Expand Down Expand Up @@ -38,11 +37,6 @@ export default {
},
async fetch() {
// Used in conjunction with `matches/match/label selectors`. Requires https://github.com/rancher/dashboard/issues/10417 to fix
// const hash = await allHash({ allResources: this.$store.dispatch('cluster/findAll', { type: this.type }) });
// this.allResources = hash.allResources;
this.updateMatchingResources();
},
Expand Down
1 change: 0 additions & 1 deletion shell/detail/workload/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default {
allNodes: hasNodes ? this.$store.dispatch('cluster/findAll', { type: NODE }) : []
};
debugger;
if (this.podSchema) {
hash.matchingPods = this.value.fetchPods();
}
Expand Down
16 changes: 8 additions & 8 deletions shell/edit/networking.k8s.io.networkpolicy/PolicyRuleTarget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ArrayList from '@shell/components/form/ArrayList';
import { Banner } from '@components/Banner';
import throttle from 'lodash/throttle';
import { isValidCIDR } from '@shell/utils/validators/cidr';
import { findMatchingResources } from '@shell/utils/selector-typed';
const TARGET_OPTIONS = {
IP_BLOCK: 'ipBlock',
Expand Down Expand Up @@ -198,14 +199,14 @@ export default {
}
},
async getMatchingPods() {
//TODO: RC TEST
// TODO: RC TEST
return await findMatchingResources({
labelSelector: { matchExpressions: this.podSelectorExpressions },
type: POD,
$store: this.$store,
inStore: 'cluster',
namespace: this.targetType === TARGET_OPTIONS.NAMESPACE_AND_POD_SELECTOR ? this.matchingNamespaces.matches.map(ns => ns.id) : this.namespace, // TODO: RC multiple?
transient: true,
inStore: 'cluster',
namespace: this.targetType === TARGET_OPTIONS.NAMESPACE_AND_POD_SELECTOR ? this.matchingNamespaces.matches.map((ns) => ns.id) : this.namespace, // TODO: RC multiple?
transient: true,
});
// const namespaces = this.targetType === TARGET_OPTIONS.NAMESPACE_AND_POD_SELECTOR ? this.matchingNamespaces.matches : [{ id: this.namespace }];
Expand All @@ -223,16 +224,15 @@ export default {
// };
},
async getMatchingNamespaces() {
//TODO: RC TEST
// TODO: RC TEST
return await findMatchingResources({
labelSelector: { matchExpressions: this.namespaceSelectorExpressions },
type: NAMESPACE,

Check warning on line 230 in shell/edit/networking.k8s.io.networkpolicy/PolicyRuleTarget.vue

View workflow job for this annotation

GitHub Actions / lint

'NAMESPACE' is not defined
$store: this.$store,
inStore: 'cluster',
transient: true,
inStore: 'cluster',
transient: true,
});
// const allNamespaces = this.allNamespaces;
// const match = matching(allNamespaces, this.namespaceSelectorExpressions);
// const matched = match.length || 0;
Expand Down
12 changes: 7 additions & 5 deletions shell/edit/networking.k8s.io.networkpolicy/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import CruResource from '@shell/components/CruResource';
import { Banner } from '@components/Banner';
import Labels from '@shell/components/form/Labels';
import { NAMESPACE, POD } from '@shell/config/types';

Check warning on line 10 in shell/edit/networking.k8s.io.networkpolicy/index.vue

View workflow job for this annotation

GitHub Actions / lint

'NAMESPACE' is defined but never used
import { convert, findMatchingResources, matching, simplify } from '@shell/utils/selector';
import { convert, simplify } from '@shell/utils/selector';
import { findMatchingResources } from '@shell/utils/selector-typed';
import { Checkbox } from '@components/Form/Checkbox';
import { addObject, removeObject } from '@shell/utils/array';
import MatchExpressions from '@shell/components/form/MatchExpressions';
Expand Down Expand Up @@ -150,12 +152,12 @@ export default {
methods: {
updateMatchingPods: throttle(async function() {
//TODO: RC TEST
// TODO: RC TEST
this.matchingPods = await findMatchingResources({
labelSelector: { matchExpressions: this.selectorExpressions },
type: POD,
$store: this.$store,
inStore: 'cluster',
inStore: 'cluster',
namespace: this.value.metadata.namespace,
});
// const allInNamespace = this.allPods.filter((pod) => pod.metadata.namespace === this.value.metadata.namespace);
Expand Down Expand Up @@ -221,7 +223,7 @@ export default {
:value="value"
type="ingress"
:mode="mode"

@update:value="$emit('input', $event)"
/>
</Tab>
Expand All @@ -248,7 +250,7 @@ export default {
:value="value"
type="egress"
:mode="mode"

@update:value="$emit('input', $event)"
/>
</Tab>
Expand Down
2 changes: 1 addition & 1 deletion shell/edit/service.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { clone } from '@shell/utils/object';
import {
POD, CAPI, HCI, COUNT, NAMESPACE, SERVICE
} from '@shell/config/types';
import { findMatchingResources, matching } from '@shell/utils/selector';
import { findMatchingResources } from '@shell/utils/selector-typed';
import { HARVESTER_NAME as HARVESTER } from '@shell/config/features';
import { allHash } from '@shell/utils/promise';
import { isHarvesterSatisfiesVersion } from '@shell/utils/cluster';
Expand Down
45 changes: 25 additions & 20 deletions shell/models/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,37 +153,42 @@ export default class Service extends SteveModel {
// }

if (isEmpty(selector)) {
return;
return undefined;
}

return { matchLabels: selector // TODO: RC confirm this is alll is ever is??? can it be string | exp[] | ??
};
}

async fetchPods(podSelector = this.podSelector) {
if (podSelector) {
const findPageArgs = { // Of type ActionFindPageArgs
namespaced: this.metadata.namespace,
pagination: new FilterArgs({ labelSelector: podSelector }),
};
// TODO: RC confirm with pagination off.... no findPage usage
// TODO: RC ARG??? podSelector vs this.podRelationship.selector

return this.$dispatch('findPage', { type: POD, opt: findPageArgs });
}
async fetchPods() {
// TODO: RC TEST
// if (!podSelector) {
// return;
// }

return Promise.resolve(undefined);
return await this.$dispatch('findMatchingOrPage', {
type: POD,
matching: {
namespace: this.metadata.namespace,
labelSelector: { matchLabels: this.podRelationship.selector } // TODO: RC is this string or map
}
// findPageOpts: { // Of type ActionFindPageArgs
// namespaced: this.metadata.namespace,
// pagination: new FilterArgs({ labelSelector: { matchLabels: this.podRelationship.selector} }),
// },
// findMatchingOpts: {
// type: POD,
// selector: this.podRelationship.selector,
// namespace: this.namespace
// }
});
}

// async fetchPods() {
// if (this.podSelector) {
// await this.$dispatch('cluster/findMatching', { // TODO: RC LEGACY? No-op
// type: POD,
// selector: this.podRelationship.selector,
// namespace: this.namespace
// }, { root: true });
// }
// }

get pods() {
// TODO: RC What uses this??
console.warn('Anything using this must be updated to ????!!!');

return [];
Expand Down
2 changes: 1 addition & 1 deletion shell/models/workload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TIMESTAMP, CATTLE_PUBLIC_ENDPOINTS } from '@shell/config/labels-annotat
import { WORKLOAD_TYPES, SERVICE, POD } from '@shell/config/types';
import { get, set } from '@shell/utils/object';
import day from 'dayjs';
import { convertSelectorObj, findMatchingResources, matching, parse } from '@shell/utils/selector';
import { convertSelectorObj, findMatchingResources, parse } from '@shell/utils/selector';
import { SEPARATOR } from '@shell/config/workload';
import WorkloadService from '@shell/models/workload.service';
import { FilterArgs } from '@shell/types/store/pagination.types';
Expand Down
10 changes: 8 additions & 2 deletions shell/pages/c/_cluster/longhorn/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ export default {
async fetch() {
if ( this.$store.getters['cluster/schemaFor'](SERVICE) ) {
this.uiServices = await this.$store.dispatch('cluster/findMatching', { // TODO: RC LEGACY? No-op
// TODO: RC TEST
this.uiServices = await this.$store.dispatch('cluster/findMatchingOrPage', {
type: SERVICE,
selector: 'app=longhorn-ui'
matching: { labelSelector: { matchLabels: { app: 'longhorn-ui' } } }
// type: SERVICE,
// context: this.$store,
// findPageOpts: { pagination: new FilterArgs({ labelSelector: { matchLabels: { app: 'longhorn-ui' } } }) },
// findMatchingOpts: { type: SERVICE, selector: 'app=longhorn-ui' }
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { allHash } from '@shell/utils/promise';
import AsyncButton from '@shell/components/AsyncButton';
import AppModal from '@shell/components/AppModal.vue';
import { FilterArgs } from '@shell/types/store/pagination.types';
export default {
emits: ['closed', 'refresh', 'update'],
Expand Down Expand Up @@ -90,18 +91,48 @@ export default {
},
async removeCatalogResources(catalog) {
const selector = `${ UI_PLUGIN_LABELS.CATALOG_IMAGE }=${ catalog.name }`;
// const selector = `${ UI_PLUGIN_LABELS.CATALOG_IMAGE }=${ catalog.name }`;
const pageSelector = { [UI_PLUGIN_LABELS.CATALOG_IMAGE]: catalog.name };
const namespace = UI_PLUGIN_NAMESPACE;
if ( selector ) {
// const findPageOpts = {
// namespaced: namespace,
// pagination: new FilterArgs({ labelSelector: { matchLabels: pageSelector } }),
// };
if ( catalog.name ) {
const hash = await allHash({
deployment: this.$store.dispatch('management/findMatching', { // TODO: RC LEGACY? No-op
type: WORKLOAD_TYPES.DEPLOYMENT, selector, namespace
deployment: this.$store.dispatch('management/findMatchingOrPage', {
type: WORKLOAD_TYPES.DEPLOYMENT,
matching: { namespace, labelSelector: { matchLabels: pageSelector } }
// type: WORKLOAD_TYPES.DEPLOYMENT, // context: this.$store,
// findPageOpts,
// findMatchingOpts: {
// type: WORKLOAD_TYPES.DEPLOYMENT, selector, namespace
// }
}),
service: this.$store.dispatch('management/findMatching', { // TODO: RC LEGACY? No-op
type: SERVICE, selector, namespace
service: this.$store.dispatch('management/findMatchingOrPage', {
type: SERVICE,
matching: { namespace, labelSelector: { matchLabels: pageSelector } }
// type: SERVICE,
// context: this.$store,
// findPageOpts,
// findMatchingOpts: { // TODO: RC LEGACY? No-op
// type: SERVICE, selector, namespace
// }
}),
repo: this.$store.dispatch('management/findMatching', { type: CATALOG.CLUSTER_REPO, selector }) // TODO: RC LEGACY? No-op
repo: this.$store.dispatch('management/findMatchingOrPage', {
type: CATALOG.CLUSTER_REPO,
matching: { labelSelector: { matchLabels: pageSelector } }
// type: CATALOG.CLUSTER_REPO,
// context: this.$store,
// findPageOpts: {
// ...findPageOpts,
// namespace: undefined,
// },
// findMatchingOpts: { type: CATALOG.CLUSTER_REPO, selector }
})
});
for ( const resource of Object.keys(hash) ) {
Expand Down
39 changes: 39 additions & 0 deletions shell/plugins/dashboard-store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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';
import { FilterArgs } from '@shell/types/store/pagination.types';

export const _ALL = 'all';
export const _MERGE = 'merge';
Expand Down Expand Up @@ -446,6 +447,44 @@ export default {
} : findAllGetter(getters, type, opt);
},

/**
*
* labelSelector is of type KubeLabelSelector
*/
async findMatchingOrPage(ctx, {
type,
matching: {
namespace,
labelSelector
},
opts
}) {
const { getters, dispatch } = ctx;

const args = {
id: type,
context,
};

if (getters[`paginationEnabled`]?.(args)) {
return dispatch('findPage', {
type,
opts: {
...(opts || {}),
namespaced: namespace,
pagination: new FilterArgs({ labelSelector }),
}
});
}

return dispatch('findMatching', {
type,
selector: labelSelector.matchLabels,
opts,
namespace,
});
},

async findMatching(ctx, {
type,
selector,
Expand Down
17 changes: 15 additions & 2 deletions shell/plugins/dashboard-store/resource-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1838,9 +1838,22 @@ export default class Resource {
const out = [];

for ( const sel of selectors ) {
const matching = await this.$dispatch('findMatching', sel); // TODO: RC LEGACY? No-op
const {
type,
selector,
namespace,
opt,
} = sel;
const matching = await this.$dispatch('findMatchingOrPage', {
type,
matching: {
namespace,
labelSelector: { matchLabels: selector } // TODO: RC selector is string or map
},
opts: opt
});

addObjects(out, matching.data);
addObjects(out, matching.data); // TODO: RC not data...??
}

for ( const obj of ids ) {
Expand Down
4 changes: 4 additions & 0 deletions shell/plugins/steve/steve-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ export default class SteveModel extends HybridModel {

return val;
}

paginationEnabled() {
return this.$getters['paginationEnabled'](this.type);
}
}
Loading

0 comments on commit df2a4db

Please sign in to comment.