Skip to content

Commit 279ed41

Browse files
authored
Merge pull request #45 from Aiden2014/issue-405
fix 模块 pod 替换导致 JVM 进程内模块实例消失
2 parents 54dbf46 + f7ef6db commit 279ed41

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

common/model/model.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ type BaseStatus struct {
3131

3232
// BizOperationResponse represents the response from a business operation
3333
type BizOperationResponse struct {
34-
Command string `json:"command"` // Operation command executed
35-
BizName string `json:"bizName"` // ClusterName of the business
36-
BizVersion string `json:"bizVersion"` // Version of the business
37-
Response ark_service.ArkResponse[ark.ArkResponseData] `json:"response"` // Response from ark service
34+
Command string `json:"command"` // Operation command executed
35+
BizName string `json:"bizName"` // ClusterName of the business
36+
BizVersion string `json:"bizVersion"` // Version of the business
37+
BizModelVersion string `json:"bizModelVersion"` // Pod key (podKey) used for aligning module state with Kubernetes pod state to prevent old uninstall requests from removing new modules. Format: {bizName}-{template}-{randomString} (e.g., biz1-web-single-host-786dfc476f-x2hwk)
38+
Response ark_service.ArkResponse[ark.ArkResponseData] `json:"response"` // Response from ark service
3839
}
3940

4041
type BatchInstallBizResponse struct {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/go-logr/logr v1.4.2
1010
github.com/go-resty/resty/v2 v2.11.0
1111
github.com/google/uuid v1.6.0
12-
github.com/koupleless/arkctl v0.2.4-0.20250106035535-5ed5cb871995
13-
github.com/koupleless/virtual-kubelet v0.3.10
12+
github.com/koupleless/arkctl v0.2.5
13+
github.com/koupleless/virtual-kubelet v0.3.11
1414
github.com/onsi/ginkgo/v2 v2.19.0
1515
github.com/onsi/gomega v1.33.1
1616
github.com/sirupsen/logrus v1.9.3

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
100100
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
101101
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
102102
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
103-
github.com/koupleless/arkctl v0.2.4-0.20250106035535-5ed5cb871995 h1:dkBdI/WczkOJ4LaoZteX3uz8r+WKxBqYQjpzwyVDvyw=
104-
github.com/koupleless/arkctl v0.2.4-0.20250106035535-5ed5cb871995/go.mod h1:nbnAiPEv7x/ZDQ+QsjFWkqwxMDofGmqnFPHa3XpXHyE=
105-
github.com/koupleless/virtual-kubelet v0.3.10 h1:2hCYTHrsfQRe8jTwYGvFz+Ag4kpEn2wkcxfT4tLpoPg=
106-
github.com/koupleless/virtual-kubelet v0.3.10/go.mod h1:V/RjXRvoSNr55I9KMV+tgtOp6duxxBMcwyDTH04XiX0=
103+
github.com/koupleless/arkctl v0.2.5 h1:gj3bcR/DjT/ycKzr7humewSW8ylmxaaQA+d+Jqi/lic=
104+
github.com/koupleless/arkctl v0.2.5/go.mod h1:nbnAiPEv7x/ZDQ+QsjFWkqwxMDofGmqnFPHa3XpXHyE=
105+
github.com/koupleless/virtual-kubelet v0.3.11 h1:BtzRKH0VkZAzjQ/eTHrJx8ozwiP1m4kHUfXXNPeeZL4=
106+
github.com/koupleless/virtual-kubelet v0.3.11/go.mod h1:aLcqqggbasS6ZkYz0svcvhb+AQrEGw7nyPsKfCCF2aU=
107107
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
108108
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
109109
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=

module_tunnels/koupleless_http_tunnel/http_tunnel.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ func (h *HttpTunnel) QueryAllBizStatusData(nodeName string) error {
325325
}
326326

327327
// StartBiz starts a container on the node
328-
func (h *HttpTunnel) StartBiz(nodeName, _ string, container *corev1.Container) error {
329-
328+
func (h *HttpTunnel) StartBiz(nodeName, podKey string, container *corev1.Container) error {
330329
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
331330
h.Lock()
332331
baseStatus, ok := h.nodeIdToBaseStatusMap[nodeID]
@@ -336,14 +335,16 @@ func (h *HttpTunnel) StartBiz(nodeName, _ string, container *corev1.Container) e
336335
}
337336

338337
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
339-
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
338+
bizModel.BizModelVersion = podKey
339+
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
340340
logger.Info("InstallModule")
341341

342342
// install current version
343343
bizOperationResponse := model.BizOperationResponse{
344-
Command: model.CommandInstallBiz,
345-
BizName: bizModel.BizName,
346-
BizVersion: bizModel.BizVersion,
344+
Command: model.CommandInstallBiz,
345+
BizName: bizModel.BizName,
346+
BizVersion: bizModel.BizVersion,
347+
BizModelVersion: podKey,
347348
}
348349

349350
response, err := h.arkService.InstallBiz(h.ctx, ark_service.InstallBizRequest{
@@ -358,7 +359,7 @@ func (h *HttpTunnel) StartBiz(nodeName, _ string, container *corev1.Container) e
358359
}
359360

360361
// StopBiz shuts down a container on the node
361-
func (h *HttpTunnel) StopBiz(nodeName, _ string, container *corev1.Container) error {
362+
func (h *HttpTunnel) StopBiz(nodeName, podKey string, container *corev1.Container) error {
362363
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
363364
h.Lock()
364365
baseStatus, ok := h.nodeIdToBaseStatusMap[nodeID]
@@ -368,13 +369,15 @@ func (h *HttpTunnel) StopBiz(nodeName, _ string, container *corev1.Container) er
368369
}
369370

370371
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
371-
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
372+
bizModel.BizModelVersion = podKey
373+
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
372374
logger.Info("UninstallModule")
373375

374376
bizOperationResponse := model.BizOperationResponse{
375-
Command: model.CommandUnInstallBiz,
376-
BizName: bizModel.BizName,
377-
BizVersion: bizModel.BizVersion,
377+
Command: model.CommandUnInstallBiz,
378+
BizName: bizModel.BizName,
379+
BizVersion: bizModel.BizVersion,
380+
BizModelVersion: podKey,
378381
}
379382

380383
response, err := h.arkService.UninstallBiz(h.ctx, ark_service.UninstallBizRequest{

module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"strings"
9+
"sync"
10+
"time"
11+
812
paho "github.com/eclipse/paho.mqtt.golang"
913
"github.com/koupleless/arkctl/v1/service/ark"
1014
"github.com/koupleless/module_controller/common/model"
1115
"github.com/koupleless/module_controller/common/utils"
1216
"github.com/koupleless/module_controller/common/zaplogger"
1317
"github.com/koupleless/module_controller/controller/module_deployment_controller"
18+
"github.com/koupleless/module_controller/module_tunnels/koupleless_http_tunnel/ark_service"
1419
"github.com/koupleless/module_controller/module_tunnels/koupleless_mqtt_tunnel/mqtt"
1520
utils2 "github.com/koupleless/virtual-kubelet/common/utils"
1621
vkModel "github.com/koupleless/virtual-kubelet/model"
1722
"github.com/koupleless/virtual-kubelet/tunnel"
1823
"github.com/virtual-kubelet/virtual-kubelet/log"
1924
corev1 "k8s.io/api/core/v1"
2025
"sigs.k8s.io/controller-runtime/pkg/client"
21-
"strings"
22-
"sync"
23-
"time"
2426
)
2527

2628
var _ tunnel.Tunnel = &MqttTunnel{}
@@ -429,19 +431,25 @@ func (mqttTunnel *MqttTunnel) QueryAllBizStatusData(nodeName string) error {
429431
return mqttTunnel.mqttClient.Pub(utils.FormatArkletCommandTopic(mqttTunnel.env, nodeID, model.CommandQueryAllBiz), mqtt.Qos0, []byte("{}"))
430432
}
431433

432-
func (mqttTunnel *MqttTunnel) StartBiz(nodeName, _ string, container *corev1.Container) error {
434+
func (mqttTunnel *MqttTunnel) StartBiz(nodeName, podKey string, container *corev1.Container) error {
433435
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
434-
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
436+
bizModel.BizModelVersion = podKey
437+
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
435438
zlogger.Info("InstallModule")
436-
installBizRequestBytes, _ := json.Marshal(bizModel)
439+
installBizRequestBytes, _ := json.Marshal(ark_service.InstallBizRequest{
440+
BizModel: bizModel,
441+
})
437442
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
438443
return mqttTunnel.mqttClient.Pub(utils.FormatArkletCommandTopic(mqttTunnel.env, nodeID, model.CommandInstallBiz), mqtt.Qos0, installBizRequestBytes)
439444
}
440445

441-
func (mqttTunnel *MqttTunnel) StopBiz(nodeName, _ string, container *corev1.Container) error {
446+
func (mqttTunnel *MqttTunnel) StopBiz(nodeName, podKey string, container *corev1.Container) error {
442447
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
443-
unInstallBizRequestBytes, _ := json.Marshal(bizModel)
444-
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
448+
bizModel.BizModelVersion = podKey
449+
unInstallBizRequestBytes, _ := json.Marshal(ark_service.UninstallBizRequest{
450+
BizModel: bizModel,
451+
})
452+
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
445453
zlogger.Info("UninstallModule")
446454
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
447455
return mqttTunnel.mqttClient.Pub(utils.FormatArkletCommandTopic(mqttTunnel.env, nodeID, model.CommandUnInstallBiz), mqtt.Qos0, unInstallBizRequestBytes)

0 commit comments

Comments
 (0)