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

[resources] Fix creation of jobs #307

Merged
merged 1 commit into from
Mar 10, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ NOTE: As semantic versioning states all 0.y.z releases can contain breaking chan
- [#297](https://github.com/kobsio/kobs/pull/297): [prometheus] Fix metrics, when Prometheus returns `Inf` value.
- [#303](https://github.com/kobsio/kobs/pull/303): [core] Fix missing borders for select elements.
- [#304](https://github.com/kobsio/kobs/pull/304): [resources] Fix formatting of cells for Custom Resource Definition.
- [#307](https://github.com/kobsio/kobs/pull/307): [resources] Fix creation of Jobs.

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AlertVariant, Button, ButtonVariant, Modal, ModalVariant } from '@patternfly/react-core';
import { V1CronJob, V1Job } from '@kubernetes/client-node';
import React from 'react';
import { V1Job } from '@kubernetes/client-node';

import { IResource, IResourceRow } from '@kobsio/plugin-core';
import { IAlert } from '../../../../utils/interfaces';
Expand Down Expand Up @@ -44,6 +44,8 @@ const CreateJob: React.FunctionComponent<ICreateJobProps> = ({
throw new Error('Resource is not defined');
}

const cronJob = resource.props as V1CronJob;

const job: V1Job = {
apiVersion: 'batch/v1',
kind: 'Job',
Expand All @@ -57,21 +59,23 @@ const CreateJob: React.FunctionComponent<ICreateJobProps> = ({
name: jobName,
namespace: resource.props.metadata.namespace,
},
spec: {
backoffLimit: resource.props.spec.jobTemplate.spec.backoffLimit,
completions: resource.props.spec.jobTemplate.spec.completions,
parallelism: resource.props.spec.jobTemplate.spec.parallelism,
template: {
metadata: {
labels: {
'job-name': jobName,
},
},
spec: resource.props.spec.jobTemplate.spec.template.spec,
},
},
spec: cronJob.spec?.jobTemplate.spec,
};

if (job.spec) {
if (job.spec.template.metadata) {
if (job.spec.template.metadata.labels) {
job.spec.template.metadata.labels['job-name'] = jobName;
}
} else {
job.spec.template.metadata = {
labels: {
'job-name': jobName,
},
};
}
}

const response = await fetch(
`/api/plugins/resources/resources?cluster=${resource.cluster}${
resource.namespace ? `&namespace=${resource.namespace}` : ''
Expand Down