Repository: kubernetes
Issue: job executions started manually for a cronjob are marked as unexpected
Labels: kind/bug,priority/backlog,sig/apps,triage/accepted

### What happened?

We have a custom resource with a name - `Foo`
We have a CronJob named - `Foo`

Now, we have a job whose owner refernce is set to the custom resource name - `Foo`. We have noticed that the job when stopped (suspended) basically causes an event/warning - "[UnexpectedJob](https://github.com/kubernetes/kubernetes/blob/8b132ea40a250e9acf08ab2fadb9a8c2fd811d74/pkg/controller/cronjob/cronjob_controllerv2.go#L444C39-L444C55)" for the given job execution.

[syncCronJob](https://github.com/kubernetes/kubernetes/blob/8b132ea40a250e9acf08ab2fadb9a8c2fd811d74/pkg/controller/cronjob/cronjob_controllerv2.go#L422C25-L422C36) is trying to reconcile the job because it thinks that it is owned by the CronJob. Probably because of "[getJobsToBeReconciled](https://github.com/kubernetes/kubernetes/blob/8b132ea40a250e9acf08ab2fadb9a8c2fd811d74/pkg/controller/cronjob/cronjob_controllerv2.go#L252C25-L252C46)", at this [line](https://github.com/kubernetes/kubernetes/blob/8b132ea40a250e9acf08ab2fadb9a8c2fd811d74/pkg/controller/cronjob/cronjob_controllerv2.go#L264C3-L264C110).

### What did you expect to happen?

The `syncCronJob` should not try to reconcile the job because it is not owned by the CronJob. 

**Proposed Solution**: [syncCronJob](https://github.com/kubernetes/kubernetes/blob/8b132ea40a250e9acf08ab2fadb9a8c2fd811d74/pkg/controller/cronjob/cronjob_controllerv2.go#L422C25-L422C36) should not reconcile the job, since it is owned by the CronJob. The `getJobsToBeReconciled` method should match the `name` and the `kind` of the job. The `kind` in the case of a cronjob would be `CronJob`.

### How can we reproduce it (as minimally and precisely as possible)?

- Run a job execution using the same CRD used to create a cronjob.
- Once the job execution starts, stop (suspend) it.
- We would start getting events of type `Warning` with reason - `UnexpectedJob`.
- Stop a job execution that was triggered due to the cronjob itself and we would not see warnings for this stopped job execution.

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version
# WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.2", GitCommit:"5835544ca568b757a8ecae5c153f317e5736700e", GitTreeState:"clean", BuildDate:"2022-09-21T14:33:49Z", GoVersion:"go1.19.1", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.6", GitCommit:"08d3594304660f86cfbd17bbb862041b4b75fe6c", GitTreeState:"clean", BuildDate:"2023-02-08T17:22:59Z", GoVersion:"go1.18.6", Compiler:"gc", Platform:"linux/amd64"}
```

</details>


### Cloud provider

<details>
N\A
</details>


### OS version

<details>

```console
# 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
```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>

</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>