mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-28 15:08:51 +00:00
fix(cache): use key versioning (#10657)
# Which Problems Are Solved Cached object may have a different schema between Zitadel versions. # How the Problems Are Solved Use the curent build version in DB based cache connectors PostgreSQL and Redis. # Additional Changes - Cleanup the ZitadelVersion field from the authz Instance - Solve potential race condition on global variables in build package. # Additional Context - Closes https://github.com/zitadel/zitadel/issues/10648 - Obsoletes https://github.com/zitadel/zitadel/pull/10646 - Needs to be back-ported to v4 over https://github.com/zitadel/zitadel/pull/10645
This commit is contained in:
+30
-17
@@ -1,33 +1,46 @@
|
||||
package build
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
var (
|
||||
version = ""
|
||||
commit = ""
|
||||
date = ""
|
||||
dateTime time.Time
|
||||
"github.com/zitadel/logging"
|
||||
)
|
||||
|
||||
func Version() string {
|
||||
if version != "" {
|
||||
return version
|
||||
// These variables are set via ldflags in the Makefile
|
||||
var (
|
||||
version = ""
|
||||
commit = ""
|
||||
date = ""
|
||||
)
|
||||
|
||||
// dateTime is the parsed version of [date]
|
||||
var dateTime time.Time
|
||||
|
||||
// init prevents race conditions when accessing dateTime and version.
|
||||
func init() {
|
||||
var err error
|
||||
dateTime, err = time.Parse(time.RFC3339, date)
|
||||
if err != nil {
|
||||
logging.WithError(err).Warn("could not parse build date, using current time instead")
|
||||
dateTime = time.Now()
|
||||
}
|
||||
version = Date().Format(time.RFC3339)
|
||||
if version == "" {
|
||||
logging.Warn("no build version set, using timestamp as version")
|
||||
version = date
|
||||
}
|
||||
}
|
||||
|
||||
// Version returns the current build version of Zitadel
|
||||
func Version() string {
|
||||
return version
|
||||
}
|
||||
|
||||
// Commit returns the git commit hash of the current build of Zitadel
|
||||
func Commit() string {
|
||||
return commit
|
||||
}
|
||||
|
||||
// Date returns the build date of the current build of Zitadel
|
||||
func Date() time.Time {
|
||||
if !dateTime.IsZero() {
|
||||
return dateTime
|
||||
}
|
||||
dateTime, _ = time.Parse(time.RFC3339, date)
|
||||
if dateTime.IsZero() {
|
||||
dateTime = time.Now()
|
||||
}
|
||||
return dateTime
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user