Skip to content

Commit 8f5193f

Browse files
authored
fix: fix: improve message on version misalignment, change level to debug unless minor-level mismatch (#567)
1 parent 77fd0e5 commit 8f5193f

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

core/deployment/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
<groupId>io.fabric8</groupId>
4747
<artifactId>crd-generator-api</artifactId>
4848
</dependency>
49+
<dependency>
50+
<groupId>org.semver4j</groupId>
51+
<artifactId>semver4j</artifactId>
52+
<version>4.3.0</version>
53+
</dependency>
4954
<dependency>
5055
<groupId>io.dekorate</groupId>
5156
<artifactId>kubernetes-annotations</artifactId>

core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/OperatorSDKProcessor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import org.jboss.jandex.DotName;
1616
import org.jboss.logging.Logger;
17+
import org.semver4j.Semver;
18+
import org.semver4j.Semver.VersionDiff;
1719

1820
import com.fasterxml.jackson.databind.ObjectMapper;
1921

@@ -134,12 +136,20 @@ void updateControllerConfigurations(
134136
}
135137

136138
private void checkVersionCompatibility(String found, String expected, String name) {
137-
if (!found.equals(expected)) {
138-
String message = "Incompatible " + name + " version found: \"" + found + "\", expected: \"" + expected + "\"";
139+
final var foundVersion = Semver.coerce(found);
140+
final var expectedVersion = Semver.coerce(expected);
141+
if (!expectedVersion.equals(foundVersion)) {
142+
String message = "Mismatched " + name + " version found: \"" + found + "\", expected: \"" + expected + "\"";
139143
if (buildTimeConfiguration.failOnVersionCheck) {
140144
throw new RuntimeException(message);
141145
} else {
142-
log.warn(message);
146+
final var diff = expectedVersion.diff(foundVersion);
147+
if (diff.compareTo(VersionDiff.MINOR) >= 0) {
148+
log.warn(message
149+
+ " by at least a minor version and things might not work as expected.");
150+
} else {
151+
log.debug(message);
152+
}
143153
}
144154
}
145155
}

core/runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/BuildTimeOperatorConfiguration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ public class BuildTimeOperatorConfiguration {
5959
public Boolean stopOnInformerErrorDuringStartup;
6060

6161
/**
62-
* Whether to fail or only emit a warning on version validation at compile time.
62+
* Whether to fail or emit a debug-level (warning-level when misalignment is at the minor or above version level) log when
63+
* the extension detects that there are misaligned versions.
64+
* <p/>
65+
* The following versions are checked for alignment:
66+
* <ul>
67+
* <li>declared Quarkus version used to build the extension vs. actually used Quarkus version at runtime</li>
68+
* <li>Fabric8 client version used by JOSDK vs. actually used Fabric8 client version</li>
69+
* <li>Fabric8 client version used by Quarkus vs. actually used Fabric8 client version</li>
70+
* </ul>
6371
*/
6472
@ConfigItem(defaultValue = "false")
6573
public Boolean failOnVersionCheck;

docs/modules/ROOT/pages/includes/quarkus-operator-sdk.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ a|icon:lock[title=Fixed at build time] [[quarkus-operator-sdk_quarkus.operator-s
206206

207207
[.description]
208208
--
209-
Whether to fail or only emit a warning on version validation at compile time.
209+
Whether to fail or emit a debug-level (warning-level when misalignment is at the minor or above version level) log when the extension detects that there are misaligned versions.
210+
The following versions are checked for alignment:
211+
- declared Quarkus version used to build the extension vs. actually used Quarkus version at runtime
212+
- Fabric8 client version used by JOSDK vs. actually used Fabric8 client version
213+
- Fabric8 client version used by Quarkus vs. actually used Fabric8 client version
210214

211215
ifdef::add-copy-button-to-env-var[]
212216
Environment variable: env_var_with_copy_button:+++QUARKUS_OPERATOR_SDK_FAIL_ON_VERSION_CHECK+++[]

samples/exposedapp/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<groupId>io.quarkiverse.operatorsdk</groupId>
2323
<artifactId>quarkus-operator-sdk-bom</artifactId>
2424
<version>${project.version}</version>
25+
<scope>import</scope>
26+
<type>pom</type>
2527
</dependency>
2628
</dependencies>
2729
</dependencyManagement>

0 commit comments

Comments
 (0)