Skip to content

Use template metadata.name when creating pods from Job/CronJob #108977

@astraw99

Description

@astraw99

What happened?

When create job && cronJob with template metadata name specified, the metadata name of job-name or pod-name will not take effect.

Demo:
cronJob.yaml

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cronjob-name
spec:
  schedule: "* * * * *"
  jobTemplate:
    metadata:
      name: job-name
    spec:
      template:
        metadata:
          name: pod-name
        spec:
          containers:
          - image: busybox
          ...

job.yaml

apiVersion: batch/v1
kind: Job
metadata:
  name: job-name
spec:
  template:
    metadata:
      name: pod-name
    spec:
      containers:
      - image: busybox
      ...

The job-name created by demo-cronjob is just like cronjob-name-xxx, and the pod-name is just like cronjob-name-xxx-xxx;
The job-name created by demo-job is just like job-name, and the pod-name is just like job-name-xxx;

The issue is: the metadata name not take effect accordingly.

What did you expect to happen?

To honor the template metadata name, and take it into effect.

How can we reproduce it (as minimally and precisely as possible)?

Apply the Demo yaml above, then check the result resources.

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
# paste output here

Cloud provider

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.sig/appsCategorizes an issue or PR as relevant to SIG Apps.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions