This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 8d4292807 fix(k8s): stop re-stamping a certificate's modified instant
in the JVM zone (#5904)
8d4292807 is described below
commit 8d4292807d43270a0e808e7cb67d33a7a8f6fc3a
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:19:30 2026 +0800
fix(k8s): stop re-stamping a certificate's modified instant in the JVM zone
(#5904)
---
.../cluster/k8s/MybatisPlusK8sCertRepository.java | 8 +++++-
.../k8s/MybatisPlusK8sCertRepositoryTest.java | 29 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepository.java
b/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepository.java
index f1839ba9c..54c66a105 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepository.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepository.java
@@ -31,6 +31,7 @@ import org.springframework.util.StringUtils;
import lombok.RequiredArgsConstructor;
import java.time.LocalDateTime;
+import java.time.ZoneOffset;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
@@ -117,7 +118,12 @@ public class MybatisPlusK8sCertRepository implements
K8sCertRepository {
entity.setCertPem(cert.getCertPem());
entity.setKeyPem(cert.getKeyPem());
entity.setGmtCreate(cert.getGmtCreate());
- entity.setGmtModified(LocalDateTime.now());
+ // The service stamps both instants from its UTC clock (K8sCertService
uses Clock.systemUTC
+ // and the API contract is UTC wall time); re-stamping the modified
instant from the JVM
+ // default zone made GET /k8s-certs report it offset from gmt_create
of the same row.
+ entity.setGmtModified(cert.getGmtModified() != null
+ ? cert.getGmtModified()
+ : LocalDateTime.now(ZoneOffset.UTC));
return entity;
}
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepositoryTest.java
b/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepositoryTest.java
index 00d3b3d29..5fa2da43c 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepositoryTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/MybatisPlusK8sCertRepositoryTest.java
@@ -21,6 +21,10 @@ import
org.apache.rocketmq.studio.common.exception.BusinessException;
import org.apache.rocketmq.studio.persistence.entity.RmqK8sCertificate;
import org.apache.rocketmq.studio.persistence.mapper.RmqK8sCertificateMapper;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import java.util.TimeZone;
+import java.time.ZoneOffset;
+import java.time.LocalDateTime;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -136,6 +140,31 @@ class MybatisPlusK8sCertRepositoryTest {
.hasMessageContaining("certificate status");
}
+ @Test
+ void saveShouldPersistTheUtcModifiedInstantTheServiceStampedTest() {
+ RmqK8sCertificateMapper mapper = mock(RmqK8sCertificateMapper.class);
+ when(mapper.updateById(any(RmqK8sCertificate.class))).thenReturn(1);
+ K8sCertVO cert = K8sCertVO.builder().k8sId("broker").build();
+ cert.setId(1L);
+ LocalDateTime utcInstant =
LocalDateTime.now(ZoneOffset.UTC).minusHours(1);
+ cert.setGmtCreate(utcInstant);
+ cert.setGmtModified(utcInstant);
+
+ TimeZone previous = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
+ try {
+ repository(mapper).save(cert);
+ } finally {
+ TimeZone.setDefault(previous);
+ }
+
+ ArgumentCaptor<RmqK8sCertificate> entity =
ArgumentCaptor.forClass(RmqK8sCertificate.class);
+ verify(mapper).updateById(entity.capture());
+ // The repository used to overwrite it with LocalDateTime.now(): the
row's modified instant
+ // then disagreed with its UTC creation instant by the whole server
offset.
+ assertThat(entity.getValue().getGmtModified()).isEqualTo(utcInstant);
+ }
+
private MybatisPlusK8sCertRepository repository(RmqK8sCertificateMapper
mapper) {
return new MybatisPlusK8sCertRepository(mapper, new ObjectMapper());
}