generated from quarkiverse/quarkiverse-template
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add version info when the extension starts
- Loading branch information
Showing
4 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 67 additions & 5 deletions
72
runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/Version.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,78 @@ | ||
package io.quarkiverse.operatorsdk.runtime; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.Properties; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.javaoperatorsdk.operator.api.config.Utils; | ||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
/** | ||
* Re-publish with a recordable constructor so that quarkus can do its thing with it! | ||
*/ | ||
public class Version extends io.javaoperatorsdk.operator.api.config.Version { | ||
private static final Logger log = Logger.getLogger(Version.class.getName()); | ||
public static final String UNKNOWN = "unknown"; | ||
|
||
private final String extensionVersion; | ||
private final String extensionBranch; | ||
private final String extensionCommit; | ||
private final Date extensionBuildTime; | ||
|
||
@RecordableConstructor | ||
public Version(String sdkVersion, String commit, Date builtTime) { | ||
@RecordableConstructor // constructor needs to be recordable for the class to be passed around by Quarkus | ||
public Version(String sdkVersion, String commit, Date builtTime, String extensionVersion, String extensionCommit, | ||
String extensionBranch, Date extensionBuildTime) { | ||
super(sdkVersion, commit, builtTime); | ||
this.extensionVersion = extensionVersion; | ||
this.extensionBranch = extensionBranch; | ||
this.extensionCommit = extensionCommit; | ||
this.extensionBuildTime = extensionBuildTime; | ||
} | ||
|
||
public String getExtensionVersion() { | ||
return extensionVersion; | ||
} | ||
|
||
public String getExtensionBranch() { | ||
return extensionBranch; | ||
} | ||
|
||
public String getExtensionCommit() { | ||
return extensionCommit; | ||
} | ||
|
||
public Date getExtensionBuildTime() { | ||
return extensionBuildTime; | ||
} | ||
|
||
public static Version loadFromProperties() { | ||
final var sdkVersion = Utils.loadFromProperties(); | ||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("extension-version.properties"); | ||
Properties properties = new Properties(); | ||
if (is != null) { | ||
try { | ||
properties.load(is); | ||
} catch (IOException e) { | ||
log.warnf("Couldn't load extension version information: {0}", e.getMessage()); | ||
} | ||
} else { | ||
log.warn("Couldn't find version.properties file. Default version information will be used."); | ||
} | ||
|
||
Date builtTime; | ||
try { | ||
builtTime = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")).parse(properties.getProperty("git.build.time")); | ||
} catch (ParseException var4) { | ||
builtTime = Date.from(Instant.EPOCH); | ||
} | ||
|
||
return new Version(sdkVersion.getSdkVersion(), sdkVersion.getCommit(), sdkVersion.getBuiltTime(), | ||
properties.getProperty("git.build.version", UNKNOWN), | ||
properties.getProperty("git.commit.id.abbrev", UNKNOWN), | ||
properties.getProperty("git.branch", UNKNOWN), | ||
builtTime); | ||
} | ||
} |