Skip to content

Conversation

@Aiden2014
Copy link
Collaborator

@Aiden2014 Aiden2014 commented Sep 18, 2025

Summary by CodeRabbit

  • New Features

    • Added a business model version identifier to operation responses.
  • Improvements

    • Start/stop flows now carry and log the model version identifier for clearer diagnostics and safer lifecycle handling.
    • Install/uninstall requests now include and propagate the model version to reduce risk of stale operations.
  • Chores

    • Updated module dependencies to newer versions for improved stability.

@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Walkthrough

Adds a BizModelVersion field to BizOperationResponse and threads a podKey into StartBiz/StopBiz for HTTP and MQTT tunnels; MQTT now wraps install/uninstall payloads in Ark service request types and logs include bizModelVersion. go.mod dependency versions updated.

Changes

Cohort / File(s) Summary of Changes
Model: BizOperationResponse field added
common/model/model.go
Added public field BizModelVersion string (json tag: bizModelVersion) to BizOperationResponse.
HTTP Tunnel: propagate podKey
module_tunnels/koupleless_http_tunnel/http_tunnel.go
Updated StartBiz/StopBiz signatures to accept podKey; set bizModel.BizModelVersion = podKey; include bizModelVersion in logs and in BizOperationResponse.
MQTT Tunnel: propagate podKey + request wrappers
module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go
Updated StartBiz/StopBiz signatures to accept podKey; added BizModelVersion on ark.BizModel and set from podKey; Install/Uninstall now marshal ark_service.InstallBizRequest{ BizModel } / ark_service.UninstallBizRequest{ BizModel }; logging includes bizModelVersion; import adjustments.
Dependencies
go.mod
Bumped module requirements: github.com/koupleless/arkctlv0.2.5, k8s.io/virtual-kubeletv0.3.11.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Controller
  participant Tunnel as HTTP/MQTT Tunnel
  participant Ark as Ark Service

  Controller->>Tunnel: StartBiz(nodeName, podKey, container)
  Note right of Tunnel #dff0d8: Build BizModel with BizModelVersion = podKey
  alt MQTT Tunnel
    Tunnel->>Ark: InstallBiz(InstallBizRequest{ BizModel })
  else HTTP Tunnel
    Tunnel->>Ark: InstallBiz(BizModel)
  end
  Ark-->>Tunnel: BizOperationResponse (bizModelVersion)
  Tunnel-->>Controller: return success/error
Loading
sequenceDiagram
  autonumber
  actor Controller
  participant Tunnel as HTTP/MQTT Tunnel
  participant Ark as Ark Service

  Controller->>Tunnel: StopBiz(nodeName, podKey, container)
  Note right of Tunnel #f0f7ff: BizModelVersion = podKey
  alt MQTT Tunnel
    Tunnel->>Ark: UninstallBiz(UninstallBizRequest{ BizModel })
  else HTTP Tunnel
    Tunnel->>Ark: UninstallBiz(BizModel)
  end
  Ark-->>Tunnel: BizOperationResponse (bizModelVersion)
  Tunnel-->>Controller: return success/error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • update vk version #19 — Related dependency bump for github.com/koupleless/virtual-kubelet, likely connected to the same version updates in this PR.

Poem

In tunnels where podKeys softly play,
I tuck a version in each start and stay.
Install wrapped, uninstall too,
Logs hum the podKey through and through.
A rabbit cheers — pods know what to do. 🥕🐇

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 clearly and concisely describes the primary purpose of the changeset—addressing the issue where replacing a module’s pod causes the JVM-process module instance to be lost—without extraneous details or ambiguity, making it easy for reviewers to understand the main fix at a glance.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c205f57 and f7ef6db.

📒 Files selected for processing (1)
  • module_tunnels/koupleless_http_tunnel/http_tunnel.go (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
module_tunnels/koupleless_http_tunnel/http_tunnel.go (3)
common/zaplogger/logger.go (1)
  • FromContext (19-26)
common/model/model.go (1)
  • BizOperationResponse (33-39)
common/model/consts.go (2)
  • CommandInstallBiz (71-71)
  • CommandUnInstallBiz (73-73)
⏰ 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 (4)
module_tunnels/koupleless_http_tunnel/http_tunnel.go (4)

328-328: LGTM! Function signature correctly updated.

The podKey parameter is now properly named and utilized throughout the function body. The unnecessary leading newline flagged in the previous review has been addressed.


338-348: LGTM! BizModelVersion properly propagated.

The podKey is correctly assigned to BizModel.BizModelVersion and included in the logging context. The BizOperationResponse initialization properly includes all required fields including the new BizModelVersion, which aligns with the structure defined in common/model/model.go.


362-362: LGTM! Function signature correctly updated.

The podKey parameter is now properly named and utilized, consistent with the StartBiz function changes.


372-381: LGTM! BizModelVersion properly propagated in uninstall flow.

The implementation correctly mirrors the StartBiz changes, with podKey assigned to BizModel.BizModelVersion and included in logging context. The BizOperationResponse is properly initialized with CommandUnInstallBiz, supporting the PR objective to prevent old uninstall requests from affecting new module instances.


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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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: 1

Caution

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

⚠️ Outside diff range comments (1)
module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go (1)

305-364: Guard against stale MQTT operation responses.

Other MQTT callbacks drop messages older than 10s, but bizOperationResponseCallback does not. Add the same expiry check to prevent late uninstall/failed install responses from flipping state after a pod replacement.

Apply:

  err := json.Unmarshal(msg.Payload(), &data)
  if err != nil {
    zlogger.Error(err, "Error unmarshalling biz response")
    return
  }
+ // Drop stale operation responses (aligns with other MQTT handlers)
+ if utils.Expired(data.PublishTimestamp, 1000*10) {
+   return
+ }
🧹 Nitpick comments (5)
common/model/model.go (1)

34-38: Layering: common/model depends on module_tunnels/…/ark_service.

Common models importing an HTTP-tunnel subpackage is an inversion of dependency flow and risks cycles. Consider moving ArkResponse into a neutral package (e.g., common/arkproto or common/arkservice) and have both tunnels depend on that.

module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go (4)

18-19: Package boundary: importing ark_service from HTTP tunnel leaks transport-specific model into MQTT.

Move the request wrappers (InstallBizRequest/UninstallBizRequest) to a transport-neutral location (e.g., common/arkproto) so both tunnels depend “upwards,” not sideways.


434-444: Marshal error is ignored; handle and surface it.

If JSON marshal fails, the publish will send an empty payload silently. Log and return the error.

Apply:

-	installBizRequestBytes, _ := json.Marshal(ark_service.InstallBizRequest{
-		BizModel: bizModel,
-	})
+	req := ark_service.InstallBizRequest{BizModel: bizModel}
+	installBizRequestBytes, err := json.Marshal(req)
+	if err != nil {
+		zlogger.Error(err, "failed to marshal InstallBizRequest")
+		return err
+	}

446-456: Same marshal‑error handling for uninstall.

Apply:

-	unInstallBizRequestBytes, _ := json.Marshal(ark_service.UninstallBizRequest{
-		BizModel: bizModel,
-	})
+	req := ark_service.UninstallBizRequest{BizModel: bizModel}
+	unInstallBizRequestBytes, err := json.Marshal(req)
+	if err != nil {
+		zlogger.Error(err, "failed to marshal UninstallBizRequest")
+		return err
+	}

439-441: Note: json:",inline" on embedded request types has no effect with encoding/json.

The wrappers embed BizModel, which already flattens fields for JSON. The ,inline tag is a YAML concept and is ignored by encoding/json. Consider removing it in ark_service/model.go to avoid confusion.

Would you like me to open a small follow‑up PR to adjust the wrapper tags?

Also applies to: 449-451

📜 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 0eb5f70.

📒 Files selected for processing (3)
  • common/model/model.go (1 hunks)
  • module_tunnels/koupleless_http_tunnel/http_tunnel.go (4 hunks)
  • module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
common/model/model.go (1)
module_tunnels/koupleless_http_tunnel/ark_service/model.go (1)
  • ArkResponse (16-31)
module_tunnels/koupleless_http_tunnel/http_tunnel.go (3)
common/zaplogger/logger.go (1)
  • FromContext (19-26)
common/model/model.go (1)
  • BizOperationResponse (33-39)
common/model/consts.go (2)
  • CommandInstallBiz (71-71)
  • CommandUnInstallBiz (73-73)
module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go (5)
common/utils/utils.go (2)
  • TranslateCoreV1ContainerToBizModel (58-64)
  • FormatArkletCommandTopic (36-38)
common/zaplogger/logger.go (1)
  • FromContext (19-26)
module_tunnels/koupleless_http_tunnel/ark_service/model.go (2)
  • InstallBizRequest (6-8)
  • UninstallBizRequest (11-13)
common/model/consts.go (1)
  • CommandInstallBiz (71-71)
module_tunnels/koupleless_mqtt_tunnel/mqtt/mqtt.go (1)
  • Qos0 (19-19)
🔇 Additional comments (4)
module_tunnels/koupleless_http_tunnel/http_tunnel.go (4)

338-348: Correctly propagating podKey into BizModel and response.

Setting BizModel.BizModelVersion and echoing it in BizOperationResponse aligns controller state with pod identity.


362-362: API surface: StopBiz second arg renamed to podKey; consistent with StartBiz.


372-381: Stop path also propagates BizModelVersion; good.

Mirrors the start flow and keeps logs correlated.


327-327: API surface: StartBiz now clearly names the second arg podKey.

  • Signature is type-compatible with Tunnel.
  • grep results: only definitions found in
    • module_tunnels/koupleless_http_tunnel/http_tunnel.go (StartBiz/StopBiz)
    • module_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go (StartBiz/StopBiz; mqtt assigns bizModel.BizModelVersion = podKey)
  • No other callers found in this repo — verify all callers (including external callers/repos) pass a non-empty podKey.

Comment on lines +34 to +38
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
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.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2866e90 and c205f57.

📒 Files selected for processing (1)
  • module_tunnels/koupleless_http_tunnel/http_tunnel.go (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
module_tunnels/koupleless_http_tunnel/http_tunnel.go (2)
common/zaplogger/logger.go (1)
  • FromContext (19-26)
common/model/model.go (1)
  • BizOperationResponse (33-39)
🪛 GitHub Actions: golangci-lint
module_tunnels/koupleless_http_tunnel/http_tunnel.go

[error] 328-328: golangci-lint: unnecessary leading newline (whitespace) at 328:92. Command: golangci-lint run --new-from-patch=/tmp/tmp-2119-SOgD9aRL861G/pull.patch --new=false --new-from-rev= --new-from-merge-base=

🪛 GitHub Check: lint
module_tunnels/koupleless_http_tunnel/http_tunnel.go

[failure] 328-328:
unnecessary leading newline (whitespace)

⏰ 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 (2)
module_tunnels/koupleless_http_tunnel/http_tunnel.go (2)

339-349: LGTM! podKey correctly threaded through install flow.

The podKey parameter is properly assigned to bizModel.BizModelVersion and flows through to BizOperationResponse.BizModelVersion, enabling the controller to align module state with Kubernetes pod state and prevent stale uninstall requests from removing new modules.


363-393: LGTM! podKey correctly threaded through uninstall flow.

The podKey parameter is properly assigned to bizModel.BizModelVersion and flows through to BizOperationResponse.BizModelVersion, maintaining consistency with the install flow. This enables the controller to reject stale uninstall requests that target replaced pods.

Copy link
Collaborator

@BetaCat0 BetaCat0 left a comment

Choose a reason for hiding this comment

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

LGTM

@BetaCat0 BetaCat0 merged commit 279ed41 into koupleless:main Oct 11, 2025
4 of 5 checks passed
@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.13%. Comparing base (54dbf46) to head (f7ef6db).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   66.92%   67.13%   +0.20%     
==========================================
  Files          12       12              
  Lines        1427     1436       +9     
==========================================
+ Hits          955      964       +9     
  Misses        405      405              
  Partials       67       67              
Files with missing lines Coverage Δ
...dule_tunnels/koupleless_http_tunnel/http_tunnel.go 69.40% <100.00%> (+0.34%) ⬆️
...dule_tunnels/koupleless_mqtt_tunnel/mqtt_tunnel.go 67.14% <100.00%> (+0.57%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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