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 1996094: Fix missing key errors for pull policy messages #9847

Merged
Merged
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
56 changes: 29 additions & 27 deletions frontend/public/module/k8s/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@ import i18next from 'i18next';

import { ContainerSpec, ContainerStatus, PodKind } from './';

const PullPolicy = {
Always: {
id: 'Always',
label: i18next.t('public~Always pull'),
description: i18next.t(
'public~Pull down a new copy of the container image whenever a new pod is created.',
),
default: true,
},
IfNotPresent: {
id: 'IfNotPresent',
label: i18next.t('public~Pull if needed'),
description: i18next.t('public~If the container isn’t available locally, pull it down.'),
},
Never: {
id: 'Never',
label: i18next.t('public~Never pull'),
description: i18next.t(
"public~Don't pull down a container image. If the correct container image doesn't exist locally, the pod will fail to start correctly.",
),
},
};

// Parses the state from k8s container info field of a pod.
// Returned object will always have a 'label' property,
// but existence of other properties vary depending on the state.
Expand Down Expand Up @@ -56,8 +33,33 @@ export const getContainerStatus = (pod: PodKind, containerName: string): Contain
return _.find(statuses, identity) || _.find(initStatuses, identity);
};

const getPullPolicy = (container: ContainerSpec) =>
_.find(PullPolicy, { id: _.get(container, 'imagePullPolicy') });
const getPullPolicy = (container: ContainerSpec) => {
const pullPolicy = {
Always: {
id: 'Always',
label: i18next.t('public~Always pull'),
description: i18next.t(
'public~Pull down a new copy of the container image whenever a new pod is created.',
),
default: true,
},
IfNotPresent: {
id: 'IfNotPresent',
label: i18next.t('public~Pull if needed'),
description: i18next.t('public~If the container isn’t available locally, pull it down.'),
},
Never: {
id: 'Never',
label: i18next.t('public~Never pull'),
description: i18next.t(
"public~Don't pull down a container image. If the correct container image doesn't exist locally, the pod will fail to start correctly.",
),
},
};

return pullPolicy[container?.imagePullPolicy];
};

export const getPullPolicyLabel = (container: ContainerSpec): string =>
_.get(getPullPolicy(container), 'label', '');
export const getPullPolicyLabel = (container: ContainerSpec): string => {
return getPullPolicy(container)?.label || '';
};