Skip to content

Commit

Permalink
Merge pull request #8038 from glekner/fix-1924583
Browse files Browse the repository at this point in the history
Bug 1924583: Deprectaed templates are listed in the Templates screen
  • Loading branch information
openshift-merge-robot committed Feb 3, 2021
2 parents 8a1a285 + 2c4e97f commit a07aa74
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { history } from '@console/internal/components/utils';
import { TemplateKind } from '@console/internal/module/k8s';
import { VMWizardName } from '../../constants';
import { getFlavor, getWorkloadProfile } from '../../selectors/vm';
import { getTemplateName, isCommonTemplate } from '../../selectors/vm-template/basic';
import {
getTemplateName,
isCommonTemplate,
isDeprecatedTemplate,
} from '../../selectors/vm-template/basic';
import { isTemplateSourceError, TemplateSourceStatus } from '../../statuses/template/types';
import { TemplateItem } from '../../types/template';
import { getVMWizardCreateLink } from '../../utils/url';
Expand All @@ -17,7 +21,7 @@ export const filterTemplates = (
commonTemplates: TemplateKind[],
): TemplateItem[] => {
const userTemplateItems: TemplateItem[] = userTemplates
.filter((t) => !isCommonTemplate(t))
.filter((t) => !isCommonTemplate(t) && !isDeprecatedTemplate(t))
.map((t) => ({
metadata: {
name: t.metadata.name,
Expand All @@ -28,33 +32,35 @@ export const filterTemplates = (
variants: [t],
}));

const commonTemplateItems = commonTemplates.reduce((acc, t) => {
const name = getTemplateName(t);
if (acc[name]) {
const isRecommended = t.metadata.labels?.[DEFAULT_OS_VARIANT] === 'true';
if (isRecommended) {
acc[name].metadata = {
name: t.metadata.name,
uid: t.metadata.uid,
namespace: t.metadata.namespace,
};
acc[name].variants.unshift(t);
const commonTemplateItems = commonTemplates
.filter((t) => !isDeprecatedTemplate(t))
.reduce((acc, t) => {
const name = getTemplateName(t);
if (acc[name]) {
const isRecommended = t.metadata.labels?.[DEFAULT_OS_VARIANT] === 'true';
if (isRecommended) {
acc[name].metadata = {
name: t.metadata.name,
uid: t.metadata.uid,
namespace: t.metadata.namespace,
};
acc[name].variants.unshift(t);
} else {
acc[name].variants.push(t);
}
} else {
acc[name].variants.push(t);
acc[name] = {
metadata: {
name: t.metadata.name,
uid: t.metadata.uid,
namespace: t.metadata.namespace,
},
isCommon: true,
variants: [t],
};
}
} else {
acc[name] = {
metadata: {
name: t.metadata.name,
uid: t.metadata.uid,
namespace: t.metadata.namespace,
},
isCommon: true,
variants: [t],
};
}
return acc;
}, {} as { [key: string]: TemplateItem });
return acc;
}, {} as { [key: string]: TemplateItem });

Object.keys(commonTemplateItems).forEach((key) => {
const recommendedProfile = getWorkloadProfile(commonTemplateItems[key].variants[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const TEMPLATE_SUPPORT_LEVEL = 'template.kubevirt.io/provider-support-lev
export const TEMPLATE_PARENT_PROVIDER_ANNOTATION = 'template.kubevirt.ui/parent-provider';
export const TEMPLATE_PARENT_SUPPORT_LEVEL = 'template.kubevirt.ui/parent-support-level';
export const TEMPLATE_PARENT_PROVIDER_URL = 'template.kubevirt.ui/parent-provider-url';
export const TEMPLATE_DEPRECATED_ANNOTATION = 'template.kubevirt.io/deprecated';

export const LABEL_USED_TEMPLATE_NAME = 'vm.kubevirt.io/template';
export const LABEL_USED_TEMPLATE_NAMESPACE = 'vm.kubevirt.io/template.namespace';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TEMPLATE_PARENT_PROVIDER_ANNOTATION,
TEMPLATE_PROVIDER_URL,
TEMPLATE_PARENT_PROVIDER_URL,
TEMPLATE_DEPRECATED_ANNOTATION,
} from '../../constants';
import { TemplateItem } from '../../types/template';

Expand All @@ -28,6 +29,9 @@ export const getTemplateName = (template: TemplateKind): string =>
export const isCommonTemplate = (template: TemplateKind): boolean =>
template?.metadata?.labels?.[TEMPLATE_TYPE_LABEL] === TEMPLATE_TYPE_BASE;

export const isDeprecatedTemplate = (template: TemplateKind): boolean =>
getAnnotation(template, TEMPLATE_DEPRECATED_ANNOTATION) === 'true';

export const getTemplateSupport = (
template: TemplateKind,
): { provider: string; providerURL: string; parent: string; parentURL: string } => {
Expand Down

0 comments on commit a07aa74

Please sign in to comment.