Repository: quarkusio/quarkus
Issue: kubernetes dev service weird error when flavor is kind and setting api value

### Describe the bug

```
quarkus.kubernetes-client.devservices.flavor=kind
quarkus.kubernetes-client.devservices.api-version=1.22
```

gives:

```
2023-04-29 01:18:07,639 INFO  [org.tes.uti.ImageNameSubstitutor] (build-4) Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2023-04-29 01:18:07,643 INFO  [org.tes.DockerClientFactory] (build-4) Checking the system...
2023-04-29 01:18:07,644 INFO  [org.tes.DockerClientFactory] (build-4) ✔︎ Docker server version should be at least 1.6.0
2023-04-29 01:18:07,688 INFO  [io.qua.dep.dev.IsolatedDevModeMain] (main) Attempting to start live reload endpoint to recover from previous Quarkus startup failure
2023-04-29 01:18:07,906 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor#setupKubernetesDevService threw an exception: java.lang.RuntimeException: java.util.NoSuchElementException: No value present
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.setupKubernetesDevService(DevServicesKubernetesProcessor.java:119)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.orElseThrow(Optional.java:377)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.findOrElseThrow(DevServicesKubernetesProcessor.java:249)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.lambda$startKubernetes$5(DevServicesKubernetesProcessor.java:212)
        at java.base/java.util.Optional.map(Optional.java:260)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.lambda$startKubernetes$7(DevServicesKubernetesProcessor.java:212)
        at java.base/java.util.Optional.orElseGet(Optional.java:364)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.startKubernetes(DevServicesKubernetesProcessor.java:241)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.setupKubernetesDevService(DevServicesKubernetesProcessor.java:109)
        ... 11 more

        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:335)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:252)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:60)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:86)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:447)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:59)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:149)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:104)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:131)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor#setupKubernetesDevService threw an exception: java.lang.RuntimeException: java.util.NoSuchElementException: No value present
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.setupKubernetesDevService(DevServicesKubernetesProcessor.java:119)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.orElseThrow(Optional.java:377)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.findOrElseThrow(DevServicesKubernetesProcessor.java:249)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.lambda$startKubernetes$5(DevServicesKubernetesProcessor.java:212)
        at java.base/java.util.Optional.map(Optional.java:260)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.lambda$startKubernetes$7(DevServicesKubernetesProcessor.java:212)
        at java.base/java.util.Optional.orElseGet(Optional.java:364)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.startKubernetes(DevServicesKubernetesProcessor.java:241)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.setupKubernetesDevService(DevServicesKubernetesProcessor.java:109)
        ... 11 more

        at io.quarkus.builder.Execution.run(Execution.java:123)
        at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:79)
        at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:160)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:331)
        ... 9 more
Caused by: java.lang.RuntimeException: java.util.NoSuchElementException: No value present
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.setupKubernetesDevService(DevServicesKubernetesProcessor.java:119)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.orElseThrow(Optional.java:377)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.findOrElseThrow(DevServicesKubernetesProcessor.java:249)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.lambda$startKubernetes$5(DevServicesKubernetesProcessor.java:212)
        at java.base/java.util.Optional.map(Optional.java:260)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.lambda$startKubernetes$7(DevServicesKubernetesProcessor.java:212)
        at java.base/java.util.Optional.orElseGet(Optional.java:364)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.startKubernetes(DevServicesKubernetesProcessor.java:241)
        at io.quarkus.kubernetes.client.deployment.DevServicesKubernetesProcessor.setupKubernetesDevService(DevServicesKubernetesProcessor.java:109)
        ... 11 more

```

if I comment out API version then it does not hit this errorr.

### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

_No response_

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

_No response_

### 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`)

_No response_

### Additional information

_No response_

Changed files:
extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java

diff --git a/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java b/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
index 8deaab773cc..48e507f6126 100644
--- a/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
+++ b/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
@@ -15,7 +15,7 @@
 import java.util.Objects;
 import java.util.Optional;
 import java.util.function.Supplier;
-import java.util.stream.Stream;
+import java.util.stream.Collectors;
 
 import org.jboss.logging.Logger;
 import org.testcontainers.DockerClientFactory;
@@ -199,17 +199,19 @@ private RunningDevService startKubernetes(DockerStatusBuildItem dockerStatusBuil
             switch (config.flavor) {
                 case API_ONLY:
                     container = new ApiServerContainer(
-                            config.apiVersion.map(version -> findOrElseThrow(version, ApiServerContainerVersion.class))
+                            config.apiVersion
+                                    .map(version -> findOrElseThrow(config.flavor, version, ApiServerContainerVersion.class))
                                     .orElseGet(() -> latest(ApiServerContainerVersion.class)));
                     break;
                 case K3S:
                     container = new K3sContainer(
-                            config.apiVersion.map(version -> findOrElseThrow(version, K3sContainerVersion.class))
+                            config.apiVersion.map(version -> findOrElseThrow(config.flavor, version, K3sContainerVersion.class))
                                     .orElseGet(() -> latest(K3sContainerVersion.class)));
                     break;
                 case KIND:
                     container = new KindContainer(
-                            config.apiVersion.map(version -> findOrElseThrow(version, KindContainerVersion.class))
+                            config.apiVersion
+                                    .map(version -> findOrElseThrow(config.flavor, version, KindContainerVersion.class))
                                     .orElseGet(() -> latest(KindContainerVersion.class)));
                     break;
                 default:
@@ -241,12 +243,17 @@ private RunningDevService startKubernetes(DockerStatusBuildItem dockerStatusBuil
                 .orElseGet(defaultKubernetesClusterSupplier);
     }
 
-    <T extends KubernetesVersionEnum<T>> T findOrElseThrow(final String version, final Class<T> versions) {
+    <T extends KubernetesVersionEnum<T>> T findOrElseThrow(final Flavor flavor, final String version, final Class<T> versions) {
         final String versionWithPrefix = !version.startsWith("v") ? "v" + version : version;
-        return Stream.of(versions.getEnumConstants())
-                .filter(v -> v.descriptor().getKubernetesVersion().equalsIgnoreCase(versionWithPrefix))
+        return KubernetesVersionEnum.ascending(versions)
+                .stream()
+                .filter(v -> v.descriptor().getKubernetesVersion().startsWith(versionWithPrefix))
                 .findFirst()
-                .orElseThrow();
+                .orElseThrow(() -> new IllegalArgumentException(
+                        String.format("Invalid API version '%s' for flavor '%s'. Options are: [%s]", versionWithPrefix, flavor,
+                                KubernetesVersionEnum.ascending(versions).stream()
+                                        .map(v -> v.descriptor().getKubernetesVersion())
+                                        .collect(Collectors.joining(", ")))));
     }
 
     private Map<String, String> getKubernetesClientConfigFromKubeConfig(KubeConfig kubeConfig) {