Skip to content

Commit 4f3d74a

Browse files
committed
feat(model): add BizModelVersion to BizOperationResponse
Enhance BizOperationResponse by including BizModelVersion field to track the version of the business model used during operations. feat(http_tunnel): update StartBiz and StopBiz to use podKey Refactor StartBiz and StopBiz methods to accept podKey parameter for better tracking of business model versions during operations. feat(mqtt_tunnel): update StartBiz and StopBiz to use podKey Modify StartBiz and StopBiz methods to include podKey parameter for improved business model version management in MQTT operations.
1 parent ea98ef8 commit 4f3d74a

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
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"` // Version of the business model
38+
Response ark_service.ArkResponse[ark.ArkResponseData] `json:"response"` // Response from ark service
3839
}
3940

4041
type BatchInstallBizResponse struct {

module_tunnels/koupleless_http_tunnel/http_tunnel.go

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

326326
// StartBiz starts a container on the node
327-
func (h *HttpTunnel) StartBiz(nodeName, _ string, container *corev1.Container) error {
327+
func (h *HttpTunnel) StartBiz(nodeName, podKey string, container *corev1.Container) error {
328328

329329
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
330330
h.Lock()
@@ -335,14 +335,16 @@ func (h *HttpTunnel) StartBiz(nodeName, _ string, container *corev1.Container) e
335335
}
336336

337337
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
338+
bizModel.BizModelVersion = podKey
338339
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
339340
logger.Info("InstallModule")
340341

341342
// install current version
342343
bizOperationResponse := model.BizOperationResponse{
343-
Command: model.CommandInstallBiz,
344-
BizName: bizModel.BizName,
345-
BizVersion: bizModel.BizVersion,
344+
Command: model.CommandInstallBiz,
345+
BizName: bizModel.BizName,
346+
BizVersion: bizModel.BizVersion,
347+
BizModelVersion: podKey,
346348
}
347349

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

359361
// StopBiz shuts down a container on the node
360-
func (h *HttpTunnel) StopBiz(nodeName, _ string, container *corev1.Container) error {
362+
func (h *HttpTunnel) StopBiz(nodeName, podKey string, container *corev1.Container) error {
361363
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
362364
h.Lock()
363365
baseStatus, ok := h.nodeIdToBaseStatusMap[nodeID]
@@ -367,13 +369,15 @@ func (h *HttpTunnel) StopBiz(nodeName, _ string, container *corev1.Container) er
367369
}
368370

369371
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
372+
bizModel.BizModelVersion = podKey
370373
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
371374
logger.Info("UninstallModule")
372375

373376
bizOperationResponse := model.BizOperationResponse{
374-
Command: model.CommandUnInstallBiz,
375-
BizName: bizModel.BizName,
376-
BizVersion: bizModel.BizVersion,
377+
Command: model.CommandUnInstallBiz,
378+
BizName: bizModel.BizName,
379+
BizVersion: bizModel.BizVersion,
380+
BizModelVersion: podKey,
377381
}
378382

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

module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go

Lines changed: 15 additions & 7 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,18 +431,24 @@ 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)
434436
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
435437
zlogger.Info("InstallModule")
436-
installBizRequestBytes, _ := json.Marshal(bizModel)
438+
installBizRequestBytes, _ := json.Marshal(ark_service.InstallBizRequest{
439+
BizModel: bizModel,
440+
PodKey: podKey,
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)
448+
unInstallBizRequestBytes, _ := json.Marshal(ark_service.UninstallBizRequest{
449+
BizModel: bizModel,
450+
PodKey: podKey,
451+
})
444452
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
445453
zlogger.Info("UninstallModule")
446454
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)

0 commit comments

Comments
 (0)