Skip to content

feat: provide Kubernetes client version #1706

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 5 commits into from
Jan 9, 2023
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
15 changes: 14 additions & 1 deletion operator-framework-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,26 @@
<generateGitPropertiesFilename>${project.build.outputDirectory}/version.properties
</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.build.time$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>git.branch</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>filtering-java-templates</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.javaoperatorsdk.operator.api.config;

public final class Versions {

private Versions() {}

protected static final String JOSDK = "${project.version}";
protected static final String KUBERNETES_CLIENT = "${fabric8-client.version}";

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static Version loadFromProperties() {
builtTime = Date.from(Instant.EPOCH);
}
return new Version(
properties.getProperty("git.build.version", "unknown"),
properties.getProperty("git.commit.id.abbrev", "unknown"),
builtTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
/** A class encapsulating the version information associated with this SDK instance. */
public class Version {

public static final Version UNKNOWN = new Version("unknown", "unknown", Date.from(Instant.EPOCH));

private final String sdk;
public static final Version UNKNOWN = new Version("unknown", Date.from(Instant.EPOCH));
private final String commit;
private final Date builtTime;

public Version(String sdkVersion, String commit, Date builtTime) {
this.sdk = sdkVersion;
public Version(String commit, Date builtTime) {
this.commit = commit;
this.builtTime = builtTime;
}
Expand All @@ -24,7 +21,7 @@ public Version(String sdkVersion, String commit, Date builtTime) {
* @return the SDK project version
*/
public String getSdkVersion() {
return sdk;
return Versions.JOSDK;
}

/**
Expand All @@ -45,4 +42,14 @@ public String getCommit() {
public Date getBuiltTime() {
return builtTime;
}

/**
* Returns the version of the Fabric8 Kubernetes Client being used by this version of the SDK
*
* @return the Fabric8 Kubernetes Client version
*/
@SuppressWarnings("unused")
public String getKubernetesClientVersion() {
return Versions.KUBERNETES_CLIENT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.javaoperatorsdk.operator.api.config;

import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;

public class VersionTest {

@Test
void versionShouldReturnTheSameResultFromMavenAndProperties() {
String versionFromProperties = Utils.loadFromProperties().getSdkVersion();
String versionFromMaven = Version.UNKNOWN.getSdkVersion();

assertEquals(versionFromProperties, versionFromMaven);
}

}