Skip to content

Commit

Permalink
Merge pull request #9847 from spadgett/fix-container-missing-key
Browse files Browse the repository at this point in the history
Bug 1996094: Fix missing key errors for pull policy messages
  • Loading branch information
openshift-merge-robot committed Aug 25, 2021
2 parents 228e7e5 + 34a4f8c commit 93836fc
Showing 1 changed file with 29 additions and 27 deletions.
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 || '';
};

0 comments on commit 93836fc

Please sign in to comment.