Skip to content

Commit

Permalink
fix: readme and namings (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
csviri authored Nov 22, 2022
1 parent a219106 commit 78830b3
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 15 deletions.
68 changes: 62 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,61 @@
Framework and tooling to support
implementing [admission controllers](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/)
and [conversion hooks](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#webhook-conversion)
for Kubernetes in Java. Supports both **quarkus** and **spring boot**. Both Sync and Async programing model.
for Kubernetes in Java. Supports both **quarkus** and **spring boot**. Both **sync** and **async** programing model.

## Sample Usage

### Admission Controllers

Defining a mutation or validation controller is simple as:

https://github.com/java-operator-sdk/kubernetes-webhooks-framework/blob/0946595d941b789caef6a69b34c2e5be8c6b59cf/samples/quarkus/src/main/java/io/javaoperatorsdk/admissioncontroller/sample/quarkus/AdmissionControllerConfig.java#L31-L68
```java

What can be then simple used in an endpoint:
@Singleton
@Named(MUTATING_CONTROLLER)
public AdmissionController<Pod> mutatingController() {
return new AdmissionController<>((resource, operation) -> {
if (resource.getMetadata().getLabels() == null) {
resource.getMetadata().setLabels(new HashMap<>());
}
resource.getMetadata().getLabels().putIfAbsent(APP_NAME_LABEL_KEY, "mutation-test");
return resource;
});
}

@Singleton
@Named(VALIDATING_CONTROLLER)
public AdmissionController<Pod> validatingController() {
return new AdmissionController<>((resource, operation) -> {
if (resource.getMetadata().getLabels() == null
|| resource.getMetadata().getLabels().get(APP_NAME_LABEL_KEY) == null) {
throw new NotAllowedException("Missing label: " + APP_NAME_LABEL_KEY);
}
});
}

```

What can be simply used in an endpoint:

```java
@POST
@Path(MUTATE_PATH)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public AdmissionReview mutate(AdmissionReview admissionReview) {
return mutationController.handle(admissionReview);
}

@POST
@Path(VALIDATE_PATH)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public AdmissionReview validate(AdmissionReview admissionReview) {
return validationController.handle(admissionReview);
}
```

https://github.com/java-operator-sdk/kubernetes-webhooks-framework/blob/0946595d941b789caef6a69b34c2e5be8c6b59cf/samples/quarkus/src/main/java/io/javaoperatorsdk/admissioncontroller/sample/quarkus/AdmissionEndpoint.java#L57-L89

See samples also for details.

Expand All @@ -29,8 +71,22 @@ To create the controller
register [mappers](https://github.com/java-operator-sdk/kubernetes-webhooks-framework/blob/main/core/src/main/java/io/javaoperatorsdk/webhook/conversion/Mapper.java)
:

https://github.com/java-operator-sdk/kubernetes-webhooks-framework/blob/2a2bce54b49ea3398bef95a9102ee8645e11cf87/samples/quarkus/src/main/java/io/javaoperatorsdk/webhook/admission/sample/quarkus/conversion/ConversionControllerConfig.java#L15-L29
```java
@Singleton
public ConversionController conversionController() {
var controller = new ConversionController();
controller.registerMapper(new V1Mapper());
controller.registerMapper(new V2Mapper());
return controller;
}
```

and use the controllers in the endpoint:

https://github.com/java-operator-sdk/kubernetes-webhooks-framework/blob/2a2bce54b49ea3398bef95a9102ee8645e11cf87/samples/spring-boot/src/main/java/io/javaoperatorsdk/webhook/sample/springboot/conversion/ConversionEndpoint.java#L29-L40
```java
@PostMapping(CONVERSION_PATH)
@ResponseBody
public ConversionReview convert(@RequestBody ConversionReview conversionReview) {
return conversionController.handle(conversionReview);
}
```
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>kubernetes-webhooks-framework-core</artifactId>
<name>Admission Controller Framework - Core</name>
<name>Kubernetes Webhooks Framework - Core</name>
<packaging>jar</packaging>

<build>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>io.javaoperatorsdk</groupId>
<artifactId>kubernetes-webhooks-framework</artifactId>
<version>0.2.1-SNAPSHOT</version>
<name>Kubernetes Webhooks Framework for Java</name>
<name>Kubernetes Webhooks Framework</name>
<description>Framework to Implement Admission Controllers and Conversion Hooks in Java</description>
<packaging>pom</packaging>
<url>https://github.com/java-operator-sdk/kubernetes-webhooks-framework</url>
Expand Down
2 changes: 1 addition & 1 deletion samples/commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>io.javaoperatorsdk.admissioncontroller.sample</groupId>
<artifactId>sample-commons</artifactId>
<name>Admission Controller Framework - Samples - Commons</name>
<name>Kubernetes Webhooks Framework - Samples - Commons</name>

<properties>
<java.version>11</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public static AdmissionController<Pod> mutatingController() {
if (resource.getMetadata().getLabels() == null) {
resource.getMetadata().setLabels(new HashMap<>());
}

resource.getMetadata().getLabels().putIfAbsent(APP_NAME_LABEL_KEY, "mutation-test");
return resource;
});
Expand Down
2 changes: 1 addition & 1 deletion samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<artifactId>kubernetes-webhooks-framework-samples</artifactId>
<packaging>pom</packaging>
<name>Admission Controller Framework - Samples</name>
<name>Kubernetes Webhooks Framework - Samples</name>
<modules>
<module>commons</module>
<module>spring-boot</module>
Expand Down
4 changes: 2 additions & 2 deletions samples/quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<artifactId>kubernetes-webhooks-framework-samples</artifactId>
<version>0.2.1-SNAPSHOT</version>
</parent>
<groupId>io.javaoperatorsdk.admissioncontroller.sample</groupId>
<groupId>io.javaoperatorsdk.webhook.sample</groupId>
<artifactId>quarkus-sample</artifactId>
<name>Admission Controller Framework - Samples - Quarkus</name>
<name>Kubernetes Webhooks Framework - Samples - Quarkus</name>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.release>11</maven.compiler.release>
Expand Down
4 changes: 2 additions & 2 deletions samples/spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<version>0.2.1-SNAPSHOT</version>
</parent>

<groupId>io.javaoperatorsdk.admissioncontroller.sample</groupId>
<groupId>io.javaoperatorsdk.webhook.sample</groupId>
<artifactId>spring-boot-sample</artifactId>
<version>0.2.1-SNAPSHOT</version>
<name>Admission Controller Framework - Samples - Spring Boot</name>
<name>Kubernetes Webhooks Framework - Samples - Spring Boot</name>

<properties>
<java.version>11</java.version>
Expand Down

0 comments on commit 78830b3

Please sign in to comment.