HARVESTER: filter namespace in harvester cluster

This commit is contained in:
wujun 2021-09-27 17:40:48 +08:00
parent 6d99fba638
commit ae390c96fe
11 changed files with 68 additions and 11 deletions

View File

@ -1,10 +1,12 @@
<script> <script>
import { mapGetters } from 'vuex';
import { get } from '@/utils/object'; import { get } from '@/utils/object';
import { mapPref, GROUP_RESOURCES } from '@/store/prefs'; import { mapPref, GROUP_RESOURCES } from '@/store/prefs';
import ButtonGroup from '@/components/ButtonGroup'; import ButtonGroup from '@/components/ButtonGroup';
import SortableTable from '@/components/SortableTable'; import SortableTable from '@/components/SortableTable';
import { NAMESPACE } from '@/config/table-headers'; import { NAMESPACE } from '@/config/table-headers';
import { findBy } from '@/utils/array'; import { findBy } from '@/utils/array';
import { NAME as HARVESTER } from '@/config/product/harvester';
export default { export default {
components: { ButtonGroup, SortableTable }, components: { ButtonGroup, SortableTable },
@ -64,6 +66,7 @@ export default {
}, },
computed: { computed: {
...mapGetters(['isVirtualCluster']),
isNamespaced() { isNamespaced() {
if ( this.namespaced !== null ) { if ( this.namespaced !== null ) {
return this.namespaced; return this.namespaced;
@ -115,9 +118,10 @@ export default {
filteredRows() { filteredRows() {
const isAll = this.$store.getters['isAllNamespaces']; const isAll = this.$store.getters['isAllNamespaces'];
const isVirutalProduct = this.$store.getters['currentProduct'].name === HARVESTER;
// If the resources isn't namespaced or we want ALL of them, there's nothing to do. // If the resources isn't namespaced or we want ALL of them, there's nothing to do.
if ( !this.isNamespaced || isAll ) { if ( (!this.isNamespaced || isAll) && !isVirutalProduct) {
return this.rows || []; return this.rows || [];
} }
@ -129,7 +133,11 @@ export default {
} }
return this.rows.filter((row) => { return this.rows.filter((row) => {
return !!includedNamespaces[row.metadata.namespace]; if (this.isVirtualCluster && this.isNamespaced) {
return !!includedNamespaces[row.metadata.namespace] && !row.isSystemResource;
} else {
return !!includedNamespaces[row.metadata.namespace];
}
}); });
}, },

View File

@ -1,4 +1,5 @@
<script> <script>
import { mapGetters } from 'vuex';
import { get, set } from '@/utils/object'; import { get, set } from '@/utils/object';
import { sortBy } from '@/utils/sort'; import { sortBy } from '@/utils/sort';
import { NAMESPACE } from '@/config/types'; import { NAMESPACE } from '@/config/types';
@ -170,6 +171,7 @@ export default {
}, },
computed: { computed: {
...mapGetters(['isVirtualCluster']),
namespaceReallyDisabled() { namespaceReallyDisabled() {
return ( return (
!!this.forceNamespace || this.namespaceDisabled || this.mode === _EDIT !!this.forceNamespace || this.namespaceDisabled || this.mode === _EDIT
@ -185,7 +187,9 @@ export default {
const choices = this.$store.getters[`${ inStore }/all`](this.namespaceType); const choices = this.$store.getters[`${ inStore }/all`](this.namespaceType);
const out = sortBy( const out = sortBy(
choices.map((obj) => { choices.filter( (N) => {
return this.isVirtualCluster ? !N.isSystem && !N.isFleetManaged : true;
}).map((obj) => {
return { return {
label: obj.nameDisplay, label: obj.nameDisplay,
value: obj.id, value: obj.id,

View File

@ -5,6 +5,7 @@ import { NAMESPACE, MANAGEMENT } from '@/config/types';
import { sortBy } from '@/utils/sort'; import { sortBy } from '@/utils/sort';
import { isArray, addObjects, findBy, filterBy } from '@/utils/array'; import { isArray, addObjects, findBy, filterBy } from '@/utils/array';
import Select from '@/components/form/Select'; import Select from '@/components/form/Select';
import { NAME as HARVESTER } from '@/config/product/harvester';
export default { export default {
components: { Select }, components: { Select },
@ -76,7 +77,12 @@ export default {
const namespaces = sortBy( const namespaces = sortBy(
this.$store.getters[`${ inStore }/all`](NAMESPACE), this.$store.getters[`${ inStore }/all`](NAMESPACE),
['nameDisplay'] ['nameDisplay']
).filter( N => this.isVirtualCluster ? !N.isSystem : true); ).filter( (N) => {
const needFilter = !N.isSystem && !N.isFleetManaged;
const isVirtualProduct = this.$store.getters['currentProduct'].name === HARVESTER;
return this.isVirtualCluster && isVirtualProduct ? needFilter : true;
});
if (this.$store.getters['isRancher'] || this.isMultiVirtualCluster) { if (this.$store.getters['isRancher'] || this.isMultiVirtualCluster) {
const cluster = this.$store.getters['currentCluster']; const cluster = this.$store.getters['currentCluster'];
@ -104,7 +110,7 @@ export default {
projectId = null; projectId = null;
} }
let entry = namespacesByProject[namespace.projectId]; let entry = namespacesByProject[projectId];
if (!entry) { if (!entry) {
entry = []; entry = [];

View File

@ -89,6 +89,7 @@ export const FLEET = {
CLUSTER_DISPLAY_NAME: 'management.cattle.io/cluster-display-name', CLUSTER_DISPLAY_NAME: 'management.cattle.io/cluster-display-name',
CLUSTER_NAME: 'management.cattle.io/cluster-name', CLUSTER_NAME: 'management.cattle.io/cluster-name',
BUNDLE_ID: 'fleet.cattle.io/bundle-id', BUNDLE_ID: 'fleet.cattle.io/bundle-id',
MANAGED: 'fleet.cattle.io/managed'
}; };
export const RBAC = { PRODUCT: 'management.cattle.io/ui-product' }; export const RBAC = { PRODUCT: 'management.cattle.io/ui-product' };

View File

@ -49,7 +49,8 @@ export const SETTING = {
LOGO_DARK: 'ui-logo-dark', LOGO_DARK: 'ui-logo-dark',
PRIMARY_COLOR: 'ui-primary-color', PRIMARY_COLOR: 'ui-primary-color',
LINK_COLOR: 'ui-link-color', LINK_COLOR: 'ui-link-color',
COMMUNITY_LINKS: 'ui-community-links' COMMUNITY_LINKS: 'ui-community-links',
SYSTEM_NAMESPACES: 'system-namespaces'
}; };
// These are the settings that are allowed to be edited via the UI // These are the settings that are allowed to be edited via the UI

View File

@ -98,6 +98,7 @@ export default {
:headers="headers" :headers="headers"
:groupable="true" :groupable="true"
default-sort-by="age" default-sort-by="age"
:namespaced="true"
:rows="rows" :rows="rows"
:schema="schema" :schema="schema"
key-field="_key" key-field="_key"

View File

@ -1,6 +1,7 @@
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import ResourceTable from '@/components/ResourceTable'; import ResourceTable from '@/components/ResourceTable';
export default { export default {
name: 'ListNamespace', name: 'ListNamespace',
components: { ResourceTable }, components: { ResourceTable },
@ -16,11 +17,13 @@ export default {
}, },
computed: { computed: {
...mapGetters(['isSingleVirtualCluster']), ...mapGetters(['isVirtualCluster']),
filterRow() { filterRow() {
if (this.isSingleVirtualCluster) { if (this.isVirtualCluster) {
return this.rows.filter( N => !N.isSystem); return this.rows.filter( (N) => {
return !N.isSystem && !N.isFleetManaged;
});
} else { } else {
return this.rows; return this.rows;
} }

View File

@ -1,7 +1,8 @@
import SYSTEM_NAMESPACES from '@/config/system-namespaces'; import SYSTEM_NAMESPACES from '@/config/system-namespaces';
import { PROJECT, SYSTEM_NAMESPACE, ISTIO as ISTIO_LABELS } from '@/config/labels-annotations'; import { PROJECT, SYSTEM_NAMESPACE, ISTIO as ISTIO_LABELS, FLEET } from '@/config/labels-annotations';
import { ISTIO, MANAGEMENT } from '@/config/types'; import { ISTIO, MANAGEMENT } from '@/config/types';
import { get } from '@/utils/object';
import { escapeHtml } from '@/utils/string'; import { escapeHtml } from '@/utils/string';
import { insertAt, isArray } from '@/utils/array'; import { insertAt, isArray } from '@/utils/array';
@ -81,6 +82,10 @@ export default {
return false; return false;
}, },
isFleetManaged() {
return get(this, `metadata.labels."${ FLEET.MANAGED }"`) === 'true';
},
// These are namespaces that are created by rancher to serve purposes in the background but the user shouldn't have // These are namespaces that are created by rancher to serve purposes in the background but the user shouldn't have
// to worry themselves about them. // to worry themselves about them.
isObscure() { isObscure() {

View File

@ -8,6 +8,7 @@ import { PROJECT_ID } from '@/config/query-params';
import Masthead from '@/components/ResourceList/Masthead'; import Masthead from '@/components/ResourceList/Masthead';
import { mapPref, GROUP_RESOURCES, DEV } from '@/store/prefs'; import { mapPref, GROUP_RESOURCES, DEV } from '@/store/prefs';
import MoveModal from '@/components/MoveModal'; import MoveModal from '@/components/MoveModal';
import { NAME as HARVESTER } from '@/config/product/harvester';
export default { export default {
name: 'ListNamespace', name: 'ListNamespace',
@ -110,9 +111,10 @@ export default {
} }
const isVirtualCluster = this.$store.getters['isVirtualCluster']; const isVirtualCluster = this.$store.getters['isVirtualCluster'];
const isVirutalProduct = this.$store.getters['currentProduct'].name === HARVESTER;
return this.namespaces.filter((namespace) => { return this.namespaces.filter((namespace) => {
return isVirtualCluster ? (!namespace.isSystem && !namespace.isObscure) : !namespace.isObscure; return isVirtualCluster && isVirutalProduct ? (!namespace.isSystem && !namespace.isObscure) : !namespace.isObscure;
}); });
} }
}, },

View File

@ -607,6 +607,16 @@ export default {
}; };
}, },
isSystemResource() {
const systemNamespaces = this.$rootGetters['systemNamespaces'];
if ( systemNamespaces.includes(this.metadata?.namespace) ) {
return true;
}
return false;
},
isCondition() { isCondition() {
return (condition, withStatus = 'True') => { return (condition, withStatus = 'True') => {
if ( !this.status || !this.status.conditions ) { if ( !this.status || !this.status.conditions ) {

View File

@ -51,6 +51,7 @@ export const state = () => {
cameFromError: false, cameFromError: false,
pageActions: [], pageActions: [],
serverVersion: null, serverVersion: null,
systemNamespaces: []
}; };
}; };
@ -83,6 +84,10 @@ export const getters = {
return state.pageActions; return state.pageActions;
}, },
systemNamespaces(state) {
return state.systemNamespaces;
},
currentCluster(state, getters) { currentCluster(state, getters) {
return getters['management/byId'](MANAGEMENT.CLUSTER, state.clusterId); return getters['management/byId'](MANAGEMENT.CLUSTER, state.clusterId);
}, },
@ -451,6 +456,10 @@ export const mutations = {
setServerVersion(state, version) { setServerVersion(state, version) {
state.serverVersion = version; state.serverVersion = version;
},
setSystemNamespaces(state, namespaces) {
state.systemNamespaces = namespaces;
} }
}; };
@ -523,6 +532,7 @@ export const actions = {
const pl = res.settings?.find(x => x.name === 'ui-pl')?.value; const pl = res.settings?.find(x => x.name === 'ui-pl')?.value;
const brand = res.settings?.find(x => x.name === SETTING.BRAND)?.value; const brand = res.settings?.find(x => x.name === SETTING.BRAND)?.value;
const systemNamespaces = res.settings?.find(x => x.name === SETTING.SYSTEM_NAMESPACES);
if ( pl ) { if ( pl ) {
setVendor(pl); setVendor(pl);
@ -532,6 +542,12 @@ export const actions = {
setBrand(brand); setBrand(brand);
} }
if (systemNamespaces) {
const namespace = (systemNamespaces.value || systemNamespaces.default)?.split(',');
commit('setSystemNamespaces', namespace);
}
commit('managementChanged', { commit('managementChanged', {
ready: true, ready: true,
isMultiCluster, isMultiCluster,