WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@BetaCat0
Copy link
Collaborator

@BetaCat0 BetaCat0 commented Sep 7, 2025

see koupleless/koupleless#423

Summary by CodeRabbit

  • New Features

    • Node status now includes a populated NodeState field (derived from reported master state), improving visibility of node lifecycle/status.
  • Chores

    • Improved startup logging: when no client ID is provided via environment variables, the app logs the generated client ID at info level to aid setup and troubleshooting.
    • Dependency bump for an underlying library (minor version).

@coderabbitai
Copy link

coderabbitai bot commented Sep 7, 2025

Walkthrough

Adds an env-var presence check after generating clientID and logs the generated clientID if the env var is absent; populates NodeState in health->node-status translation; bumps virtual-kubelet dependency; minor import reorder in an HTTP tunnel file.

Changes

Cohort / File(s) Summary
Module controller startup
cmd/module-controller/main.go
After generating a random clientID, calls os.LookupEnv for EnvKeyOfClientID and logs the generated ID with log.L.Infof when the env var is unset; no other control-flow changes.
Health → NodeStatus translation
common/utils/utils.go
ConvertHealthDataToNodeStatus now sets NodeState on vkModel.NodeStatusData using strings.ToUpper(data.MasterBizInfo.BizState); comments formatting tweak only elsewhere.
Dependency update
go.mod
Bumps github.com/koupleless/virtual-kubelet from v0.3.9 to v0.3.10.
Import reorder (cosmetic)
module_tunnels/koupleless_http_tunnel/http_tunnel.go
Reorganized import block (moved zaplogger, module_deployment_controller, utils2 positions); no logic changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Main as Module Controller (main)
  participant OS as Env Vars
  participant Log as Logger

  Main->>Main: Generate random clientID
  Main->>OS: os.LookupEnv(EnvKeyOfClientID)
  alt Env var missing
    Main->>Log: Infof("Using generated clientID: %s", clientID)
  else Env var present
    Note over Main: No extra log
  end
  Main->>Main: Continue initialization
Loading
sequenceDiagram
  autonumber
  participant Health as HealthData
  participant Utils as ConvertHealthDataToNodeStatus
  participant VK as vkModel.NodeStatusData

  Health->>Utils: pass health data
  Utils->>VK: populate fields including NodeState = ToUpper(MasterBizInfo.BizState)
  Utils->>VK: return NodeStatusData
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • lvjing2
  • lylingzhen

Poem

I twitch my whiskers at the start,
A random ID hops into my cart.
If no env hides its name from me,
I log it bright for all to see—
A little rabbit’s stamp of glee. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: http tunnel in cluster mode" references the http_tunnel component changed in the PR but does not accurately summarize the primary edits in the diff, which mainly add a clientID env-var log, populate NodeState in node status conversion, and bump a dependency; the http_tunnel file only shows import reordering. This makes the title only partially related to the actual main changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/module-controller/main.go (1)

276-278: Fix typo in user-facing error

“deteched” → “detected”.

-		return "", fmt.Errorf("multiple kubelet proxy services deteched in namespace %s, expected only one", namespace)
+		return "", fmt.Errorf("multiple kubelet proxy services detected in namespace %s, expected only one", namespace)
🧹 Nitpick comments (1)
cmd/module-controller/main.go (1)

88-91: Handle empty CLIENT_ID and make the log actionable; avoid eager UUID generation

Treat empty value as unset, generate UUID lazily, and guide operators to persist it.

-	clientID := utils.GetEnv(model.EnvKeyOfClientID, uuid.New().String())
-	if _, ok := os.LookupEnv(model.EnvKeyOfClientID); !ok {
-		log.L.Infof("Randomly generated client ID: %s", clientID)
-	}
+	var clientID string
+	if clientIDEnv, ok := os.LookupEnv(model.EnvKeyOfClientID); !ok || clientIDEnv == "" {
+		clientID = uuid.New().String()
+		log.L.Infof("%s not set; generated client ID: %s. Set %s to persist across restarts.", model.EnvKeyOfClientID, clientID, model.EnvKeyOfClientID)
+	} else {
+		clientID = clientIDEnv
+	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7695c5 and e5e3c9b.

📒 Files selected for processing (1)
  • cmd/module-controller/main.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/module-controller/main.go (1)
common/model/consts.go (1)
  • EnvKeyOfClientID (24-24)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: unit-test
  • GitHub Check: lint

@BetaCat0 BetaCat0 self-assigned this Sep 8, 2025
@BetaCat0 BetaCat0 marked this pull request as draft September 8, 2025 07:29
@BetaCat0
Copy link
Collaborator Author

BetaCat0 commented Sep 8, 2025

等待 koupleless/virtual-kubelet#46 通过后更新依赖

@BetaCat0 BetaCat0 force-pushed the fix/http-tunnel-cluster-mode branch from e5e3c9b to 5077d10 Compare September 8, 2025 08:12
@BetaCat0 BetaCat0 marked this pull request as ready for review September 22, 2025 05:52
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
common/utils/utils.go (2)

201-204: Bug: wrong error checked for NotFound after delete

Uses err (from Get) instead of deleteErr. This will misreport NotFound deletes as errors.

-        if deleteErr != nil && !apiErrors.IsNotFound(err) {
+        if deleteErr != nil && !apiErrors.IsNotFound(deleteErr) {
             logger.Error(deleteErr, "delete base node failed")
         }

216-220: Pass the actual parse error to logger

Error(nil, ...) drops the cause. Pass err.

-    if err != nil {
-        zaplogger.GetLogger().Error(nil, fmt.Sprintf("failed to parse port %s from node info", portStr))
+    if err != nil {
+        zaplogger.GetLogger().Error(err, fmt.Sprintf("failed to parse port %s from node info", portStr))
         port = 1238
     }
🧹 Nitpick comments (2)
common/utils/utils.go (2)

138-139: Fix typo and clarify intent for PodKey

Minor: “fille” → “fill”. If PodKey is intentionally deferred, keep it commented; otherwise set it explicitly.

-            // fille PodKey when using
+            // fill PodKey when used

197-197: Log context function name is misleading

The function is OnBaseUnreachable but the context tag says OnNodeNotReady.

-    logger := zaplogger.FromContext(ctx).WithValues("nodeName", nodeName, "func", "OnNodeNotReady")
+    logger := zaplogger.FromContext(ctx).WithValues("nodeName", nodeName, "func", "OnBaseUnreachable")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5e3c9b and 7ff1791.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • cmd/module-controller/main.go (1 hunks)
  • common/utils/utils.go (3 hunks)
  • go.mod (1 hunks)
  • module_tunnels/koupleless_http_tunnel/http_tunnel.go (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • go.mod
  • module_tunnels/koupleless_http_tunnel/http_tunnel.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/module-controller/main.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: unit-test
🔇 Additional comments (1)
common/utils/utils.go (1)

10-11: OK: zaplogger import

Import is used below (FromContext/GetLogger). No action needed.

Comment on lines 114 to 117
return vkModel.NodeStatusData{
Resources: resourceMap,
NodeState: vkModel.NodeState(strings.ToUpper(data.MasterBizInfo.BizState)),
}
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.

Copy link
Contributor

@lylingzhen lylingzhen left a comment

Choose a reason for hiding this comment

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

reviewed

@lylingzhen lylingzhen merged commit 54dbf46 into koupleless:main Sep 22, 2025
4 checks passed
@codecov
Copy link

codecov bot commented Sep 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.13%. Comparing base (405833a) to head (7ff1791).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #44      +/-   ##
==========================================
+ Coverage   67.11%   67.13%   +0.02%     
==========================================
  Files          12       12              
  Lines        1426     1427       +1     
==========================================
+ Hits          957      958       +1     
  Misses        403      403              
  Partials       66       66              
Files with missing lines Coverage Δ
common/utils/utils.go 92.25% <100.00%> (+0.05%) ⬆️
...dule_tunnels/koupleless_http_tunnel/http_tunnel.go 69.05% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BetaCat0 BetaCat0 deleted the fix/http-tunnel-cluster-mode branch September 22, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants