Files
harvester-ui-extension/pkg/harvester/utils/component-health.js
T
Marcelo Fukumoto 97ce1e90f6 feat: make the ignore rule dialog and the ignored checks clearer (#1255)
* feat: make the ignore rule dialog and the ignored checks clearer

In the ignore rule dialog, "Ignore for" becomes "Expiration" and
"Entire check" becomes "All resources". Editing an expired rule now
opens with a warning at the top that says when it expired, and only
its expiration can change until a new one is set. The warning that
the rule stays expired, shown at the bottom after a change, is gone.

In the Components table, "+ N ignored" is a link like "+ N more" and
shows that check's ignored resources. The checkbox only brings back the
checks ignored as a whole, reads "Show ignored checks" and counts them
in a badge. Checks with anything ignored get the warning banner's
background, and the filter also finds ignored resources.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* fix: put Expiration first and keep a locked Scope from changing

An expired rule's fields wait for a new expiration, so Expiration is
now the first field of the dialog instead of coming after the fields it
unlocks.

The shell's RadioGroup still takes the Up and Down keys once it is
clicked, even when it is disabled or in view mode. So on an expired rule
a click and Up switched the locked Scope, and Save then widened a rule
for some resources to the whole check. The dialog now ignores a scope
change while the rule is locked or only viewed.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

---------

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
2026-11-16 11:16:36 +01:00

101 lines
3.1 KiB
JavaScript

export const COMPONENT_LABEL = 'health.harvesterhci.io/component';
export const IGNORE_RULE_SOURCE_LABEL = 'health.harvesterhci.io/source';
export const IGNORE_DURATION_DAYS = {
days7: 7,
days30: 30,
forever: 0,
};
export const AFFECTED_RESOURCES_TRUNCATE_COUNT = 3;
export const MESSAGE_TRUNCATE_LENGTH = 100;
export const SEVERITY_COLORS = {
Error: 'bg-error',
Warning: 'bg-warning',
Info: 'bg-info',
Healthy: 'bg-success',
};
export const HEALTH_SUMMARY_SEVERITY_RANK = {
Error: 0,
Warning: 1,
Healthy: 2,
};
export const COMPONENT_HEALTH_SEVERITIES = ['Error', 'Warning', 'Info'];
export function severityColor(severity) {
return SEVERITY_COLORS[severity] || 'bg-info';
}
export function healthSummarySeverity(row) {
if (row.errorCount > 0) {
return 'Error';
}
if (row.warningCount > 0) {
return 'Warning';
}
return 'Healthy';
}
// the summaries already leave out what is ignored
export function totalErrorCount(healthSummaries) {
return (healthSummaries || []).reduce((total, summary) => {
return Object.values(summary?.status?.components || {}).reduce((sum, counts) => sum + (counts?.errorCount || 0), total);
}, 0);
}
export function componentOf(componentHealth) {
return componentHealth?.metadata?.labels?.[COMPONENT_LABEL] || componentHealth?.metadata?.name;
}
export function allAffectedResourceNames(row) {
return Object.keys(row?.affectedResources?.names || {});
}
// the resources that no HealthIgnoreRule ignores
export function activeAffectedResourceNames(row) {
const names = row?.affectedResources?.names || {};
return Object.keys(names).filter((name) => !names[name]?.ignored);
}
export function resourceIgnoredBy(row, name) {
const detail = row?.affectedResources?.names?.[name];
return detail?.ignored ? detail.ignoredBy : '';
}
export function ignoredResourceCount(row) {
return allAffectedResourceNames(row).length - activeAffectedResourceNames(row).length;
}
// the check is ignored as a whole, or some of its resources are
export function hasIgnored(check) {
return !!check?.ignored || ignoredResourceCount(check) > 0;
}
// the UI keeps one rule per check under this name, so Kubernetes refuses a second one for the same check.
// Some checks are named after a condition reason with spaces, like "Proactive Schedule Suspend", which a name can't have
export function ignoreRuleName(componentHealthName, checkName) {
const check = checkName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
return `${ componentHealthName }.${ check }`;
}
export function affectedResourceKind(row) {
return row?.affectedResources?.kind || '';
}
// what the UI calls that kind, in the singular or plural of how many there are
export function affectedResourceLabel(row, store) {
const { apiVersion = '', kind = '' } = row?.affectedResources || {};
const group = apiVersion.includes('/') ? `${ apiVersion.split('/')[0] }.` : '';
const schema = store.getters['harvester/schemaFor'](`${ group }${ kind.toLowerCase() }`);
return schema ? store.getters['type-map/labelFor'](schema, row.affectedCount) : kind;
}