Repository: quarkusio/quarkus
Issue: Missing spec.template.metadata.labels in deployment

### Describe the bug

Following the OpenShift Guide (https://quarkus.io/guides/deploying-to-openshift) I tried to switch from the default DeploymentConfig to Deployment but ended up with the error:

```
Message: Deployment.apps "openshift-quickstart" is invalid: spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels`.
```

Looking at the produced openshift.yml I saw that there seems to be missing metadata labels in the spec template:

```yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    app.openshift.io/vcs-url: <<unknown>>
    app.quarkus.io/build-timestamp: 2022-11-25 - 17:08:22 +0000
  labels:
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
    app.kubernetes.io/name: openshift-quickstart
    app.openshift.io/runtime: quarkus
  name: openshift-quickstart
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: openshift-quickstart
      app.kubernetes.io/version: 1.0.0-SNAPSHOT
  template:
    spec:
      containers:
        - env:
            - name: JAVA_APP_JAR
              value: /deployments/quarkus-run.jar
          image: image-registry.openshift-image-registry.svc:5000/quarkus-test/openshift-quickstart:1.0.0-SNAPSHOT
          imagePullPolicy: Always
          name: openshift-quickstart
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP
---
```

### Expected behavior

Ending up with a working Deployment when using the config "quarkus.openshift.deployment-kind=Deployment"

### Actual behavior

```posh
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  49.388 s
[INFO] Finished at: 2022-11-25T18:08:46+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.14.1.Final:build (default) on project openshift-quickstart: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR]         [error]: Build step io.quarkus.kubernetes.deployment.KubernetesDeployer#deploy threw an exception: io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://api.crc.testing:6443/apis/apps/v1/namespaces/quarkus-test/deployments. Message: Deployment.apps "openshift-quickstart" is invalid: spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels`. Received status: Status(apiVersion=v1, code=422, details=StatusDetails(causes=[StatusCause(field=spec.template.metadata.labels, message=Invalid value: map[string]string(nil): `selector` does not match template `labels`, reason=FieldValueInvalid, additionalProperties={})], group=apps, kind=Deployment, name=openshift-quickstart, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=Deployment.apps "openshift-quickstart" is invalid: spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels`, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Invalid, status=Failure, additionalProperties={}).
[ERROR]         at io.fabric8.kubernetes.client.KubernetesClientException.copyAsCause(KubernetesClientException.java:238)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.waitForResult(OperationSupport.java:517)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleResponse(OperationSupport.java:551)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleResponse(OperationSupport.java:535)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleCreate(OperationSupport.java:328)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.handleCreate(BaseOperation.java:675)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.handleCreate(BaseOperation.java:88)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.CreateOnlyResourceOperation.create(CreateOnlyResourceOperation.java:42)
[ERROR]         at io.fabric8.kubernetes.client.utils.internal.CreateOrReplaceHelper.createOrReplace(CreateOrReplaceHelper.java:50)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.createOrReplace(BaseOperation.java:296)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.createOrReplace(BaseOperation.java:88)
[ERROR]         at io.fabric8.kubernetes.client.extension.ResourceAdapter.createOrReplace(ResourceAdapter.java:121)
[ERROR]         at io.quarkus.kubernetes.deployment.KubernetesDeployer.lambda$deploy$5(KubernetesDeployer.java:251)
[ERROR]         at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
[ERROR]         at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
[ERROR]         at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
[ERROR]         at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
[ERROR]         at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
[ERROR]         at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
[ERROR]         at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
[ERROR]         at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[ERROR]         at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
[ERROR]         at io.quarkus.kubernetes.deployment.KubernetesDeployer.deploy(KubernetesDeployer.java:226)
[ERROR]         at io.quarkus.kubernetes.deployment.KubernetesDeployer.deploy(KubernetesDeployer.java:135)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[ERROR]         at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
[ERROR]         at io.quarkus.builder.BuildContext.run(BuildContext.java:281)
[ERROR]         at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:833)
[ERROR]         at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] Caused by: io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://api.crc.testing:6443/apis/apps/v1/namespaces/quarkus-test/deployments. Message: Deployment.apps "openshift-quickstart" is invalid: spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels`. Received status: Status(apiVersion=v1, code=422, details=StatusDetails(causes=[StatusCause(field=spec.template.metadata.labels, message=Invalid value: map[string]string(nil): `selector` does not match template `labels`, reason=FieldValueInvalid, additionalProperties={})], group=apps, kind=Deployment, name=openshift-quickstart, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=Deployment.apps "openshift-quickstart" is invalid: spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels`, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Invalid, status=Failure, additionalProperties={}).
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.requestFailure(OperationSupport.java:709)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.requestFailure(OperationSupport.java:689)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.assertResponseCode(OperationSupport.java:640)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.lambda$handleResponse$0(OperationSupport.java:576)
[ERROR]         at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
[ERROR]         at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
[ERROR]         at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147)
[ERROR]         at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.lambda$retryWithExponentialBackoff$2(OperationSupport.java:618)
[ERROR]         at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863)
[ERROR]         at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841)
[ERROR]         at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
[ERROR]         at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147)
[ERROR]         at io.fabric8.kubernetes.client.okhttp.OkHttpClientImpl$4.onResponse(OkHttpClientImpl.java:277)
[ERROR]         at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
[ERROR]         at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
[ERROR]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[ERROR]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:833)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
```

### How to Reproduce?

1. mvn io.quarkus.platform:quarkus-maven-plugin:2.14.1.Final:create -DprojectGroupId=org.acme -DprojectArtifactId=openshift-quickstart -Dextensions="resteasy-reactive,openshift"
2. cd openshift-quickstart
3. mvnw install -Dquarkus.kubernetes.deploy=true -Dquarkus.openshift.deployment-kind=Deployment -Dquarkus.container-image.group=quarkus-test

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

Java version: 17.0.3

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

_No response_

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Apache Maven 3.8.6

### Additional information

_No response_

Changed files:
integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java
extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java

diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java
index c877ad32e26..2afcf46e728 100644
--- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java
+++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java
@@ -24,6 +24,8 @@ public void visit(KubernetesListFluent<?> list) {
                 .withMatchLabels(new HashMap<String, String>())
                 .endSelector()
                 .withNewTemplate()
+                .withNewMetadata()
+                .endMetadata()
                 .withNewSpec()
                 .addNewContainer()
                 .withName(name)
diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java
index d4e5ae89ea8..4b86271cfdc 100644
--- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java
+++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java
@@ -2,6 +2,7 @@
 package io.quarkus.it.kubernetes;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
 
 import java.io.IOException;
 import java.nio.file.Path;
@@ -29,10 +30,12 @@
 //
 public class OpenshiftWithDeploymentResourceTest {
 
+    private static final String NAME = "openshift-with-deployment-resource";
+
     @RegisterExtension
     static final QuarkusProdModeTest config = new QuarkusProdModeTest()
             .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class))
-            .setApplicationName("openshift-with-deployment-resource")
+            .setApplicationName(NAME)
             .setApplicationVersion("0.1-SNAPSHOT")
             .overrideConfigKey("quarkus.openshift.deployment-kind", "Deployment")
             .overrideConfigKey("quarkus.openshift.replicas", "3")
@@ -55,17 +58,21 @@ public void assertGeneratedResources() throws IOException {
         assertThat(kubernetesList).filteredOn(h -> "BuildConfig".equals(h.getKind())).hasSize(1);
         assertThat(kubernetesList).filteredOn(h -> "ImageStream".equals(h.getKind())).hasSize(2);
         assertThat(kubernetesList).filteredOn(h -> "ImageStream".equals(h.getKind())
-                && h.getMetadata().getName().equals("openshift-with-deployment-resource")).hasSize(1);
+                && h.getMetadata().getName().equals(NAME)).hasSize(1);
 
         assertThat(kubernetesList).filteredOn(i -> i instanceof Deployment).singleElement().satisfies(i -> {
             assertThat(i).isInstanceOfSatisfying(Deployment.class, d -> {
                 assertThat(d.getMetadata()).satisfies(m -> {
-                    assertThat(m.getName()).isEqualTo("openshift-with-deployment-resource");
+                    assertThat(m.getName()).isEqualTo(NAME);
                 });
 
                 assertThat(d.getSpec()).satisfies(deploymentSpec -> {
                     assertThat(deploymentSpec.getReplicas()).isEqualTo(3);
                     assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
+                        assertThat(t.getMetadata()).satisfies(metadata -> assertThat(metadata.getLabels()).containsAnyOf(
+                                entry("app.kubernetes.io/name", NAME),
+                                entry("app.kubernetes.io/version", "0.1-SNAPSHOT")));
+
                         assertThat(t.getSpec()).satisfies(podSpec -> {
                             assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
                                 assertThat(container.getImage())