-
Notifications
You must be signed in to change notification settings - Fork 220
Fixes #318
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
Fixes #318
Changes from 8 commits
e77f2dd
4277b3d
174097f
8fa839e
4eb057b
f278c8f
2db6b5f
042d1e4
b791c4e
9edcde9
538e468
9c0ccbd
b9987a7
09ce889
6cde0be
ebb453e
d4d48cd
7608163
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,6 @@ default Config getClientConfiguration() { | |
} | ||
|
||
Set<String> getKnownControllerNames(); | ||
|
||
Version getVersion(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.javaoperatorsdk.operator.api.config; | ||
|
||
import java.io.IOException; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.Properties; | ||
|
||
public class Utils { | ||
|
||
public static Version loadFromProperties() { | ||
final var is = | ||
Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties"); | ||
final var properties = new Properties(); | ||
try { | ||
properties.load(is); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
Date builtTime; | ||
try { | ||
builtTime = | ||
// RFC 822 date is the default format used by git-commit-id-plugin | ||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") | ||
.parse(properties.getProperty("git.build.time")); | ||
} catch (ParseException e) { | ||
builtTime = Date.from(Instant.EPOCH); | ||
} | ||
return new Version( | ||
properties.getProperty("git.build.version", "unknown"), | ||
properties.getProperty("git.commit.id.abbrev", "unknown"), | ||
builtTime); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.javaoperatorsdk.operator.api.config; | ||
|
||
import java.util.Date; | ||
|
||
public class Version { | ||
private final String project; | ||
private final String commit; | ||
private final Date builtTime; | ||
|
||
public Version(String project, String commit, Date builtTime) { | ||
this.project = project; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @metacosm What is project stands for exactly? Isn't this information inherently redundant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or is this meant to be like the application name is spring boot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @metacosm still not sure about why is this? this seems to me some opionated way. Especially with build time and project. Commit id is fine? Is there some deeper meening of this, or its required by quarkus? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @csviri Maybe a better name would be helpful, indeed. This corresponds to the Maven project version. Why would it be redundant? The goal is to make sure that the operator is running the SDK version the user thinks it's running which can be helpful to diagnose issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, makes sense, but isn't the commit id enough for that, like log "running sdk version: {{commit id}}" . Or rather even the release version, thus version of the dependency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the project version is useful as a first check because it's not as easy to figure out which version of the SDK you're running solely from the commit id. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely, I agree, I just not see any field for real version (in terms of semantic versioning), just commit id and time stamp. Or am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why wouldn't the sdk version be useful? If you have a running operator on a cluster, it's easier to look at the logs than try to figure out which version of the code was used to build the image. Or make sure that the image is actually running the version of the code you think it is… 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its useful probably just the naming was confusing, so by "project" you meant the SDK Version right? I think that was the only issue, thus was not obviouse what it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I renamed it to |
||
this.commit = commit; | ||
this.builtTime = builtTime; | ||
} | ||
|
||
public String getProject() { | ||
return project; | ||
} | ||
|
||
public String getCommit() { | ||
return commit; | ||
} | ||
|
||
public Date getBuiltTime() { | ||
return builtTime; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
immutable classes 🧡