Skip to content
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

Clean-ups and bug fixes #237

Merged
merged 26 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ea957a2
feat: make it possible to not automatically start the operator (#229)
metacosm Feb 11, 2022
b614ca1
feat!: remove deprecated configuration option
metacosm Feb 14, 2022
b89ca82
chore: update to latest SDK
metacosm Feb 14, 2022
208a07d
chore: remove unneeded versions
metacosm Feb 14, 2022
76018e6
feat: make it possible to not build samples
metacosm Feb 14, 2022
fc11615
fix: throw exception if CRD output directory cannot be created
metacosm Feb 14, 2022
c6a069f
chore: suppress warnings
metacosm Feb 14, 2022
a809975
refactor: move ResourceInfo to runtime module
metacosm Feb 14, 2022
a5d687e
refactor: create common-deployment module and move util classes there
metacosm Feb 14, 2022
9754c86
feat: getKnownReconcilers now only returns processable reconcilers
metacosm Feb 14, 2022
f67d1d6
fix: remove deprecated configuration option
metacosm Feb 14, 2022
b9a6d92
feat: do not start operator for tests
metacosm Feb 14, 2022
090545c
feat: do not register java classes for reflection
metacosm Feb 14, 2022
45b013c
fix: skip @Ignore'd reconciler before checking primary type
metacosm Feb 14, 2022
c556d85
fix: operator needs to start for delayed reconciler test to pass
metacosm Feb 14, 2022
88f85a6
chore: remove unneeded version
metacosm Feb 21, 2022
1ffcb3c
fix: initial support for new dependent resource architecture
metacosm Feb 28, 2022
5f7496c
fix: revert to next branch version
metacosm Feb 28, 2022
fee9ea8
fix: throw exception if configuration is missing for reconciler
metacosm Feb 28, 2022
3b8155a
fix?: check if code is taken into account
metacosm Feb 28, 2022
7b20f54
fix: no need to use cache action anymore
metacosm Feb 28, 2022
77be810
fix: prevent tests from using already built artifacts
metacosm Mar 1, 2022
29f2271
fix: install instead of verify to make sure local artifacts are built
metacosm Mar 1, 2022
9dd5fe4
fix: do not deploy or sign integration tests
metacosm Mar 1, 2022
aa5268f
fix: improper logging
metacosm Mar 1, 2022
e4f9764
chore: upgrade to Quarkus 2.7.2
metacosm Mar 1, 2022
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
10 changes: 2 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,13 @@ jobs:
distribution: ${{ matrix.distribution }}
java-version: ${{ matrix.java }}
cache: 'maven'

- name: Get Date
id: get-date
run: |
echo "::set-output name=date::$(/bin/date -u "+%Y-%m")"
shell: bash
- name: Cache Maven Repository
id: cache-maven
uses: actions/cache@v2
with:
path: ~/.m2/repository
# refresh cache every month to avoid unlimited growth
key: maven-repo-${{ runner.os }}-${{ steps.get-date.outputs.date }}

- name: Build with Maven
run: mvn -B formatter:validate verify -Dnative --file pom.xml
run: mvn -B formatter:validate install -Dnative --file pom.xml

7 changes: 6 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</issueManagement>

<properties>
<quarkus.version>2.7.1.Final</quarkus.version>
<quarkus.version>2.7.2.Final</quarkus.version>
<java-operator-sdk.version>2.2.0-SNAPSHOT</java-operator-sdk.version>
<kubernetes-client.version>5.11.2</kubernetes-client.version>
</properties>
Expand Down Expand Up @@ -94,6 +94,11 @@
<artifactId>quarkus-operator-sdk-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.operatorsdk</groupId>
<artifactId>quarkus-operator-sdk-common-deployment</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
19 changes: 18 additions & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>2.7.1.Final</quarkus.version>
<quarkus.version>2.7.2.Final</quarkus.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
</properties>
<dependencyManagement>
Expand All @@ -30,6 +30,23 @@
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkiverse.operatorsdk</groupId>
<artifactId>quarkus-operator-sdk-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<repositories>
<repository>
<id>oss-sonatype</id>
Expand Down
39 changes: 39 additions & 0 deletions common-deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkiverse.operatorsdk</groupId>
<artifactId>quarkus-operator-sdk-build-parent</artifactId>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<name>Quarkus - Operator SDK - Common - Deployment</name>
<artifactId>quarkus-operator-sdk-common-deployment</artifactId>

<dependencies>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>operator-framework-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package io.quarkiverse.operatorsdk.common;

import static io.quarkiverse.operatorsdk.common.Constants.CUSTOM_RESOURCE;
import static io.quarkiverse.operatorsdk.common.Constants.HAS_METADATA;
import static io.quarkiverse.operatorsdk.common.Constants.IGNORE_RECONCILER;
import static io.quarkiverse.operatorsdk.common.Constants.RECONCILER;

import java.lang.reflect.Modifier;
import java.util.Optional;
import java.util.stream.Stream;

import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;

import io.quarkus.deployment.util.JandexUtil;

public class ClassUtils {

private ClassUtils() {
}

/**
* Metadata about a processable reconciler implementation.
*/
public static class ReconcilerInfo {
private final ClassInfo classInfo;
private final DotName primaryTypeName;
private final String name;

public ReconcilerInfo(ClassInfo classInfo, IndexView index) {
this.classInfo = classInfo;
final var primaryType = JandexUtil.resolveTypeParameters(classInfo.name(), RECONCILER, index)
.get(0);
this.primaryTypeName = primaryType.name();
this.name = ConfigurationUtils.getReconcilerName(classInfo);
}

public DotName primaryTypeName() {
return primaryTypeName;
}

public String name() {
return name;
}

public ClassInfo classInfo() {
return classInfo;
}
}

/**
* Only retrieve {@link io.javaoperatorsdk.operator.api.reconciler.Reconciler} implementations that should be considered by
* the extension, excluding the SDK's own implementations and non-processable (i.e. reconcilers that are not correctly
* parameterized) ones.
*
* @param index the {@link IndexView} used to retrieve class informations
* @param log a {@link Logger} used to output skipped reconcilers information
* @return a stream of {@link ReconcilerInfo} providing information about processable reconcilers
*/
public static Stream<ReconcilerInfo> getKnownReconcilers(IndexView index, Logger log) {
return index.getAllKnownImplementors(RECONCILER).stream()
.map(ci -> keep(ci, index, log))
.filter(Optional::isPresent)
.map(Optional::get);
}

private static Optional<ReconcilerInfo> keep(ClassInfo ci, IndexView index, Logger log) {
final var consideredClassName = ci.name();
if (Modifier.isAbstract(ci.flags())) {
log.warnv("Skipping ''{0}'' reconciler because it''s abstract", consideredClassName);
return Optional.empty();
}

// Ignore Reconciler implementations annotated with @Ignore
if (ci.annotations().containsKey(IGNORE_RECONCILER)) {
log.debugv("Skipping ''{0}'' reconciler because it''s annotated with @Ignore", consideredClassName);
return Optional.empty();
}

ReconcilerInfo info = new ReconcilerInfo(ci, index);
final var primaryTypeDN = info.primaryTypeName;
// if we get CustomResource instead of a subclass, ignore the controller since we cannot do anything with it
if (primaryTypeDN.toString() == null || CUSTOM_RESOURCE.equals(primaryTypeDN) || HAS_METADATA.equals(primaryTypeDN)) {
log.warnv(
"Skipped processing of ''{0}'' reconciler as it''s not parameterized with a CustomResource or HasMetadata sub-class",
info.name);
return Optional.empty();
}

return Optional.of(info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.logging.Logger;

import io.javaoperatorsdk.operator.ReconcilerUtils;
import io.javaoperatorsdk.operator.api.config.Utils;
Expand Down Expand Up @@ -73,32 +72,17 @@ public static <T> T annotationValueOrDefault(
/**
* Checks whether CRD presence should be checked on the cluster and if custom resources should be (somewhat) validated.
* If the {@link Utils#CHECK_CRD_ENV_KEY} system property is set, this will be used, regardless of other configuration
* options. Issues a warning if the older configuration property is used, in particular if it conflicts with the newer
* property value.
* options.
*
* @param oldValidateCRD optional value specified by the deprecated configuration property
* @param newValidateCRD new defaulted value from the supported configuration property
* @param log an optional {@link Logger} to log to (can be {@code null})
* @return the value specified by {@link Utils#CHECK_CRD_ENV_KEY} if set, the value specified by the new supported
* configuration property otherwise (the deprecated configuration property value is always overridden)
* @param validate value from the build time configuration
* @return the value specified by {@link Utils#CHECK_CRD_ENV_KEY} if set, the value specified by the build time
* configuration property otherwise
*/
public static boolean shouldValidateCustomResources(Optional<Boolean> oldValidateCRD, boolean newValidateCRD, Logger log) {
public static boolean shouldValidateCustomResources(boolean validate) {
if (Utils.isValidateCustomResourcesEnvVarSet()) {
return Utils.shouldCheckCRDAndValidateLocalModel();
}
if (log != null && oldValidateCRD.isPresent()) {
var validateCustomResources = oldValidateCRD.get();
String msg;
if (Boolean.TRUE.equals(validateCustomResources) != newValidateCRD) {
msg = String.format(
"Deprecated property check-crd-and-validate-local-model with value '%s' is overridden by crd.validate property value '%s'",
validateCustomResources, newValidateCRD);
} else {
msg = "Use of deprecated check-crd-and-validate-local-model property. Use crd.validate instead.";
}
log.warn(msg);
}
return newValidateCRD;
return validate;
}

public static String getReconcilerName(ClassInfo info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Ignore;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource;

public class Constants {
private Constants() {
Expand All @@ -17,4 +19,7 @@ private Constants() {
public static final DotName CUSTOM_RESOURCE = DotName.createSimple(CustomResource.class.getName());
public static final DotName HAS_METADATA = DotName.createSimple(HasMetadata.class.getName());
public static final DotName CONTROLLER_CONFIGURATION = DotName.createSimple(ControllerConfiguration.class.getName());
public static final DotName KUBERNETES_DEPENDENT_RESOURCE = DotName
.createSimple(KubernetesDependentResource.class.getName());
public static final DotName KUBERNETES_DEPENDENT = DotName.createSimple(KubernetesDependent.class.getName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.operatorsdk.common;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.javaoperatorsdk.operator.api.config.Utils;

class ConfigurationUtilsTest {
@Test
void shouldUseSystemPropertyIfPresent() {
if (Utils.isValidateCustomResourcesEnvVarSet()) {
Assertions.assertEquals(Utils.shouldCheckCRDAndValidateLocalModel(),
ConfigurationUtils.shouldValidateCustomResources(false));
}
}
}
24 changes: 0 additions & 24 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,4 @@

<name>Quarkus - Operator SDK - Common</name>
<artifactId>quarkus-operator-sdk-common</artifactId>

<dependencies>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
</dependency>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>operator-framework-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkiverse.operatorsdk.common;

public class ClassLoadingUtils {

private ClassLoadingUtils() {
}

public static <T> Class<T> loadClassIfNeeded(String className, Class<T> loadedOrNull) {
return loadedOrNull == null ? loadClass(className, loadedOrNull) : loadedOrNull;
}

@SuppressWarnings("unchecked")
public static <T> Class<T> loadClass(String className, Class<T> expected) {
try {
return (Class<T>) Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (Exception e) {
throw new IllegalArgumentException("Couldn't find class " + className, e);
}
}
}

This file was deleted.

Loading