Skip to content

Commit 498d12c

Browse files
metacosmandreaTP
authored andcommitted
feat: provide Kubernetes client version (#1706)
Generate a Versions file to be consumed at runtime Co-authored-by: Andrea Peruffo <[email protected]>
1 parent ae43b3b commit 498d12c

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

operator-framework-core/pom.xml

+14-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,26 @@
4040
<generateGitPropertiesFilename>${project.build.outputDirectory}/version.properties
4141
</generateGitPropertiesFilename>
4242
<includeOnlyProperties>
43-
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
43+
<includeOnlyProperty>^git.build.time$</includeOnlyProperty>
4444
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
4545
<includeOnlyProperty>git.branch</includeOnlyProperty>
4646
</includeOnlyProperties>
4747
<commitIdGenerationMode>full</commitIdGenerationMode>
4848
</configuration>
4949
</plugin>
50+
<plugin>
51+
<groupId>org.codehaus.mojo</groupId>
52+
<artifactId>templating-maven-plugin</artifactId>
53+
<version>1.0.0</version>
54+
<executions>
55+
<execution>
56+
<id>filtering-java-templates</id>
57+
<goals>
58+
<goal>filter-sources</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
</plugin>
5063
</plugins>
5164
</build>
5265

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.javaoperatorsdk.operator.api.config;
2+
3+
public final class Versions {
4+
5+
private Versions() {}
6+
7+
protected static final String JOSDK = "${project.version}";
8+
protected static final String KUBERNETES_CLIENT = "${fabric8-client.version}";
9+
10+
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public static Version loadFromProperties() {
6363
builtTime = Date.from(Instant.EPOCH);
6464
}
6565
return new Version(
66-
properties.getProperty("git.build.version", "unknown"),
6766
properties.getProperty("git.commit.id.abbrev", "unknown"),
6867
builtTime);
6968
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Version.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
/** A class encapsulating the version information associated with this SDK instance. */
77
public class Version {
88

9-
public static final Version UNKNOWN = new Version("unknown", "unknown", Date.from(Instant.EPOCH));
10-
11-
private final String sdk;
9+
public static final Version UNKNOWN = new Version("unknown", Date.from(Instant.EPOCH));
1210
private final String commit;
1311
private final Date builtTime;
1412

15-
public Version(String sdkVersion, String commit, Date builtTime) {
16-
this.sdk = sdkVersion;
13+
public Version(String commit, Date builtTime) {
1714
this.commit = commit;
1815
this.builtTime = builtTime;
1916
}
@@ -24,7 +21,7 @@ public Version(String sdkVersion, String commit, Date builtTime) {
2421
* @return the SDK project version
2522
*/
2623
public String getSdkVersion() {
27-
return sdk;
24+
return Versions.JOSDK;
2825
}
2926

3027
/**
@@ -45,4 +42,14 @@ public String getCommit() {
4542
public Date getBuiltTime() {
4643
return builtTime;
4744
}
45+
46+
/**
47+
* Returns the version of the Fabric8 Kubernetes Client being used by this version of the SDK
48+
*
49+
* @return the Fabric8 Kubernetes Client version
50+
*/
51+
@SuppressWarnings("unused")
52+
public String getKubernetesClientVersion() {
53+
return Versions.KUBERNETES_CLIENT;
54+
}
4855
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.javaoperatorsdk.operator.api.config;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class VersionTest {
8+
9+
@Test
10+
void versionShouldReturnTheSameResultFromMavenAndProperties() {
11+
String versionFromProperties = Utils.loadFromProperties().getSdkVersion();
12+
String versionFromMaven = Version.UNKNOWN.getSdkVersion();
13+
14+
assertEquals(versionFromProperties, versionFromMaven);
15+
}
16+
17+
}

0 commit comments

Comments
 (0)