Skip to content

chore: update to Quarkus 1.12.0 and fabric8 kubernetes-client 5.1.0 #345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,21 @@ to your project:
</dependency>
```

Create an Application, Quarkus will automatically create and inject a `KubernetesClient`, `Operator`
and `ConfigurationService` instances that your application can use, as shown below:
Create an Application, Quarkus will automatically create and inject a `KubernetesClient`, `Operator`, `ConfigurationService` and `ResourceController` instances that your application can use. Below, you can see the minimal code you need to write to get your operator and controllers up and running:

```java
@QuarkusMain
public class QuarkusOperator implements QuarkusApplication {

@Inject KubernetesClient client;

@Inject Operator operator;

@Inject ConfigurationService configuration;

public static void main(String... args) {
Quarkus.run(QuarkusOperator.class, args);
}

@Override
public int run(String... args) throws Exception {
final var config = configuration.getConfigurationFor(new CustomServiceController(client));
System.out.println("CR class: " + config.getCustomResourceClass());

operator.start();
Quarkus.waitForExit();
return 0;
}
Expand Down
9 changes: 8 additions & 1 deletion operator-framework-quarkus-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.parameters>true</maven.compiler.parameters>
<quarkus.version>1.11.3.Final</quarkus.version>
<quarkus.version>1.12.0.Final</quarkus.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
</properties>
Expand All @@ -31,6 +31,13 @@
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client-bom</artifactId>
<version>${fabric8-client.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
Expand Down
1 change: 1 addition & 0 deletions operator-framework-spring-boot-starter-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>Operator SDK - Spring Boot Starter - Tests</name>
<artifactId>operator-framework-spring-boot-starter-test</artifactId>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ void testCrdLoaded() {
assertThat(applicationContext.getBean(Operator.class)).isNotNull();
assertThat(
client
.apiextensions()
.v1()
.customResourceDefinitions()
.withName("customservices.sample.javaoperatorsdk")
.get())
.isNotNull();
assertThat(
client
.apiextensions()
.v1()
.customResourceDefinitions()
.withName("customservices.global.sample.javaoperatorsdk")
.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
Expand Down Expand Up @@ -70,10 +70,17 @@ public void initialize(
log.info("Operator is running with {}", controller.getClass().getCanonicalName());
}

public CustomResourceDefinition loadCRDAndApplyToCluster(String classPathYaml) {
CustomResourceDefinition crd = loadYaml(CustomResourceDefinition.class, classPathYaml);
k8sClient.customResourceDefinitions().createOrReplace(crd);
return crd;
public void loadCRDAndApplyToCluster(String classPathYaml) {
var crd = loadYaml(CustomResourceDefinition.class, classPathYaml);
if ("apiextensions.k8s.io/v1".equals(crd.getApiVersion())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather describe this as hackish but it works… 🤷🏼 😁

k8sClient.apiextensions().v1().customResourceDefinitions().createOrReplace(crd);
} else {
var crd2 =
loadYaml(
io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition.class,
classPathYaml);
k8sClient.apiextensions().v1beta1().customResourceDefinitions().createOrReplace(crd2);
}
}

public void cleanup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Kind;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.javaoperatorsdk")
@Version("v1")
@Kind("DoubleUpdateSample")
@ShortNames("du")
public class DoubleUpdateTestCustomResource
extends CustomResource<DoubleUpdateTestCustomResourceSpec, DoubleUpdateTestCustomResourceStatus>
implements Namespaced {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Kind;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.javaoperatorsdk")
@Version("v1")
@Kind("Eventsourcesample")
@ShortNames("es")
public class EventSourceTestCustomResource
extends CustomResource<EventSourceTestCustomResourceSpec, EventSourceTestCustomResourceStatus>
implements Namespaced {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Kind;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.javaoperatorsdk")
@Version("v1")
@Kind("retrysample")
@ShortNames("rs")
public class RetryTestCustomResource
extends CustomResource<RetryTestCustomResourceSpec, RetryTestCustomResourceStatus>
implements Namespaced {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Kind;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.javaoperatorsdk")
@Version("v1")
@Kind("CustomService")
@ShortNames("cs")
public class TestCustomResource
extends CustomResource<TestCustomResourceSpec, TestCustomResourceStatus>
implements Namespaced {}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public UpdateControl<TestCustomResource> createOrUpdateResource(
}
resource.getStatus().setConfigMapStatus("ConfigMap Ready");
}
return UpdateControl.updateCustomResource(resource);
return UpdateControl.updateStatusSubResource(resource);
}

private Map<String, String> configMapData(TestCustomResource resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Kind;
import io.fabric8.kubernetes.model.annotation.Plural;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.javaoperatorsdk")
@Version("v1")
@Kind("SubresourceSample")
@Plural("subresourcesample")
@ShortNames("ss")
public class SubResourceTestCustomResource
extends CustomResource<SubResourceTestCustomResourceSpec, SubResourceTestCustomResourceStatus>
implements Namespaced {}
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: doubleupdatesamples.sample.javaoperatorsdk
spec:
group: sample.javaoperatorsdk
version: v1
subresources:
status: {}
scope: Namespaced
names:
kind: DoubleUpdateSample
plural: doubleupdatesamples
singular: doubleupdatesample
kind: DoubleUpdateSample
shortNames:
- du
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
properties:
status:
properties:
state:
type: string
enum:
- "SUCCESS"
- "ERROR"
type: object
spec:
properties:
value:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: { }
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: eventsourcesamples.sample.javaoperatorsdk
spec:
group: sample.javaoperatorsdk
version: v1
subresources:
status: { }
scope: Namespaced
names:
kind: Eventsourcesample
plural: eventsourcesamples
singular: eventsourcesample
kind: Eventsourcesample
shortNames:
- es
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
properties:
status:
properties:
state:
type: string
enum:
- "SUCCESS"
- "ERROR"
type: object
spec:
properties:
value:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: { }
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: retrysamples.sample.javaoperatorsdk
spec:
group: sample.javaoperatorsdk
version: v1
subresources:
status: { }
scope: Namespaced
names:
kind: retrysample
plural: retrysamples
singular: retrysample
kind: retrysample
shortNames:
- rs
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
properties:
status:
properties:
state:
type: string
enum:
- "SUCCESS"
- "ERROR"
type: object
spec:
properties:
value:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: { }
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: subresourcesample.sample.javaoperatorsdk
spec:
group: sample.javaoperatorsdk
version: v1
subresources:
status: { }
scope: Namespaced
names:
kind: SubresourceSample
plural: subresourcesample
singular: subresourcesample
kind: SubresourceSample
shortNames:
- ss
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
properties:
status:
properties:
state:
type: string
enum:
- "SUCCESS"
- "ERROR"
type: object
spec:
properties:
value:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: { }
Loading