Skip to content

Commit

Permalink
Addressed remaining code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msupic committed Oct 16, 2024
1 parent 0b86072 commit 55ca735
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 21 deletions.
38 changes: 38 additions & 0 deletions examples/example-kubernetes-client-openapi-java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'io.micronaut.build.internal.kubernetes-examples'
id 'groovy'
}

micronaut {
version libs.versions.micronaut.platform.get()
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("micronaut.client.*")
}
}

dependencies {
annotationProcessor(mnValidation.micronaut.validation.processor)
annotationProcessor(mnSerde.micronaut.serde.processor)
implementation(mnValidation.micronaut.validation)
implementation(mnSerde.micronaut.serde.jackson)
implementation(mn.micronaut.management)
implementation projects.micronautKubernetesClientOpenapi
compileOnly(mn.micronaut.http.client)
runtimeOnly(mnLogging.logback.classic)
}

application {
mainClass.set("micronaut.client.Application")
}
tasks {
dockerBuild {
images = ['micronaut-kubernetes-client-openapi-example']
}

dockerBuildNative {
images = ['micronaut-kubernetes-client-openapi-example']
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package micronaut.client;

import io.micronaut.runtime.Micronaut;

public class Application {

public static void main(String[] args) {
Micronaut.run(Application.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package micronaut.client;

import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.kubernetes.client.openapi.api.CoreV1Api;
import io.micronaut.kubernetes.client.openapi.model.V1Pod;
import io.micronaut.kubernetes.client.openapi.model.V1PodList;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
import jakarta.inject.Inject;
import jakarta.validation.constraints.NotNull;

import java.util.Map;
import java.util.stream.Collectors;

@Controller("/pods")
@ExecuteOn(TaskExecutors.BLOCKING)
public class PodController {

@Inject
CoreV1Api coreV1Api;

@Get("/{namespace}/{name}")
public String getPod(final @NotNull String namespace, final @NotNull String name) {
V1Pod v1Pod = coreV1Api.readNamespacedPod(name, namespace, null);
return v1Pod.getStatus().getPhase();
}

@Get("/{namespace}")
public Map<String, String> getPods(final @NotNull String namespace) {
V1PodList v1PodList = coreV1Api.listNamespacedPod(namespace, null, null, null, null, null, null, null, null, null, null, false);
return v1PodList.getItems().stream()
.filter(p -> p.getStatus() != null)
.collect(Collectors.toMap(
p -> p.getMetadata().getName(),
p -> p.getStatus().getPhase()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
micronaut:
server:
port: 8082
application:
name: micronaut-kubernetes-client-openapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([example-client]) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
public interface KubeConfigLoader {

/**
* Gets kube config.
* Returns {@link KubeConfig} instance which contains data from the kube config file. The method is
* called multiple times during the application context startup so the {@link KubeConfig} instance
* should be created when the method is called for the first time, cached and then returned by subsequent calls.
* Since it is called only in the context startup, it doesn't require thread synchronization.
*
* @return kube config
*/
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include 'test-utils'

include 'examples:example-client'
include 'examples:example-kubernetes-client'
include 'examples:example-kubernetes-client-openapi-java'
include 'examples:example-kubernetes-informer'
include 'examples:example-kubernetes-operator'
include 'examples:example-service'
Expand Down
21 changes: 1 addition & 20 deletions src/main/docs/guide/kubernetes-client-openapi.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,7 @@ dependency:io.micronaut.kubernetes:micronaut-kubernetes-client-openapi[]

Then you can simply use Micronaut injection to get configured apis object from package `io.micronaut.kubernetes.client.openapi.api`:

[source,java]
----
import io.micronaut.kubernetes.client.openapi.api.CoreV1Api;
import io.micronaut.kubernetes.client.openapi.model.V1PodList;
import jakarta.inject.Singleton;
@Singleton
public class MyService {
private final CoreV1Api coreV1Api;
public MyService(CoreV1Api coreV1Api) {
this.coreV1Api = coreV1Api;
}
public void myMethod(String namespace) {
V1PodList v1PodList = coreV1Api.listNamespacedPod(namespace, null, null, null, null, null, null, null, null, null, null, null);
}
}
----
snippet::micronaut.client.PodController[project-base="examples/example-kubernetes-client-openapi", source="main"]

.Configuration

Expand Down

0 comments on commit 55ca735

Please sign in to comment.