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
3 changes: 3 additions & 0 deletions cmd/module-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func main() {

// Get configuration from environment variables
clientID := utils.GetEnv(model.EnvKeyOfClientID, uuid.New().String())
if _, ok := os.LookupEnv(model.EnvKeyOfClientID); !ok {
log.L.Infof("Randomly generated client ID: %s", clientID)
}
env := utils.GetEnv("ENV", "dev")

zlogger := zaplogger.GetLogger()
Expand Down
6 changes: 4 additions & 2 deletions common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package utils
import (
"context"
"fmt"
"github.com/koupleless/module_controller/common/zaplogger"
"strconv"
"strings"
"time"

"github.com/koupleless/module_controller/common/zaplogger"

"github.com/koupleless/arkctl/common/fileutil"
"github.com/koupleless/arkctl/v1/service/ark"
"github.com/koupleless/module_controller/common/model"
Expand Down Expand Up @@ -112,6 +113,7 @@ func ConvertHealthDataToNodeStatus(data ark.HealthData) vkModel.NodeStatusData {
resourceMap[corev1.ResourceMemory] = memory
return vkModel.NodeStatusData{
Resources: resourceMap,
NodeState: vkModel.NodeState(strings.ToUpper(data.MasterBizInfo.BizState)),
}
Comment on lines 114 to 117
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

Harden NodeState derivation; avoid empty/unknown values leaking through

If BizState is empty, we emit an empty NodeState. Recommend a safe fallback and normalization. Also, if MasterBizInfo is a pointer in arkctl, add a nil‑check (verify type).

Apply:

-        NodeState: vkModel.NodeState(strings.ToUpper(data.MasterBizInfo.BizState)),
+        NodeState: func() vkModel.NodeState {
+            v := strings.ToUpper(data.MasterBizInfo.BizState)
+            if v == "" {
+                return vkModel.NodeStateDeactivated
+            }
+            return vkModel.NodeState(v)
+        }(),

To confirm the allowed values and whether Unknown exists in vkModel, and whether MasterBizInfo is a pointer in arkctl:


🌐 Web query:

What are the defined values for vkModel.NodeState in github.com/koupleless/virtual-kubelet/model, and does a NodeStateUnknown constant exist? Also, in github.com/koupleless/arkctl (v1/service/ark), is HealthData.MasterBizInfo a pointer type?

💡 Result:

  • vkModel.NodeState (github.com/koupleless/virtual-kubelet/model) has two defined values: NodeStateActivated = "ACTIVATED" and NodeStateDeactivated = "DEACTIVATED". There is no NodeStateUnknown constant. [1]

  • In github.com/koupleless/arkctl (v1/service/ark) HealthData.MasterBizInfo is a value field of type MasterBizInfo (not a pointer). [2]

Sources:
[1] pkg.go.dev: github.com/koupleless/virtual-kubelet/model (NodeState). (pkg.go.dev)
[2] pkg.go.dev: github.com/koupleless/arkctl/v1/service/ark (HealthData, MasterBizInfo). (pkg.go.dev)

Citations:


Harden NodeState derivation — default empty BizState to vkModel.NodeStateDeactivated (no nil-check needed)

vkModel only defines ACTIVATED/DEACTIVATED (no Unknown). HealthData.MasterBizInfo is a value (not a pointer), so check for empty BizState and fall back to NodeStateDeactivated.

File: common/utils/utils.go Lines: 114-117

-        NodeState: vkModel.NodeState(strings.ToUpper(data.MasterBizInfo.BizState)),
+        NodeState: func() vkModel.NodeState {
+            v := strings.ToUpper(data.MasterBizInfo.BizState)
+            if v == "" {
+                return vkModel.NodeStateDeactivated
+            }
+            return vkModel.NodeState(v)
+        }(),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return vkModel.NodeStatusData{
Resources: resourceMap,
NodeState: vkModel.NodeState(strings.ToUpper(data.MasterBizInfo.BizState)),
}
return vkModel.NodeStatusData{
Resources: resourceMap,
NodeState: func() vkModel.NodeState {
v := strings.ToUpper(data.MasterBizInfo.BizState)
if v == "" {
return vkModel.NodeStateDeactivated
}
return vkModel.NodeState(v)
}(),
}
🤖 Prompt for AI Agents
In common/utils/utils.go around lines 114-117, the NodeState is derived directly
from data.MasterBizInfo.BizState which can be an empty string; change the logic
to check if BizState == "" and if so set NodeState to
vkModel.NodeStateDeactivated, otherwise set NodeState to
vkModel.NodeState(strings.ToUpper(data.MasterBizInfo.BizState)); keep the rest
of the returned vkModel.NodeStatusData unchanged.

}

Expand All @@ -133,7 +135,7 @@ func TranslateBizInfosToContainerStatuses(data []ark.ArkBizInfo, changeTimestamp
Key: GetBizIdentity(bizInfo.BizName, bizInfo.BizVersion),
Name: bizInfo.BizName,
// fille PodKey when using
//PodKey: vkModel.PodKeyAll,
// PodKey: vkModel.PodKeyAll,
State: bizInfo.BizState,
// TODO: 需要使用实际 bizState 变化的时间,而非心跳时间
ChangeTime: time.UnixMilli(changeTimestamp),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
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.9
github.com/koupleless/virtual-kubelet v0.3.10
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2
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.9 h1:7O+unpomhxiLvgF4R856p4YUVr10rtz27zhxRylgJuM=
github.com/koupleless/virtual-kubelet v0.3.9/go.mod h1:V/RjXRvoSNr55I9KMV+tgtOp6duxxBMcwyDTH04XiX0=
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/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
7 changes: 4 additions & 3 deletions module_tunnels/koupleless_http_tunnel/http_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/koupleless/module_controller/common/zaplogger"
"github.com/koupleless/module_controller/controller/module_deployment_controller"
utils2 "github.com/koupleless/virtual-kubelet/common/utils"
"net/http"
"sync"
"time"

"errors"

"github.com/koupleless/module_controller/common/zaplogger"
"github.com/koupleless/module_controller/controller/module_deployment_controller"
utils2 "github.com/koupleless/virtual-kubelet/common/utils"

"github.com/koupleless/arkctl/v1/service/ark"
"github.com/koupleless/module_controller/common/model"
"github.com/koupleless/module_controller/common/utils"
Expand Down