Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1924583: Deprectaed templates are listed in the Templates screen #8038

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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