Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions common/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ type BaseStatus struct {

// BizOperationResponse represents the response from a business operation
type BizOperationResponse struct {
Command string `json:"command"` // Operation command executed
BizName string `json:"bizName"` // ClusterName of the business
BizVersion string `json:"bizVersion"` // Version of the business
Response ark_service.ArkResponse[ark.ArkResponseData] `json:"response"` // Response from ark service
Command string `json:"command"` // Operation command executed
BizName string `json:"bizName"` // ClusterName of the business
BizVersion string `json:"bizVersion"` // Version of the business
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)
Response ark_service.ArkResponse[ark.ArkResponseData] `json:"response"` // Response from ark service
Comment on lines +34 to +38
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

BizModelVersion addition looks correct; consider making it optional and verify upstream type alignment.

  • Good addition to carry podKey across the wire.
  • Suggest tag omitempty to avoid emitting empty values when older producers don’t populate it.
  • Please verify arkctl’s ark.BizModel includes BizModelVersion so assignments in tunnels compile and serialize as expected.

Apply:

-	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)
+	BizModelVersion string                                       `json:"bizModelVersion,omitempty"` // 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)

To double‑check usage and upstream type availability:

Optionally confirm upstream library shape via web:


🏁 Script executed:

#!/bin/bash
# Find all assignments/usages to BizModelVersion across the repo
rg -nP -C2 '\bBizModelVersion\b'

# Find StartBiz/StopBiz call sites and confirm a non-empty podKey is passed
rg -nP -C3 '\b(StartBiz|StopBiz)\s*\('

Length of output: 7764


🌐 Web query:

Does github.com/koupleless/arkctl/v1/service/ark define BizModel with a field named BizModelVersion?

💡 Result:

No. The BizModel defined in github.com/koupleless/arkctl/v1/service/ark has fields BizName, BizVersion and BizUrl — it does not define a field named BizModelVersion. [1]

Sources:
[1] pkg.go.dev reference for github.com/koupleless/arkctl/v1/service/ark (type BizModel).


Add omitempty and fix upstream type mismatch (BizModelVersion missing in ark.BizModel)

  • Apply this diff to common/model/model.go:
-	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)
+	BizModelVersion string                                       `json:"bizModelVersion,omitempty"` // 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)
  • Verification result: github.com/koupleless/arkctl/v1/service/ark.BizModel does NOT define BizModelVersion. Current code assigns bizModel.BizModelVersion = podKey and includes BizModelVersion in requests (see module_tunnels/koupleless_http_tunnel/http_tunnel.go and module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go). This creates a type/serialization mismatch — resolve by either:
    • adding BizModelVersion to the upstream ark.BizModel, or
    • moving the podKey into the request field(s) that ark_service expects and updating all call sites, then rebuild to confirm.
🤖 Prompt for AI Agents
In common/model/model.go around lines 34 to 38, the JSON tag for BizModelVersion
should include `omitempty` and the current inclusion of BizModelVersion creates
a type/serialization mismatch because ark.BizModel upstream does not define
BizModelVersion; fix by either (A) adding BizModelVersion to the upstream
ark.BizModel definition (matching name and type) so serialization aligns, or (B)
remove BizModelVersion from this model and move the podKey value into the
request field(s) that ark_service expects, then update all call sites
(module_tunnels/*) to use the new request field(s) and rebuild to confirm the
mismatch is resolved; also ensure the BizModelVersion JSON tag is changed to
include `omitempty` if you keep the field locally.

}

type BatchInstallBizResponse struct {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/go-logr/logr v1.4.2
github.com/go-resty/resty/v2 v2.11.0
github.com/google/uuid v1.6.0
github.com/koupleless/arkctl v0.2.4-0.20250106035535-5ed5cb871995
github.com/koupleless/virtual-kubelet v0.3.10
github.com/koupleless/arkctl v0.2.5
github.com/koupleless/virtual-kubelet v0.3.11
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/sirupsen/logrus v1.9.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/koupleless/arkctl v0.2.4-0.20250106035535-5ed5cb871995 h1:dkBdI/WczkOJ4LaoZteX3uz8r+WKxBqYQjpzwyVDvyw=
github.com/koupleless/arkctl v0.2.4-0.20250106035535-5ed5cb871995/go.mod h1:nbnAiPEv7x/ZDQ+QsjFWkqwxMDofGmqnFPHa3XpXHyE=
github.com/koupleless/virtual-kubelet v0.3.10 h1:2hCYTHrsfQRe8jTwYGvFz+Ag4kpEn2wkcxfT4tLpoPg=
github.com/koupleless/virtual-kubelet v0.3.10/go.mod h1:V/RjXRvoSNr55I9KMV+tgtOp6duxxBMcwyDTH04XiX0=
github.com/koupleless/arkctl v0.2.5 h1:gj3bcR/DjT/ycKzr7humewSW8ylmxaaQA+d+Jqi/lic=
github.com/koupleless/arkctl v0.2.5/go.mod h1:nbnAiPEv7x/ZDQ+QsjFWkqwxMDofGmqnFPHa3XpXHyE=
github.com/koupleless/virtual-kubelet v0.3.11 h1:BtzRKH0VkZAzjQ/eTHrJx8ozwiP1m4kHUfXXNPeeZL4=
github.com/koupleless/virtual-kubelet v0.3.11/go.mod h1:aLcqqggbasS6ZkYz0svcvhb+AQrEGw7nyPsKfCCF2aU=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down
25 changes: 14 additions & 11 deletions module_tunnels/koupleless_http_tunnel/http_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ func (h *HttpTunnel) QueryAllBizStatusData(nodeName string) error {
}

// StartBiz starts a container on the node
func (h *HttpTunnel) StartBiz(nodeName, _ string, container *corev1.Container) error {

func (h *HttpTunnel) StartBiz(nodeName, podKey string, container *corev1.Container) error {
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
h.Lock()
baseStatus, ok := h.nodeIdToBaseStatusMap[nodeID]
Expand All @@ -336,14 +335,16 @@ func (h *HttpTunnel) StartBiz(nodeName, _ string, container *corev1.Container) e
}

bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
bizModel.BizModelVersion = podKey
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
logger.Info("InstallModule")

// install current version
bizOperationResponse := model.BizOperationResponse{
Command: model.CommandInstallBiz,
BizName: bizModel.BizName,
BizVersion: bizModel.BizVersion,
Command: model.CommandInstallBiz,
BizName: bizModel.BizName,
BizVersion: bizModel.BizVersion,
BizModelVersion: podKey,
}

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

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

bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
bizModel.BizModelVersion = podKey
logger := zaplogger.FromContext(h.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
logger.Info("UninstallModule")

bizOperationResponse := model.BizOperationResponse{
Command: model.CommandUnInstallBiz,
BizName: bizModel.BizName,
BizVersion: bizModel.BizVersion,
Command: model.CommandUnInstallBiz,
BizName: bizModel.BizName,
BizVersion: bizModel.BizVersion,
BizModelVersion: podKey,
}

response, err := h.arkService.UninstallBiz(h.ctx, ark_service.UninstallBizRequest{
Expand Down
26 changes: 17 additions & 9 deletions module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"sync"
"time"

paho "github.com/eclipse/paho.mqtt.golang"
"github.com/koupleless/arkctl/v1/service/ark"
"github.com/koupleless/module_controller/common/model"
"github.com/koupleless/module_controller/common/utils"
"github.com/koupleless/module_controller/common/zaplogger"
"github.com/koupleless/module_controller/controller/module_deployment_controller"
"github.com/koupleless/module_controller/module_tunnels/koupleless_http_tunnel/ark_service"
"github.com/koupleless/module_controller/module_tunnels/koupleless_mqtt_tunnel/mqtt"
utils2 "github.com/koupleless/virtual-kubelet/common/utils"
vkModel "github.com/koupleless/virtual-kubelet/model"
"github.com/koupleless/virtual-kubelet/tunnel"
"github.com/virtual-kubelet/virtual-kubelet/log"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
"sync"
"time"
)

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

func (mqttTunnel *MqttTunnel) StartBiz(nodeName, _ string, container *corev1.Container) error {
func (mqttTunnel *MqttTunnel) StartBiz(nodeName, podKey string, container *corev1.Container) error {
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
bizModel.BizModelVersion = podKey
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
zlogger.Info("InstallModule")
installBizRequestBytes, _ := json.Marshal(bizModel)
installBizRequestBytes, _ := json.Marshal(ark_service.InstallBizRequest{
BizModel: bizModel,
})
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
return mqttTunnel.mqttClient.Pub(utils.FormatArkletCommandTopic(mqttTunnel.env, nodeID, model.CommandInstallBiz), mqtt.Qos0, installBizRequestBytes)
}

func (mqttTunnel *MqttTunnel) StopBiz(nodeName, _ string, container *corev1.Container) error {
func (mqttTunnel *MqttTunnel) StopBiz(nodeName, podKey string, container *corev1.Container) error {
bizModel := utils.TranslateCoreV1ContainerToBizModel(container)
unInstallBizRequestBytes, _ := json.Marshal(bizModel)
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion)
bizModel.BizModelVersion = podKey
unInstallBizRequestBytes, _ := json.Marshal(ark_service.UninstallBizRequest{
BizModel: bizModel,
})
zlogger := zaplogger.FromContext(mqttTunnel.ctx).WithValues("bizName", bizModel.BizName, "bizVersion", bizModel.BizVersion, "bizModelVersion", bizModel.BizModelVersion)
zlogger.Info("UninstallModule")
nodeID := utils2.ExtractNodeIDFromNodeName(nodeName)
return mqttTunnel.mqttClient.Pub(utils.FormatArkletCommandTopic(mqttTunnel.env, nodeID, model.CommandUnInstallBiz), mqtt.Qos0, unInstallBizRequestBytes)
Expand Down
Loading