Skip to content
Open
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
24 changes: 23 additions & 1 deletion exec/model/osexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/chaosblade-io/chaosblade-exec-os/exec/file"
"github.com/chaosblade-io/chaosblade-exec-os/exec/mem"
"github.com/chaosblade-io/chaosblade-exec-os/exec/network"
"github.com/chaosblade-io/chaosblade-exec-os/exec/network/tc"
"github.com/chaosblade-io/chaosblade-exec-os/exec/process"
"github.com/chaosblade-io/chaosblade-exec-os/exec/script"
"github.com/chaosblade-io/chaosblade-spec-go/spec"
Expand All @@ -31,12 +32,33 @@ type OSSubResourceModelSpec struct {
BaseSubResourceExpModelSpec
}

// newK8sNetworkCommandSpec returns all Linux-compatible network actions
// regardless of the build platform, since k8s pods always run on Linux.
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The comment says “k8s pods always run on Linux”, but this helper is also used for node/container specs and the repo’s stated constraint is broader/clearer: build docs list the target platforms as Linux (amd64/arm64). Consider rewording the comment to reflect the project’s Linux-target assumption (per BUILD.md) rather than a universal Kubernetes property.

Suggested change
// regardless of the build platform, since k8s pods always run on Linux.
// based on the project's Linux (amd64/arm64) target platforms, independent
// of the local build platform.

Copilot uses AI. Check for mistakes.
func newK8sNetworkCommandSpec() spec.ExpModelCommandSpec {
return &network.NetworkCommandSpec{
BaseExpModelCommandSpec: spec.BaseExpModelCommandSpec{
ExpActions: []spec.ExpActionCommandSpec{
tc.NewDelayActionSpec(),
network.NewDropActionSpec(),
network.NewDnsActionSpec(),
network.NewDnsDownActionSpec(),
tc.NewLossActionSpec(),
tc.NewDuplicateActionSpec(),
tc.NewCorruptActionSpec(),
tc.NewReorderActionSpec(),
network.NewOccupyActionSpec(),
},
ExpFlags: []spec.ExpFlagSpec{},
Comment on lines +35 to +51
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

This hard-codes the full list of network actions. That fixes the cross-build issue, but it also means future additions/removals in chaosblade-exec-os (e.g., new Linux network actions) won’t automatically show up in the k8s spec. To reduce drift risk, consider centralizing the action list (single source of truth) or adding an explicit assertion/test that enumerates the expected actions so updates fail loudly.

Suggested change
// newK8sNetworkCommandSpec returns all Linux-compatible network actions
// regardless of the build platform, since k8s pods always run on Linux.
func newK8sNetworkCommandSpec() spec.ExpModelCommandSpec {
return &network.NetworkCommandSpec{
BaseExpModelCommandSpec: spec.BaseExpModelCommandSpec{
ExpActions: []spec.ExpActionCommandSpec{
tc.NewDelayActionSpec(),
network.NewDropActionSpec(),
network.NewDnsActionSpec(),
network.NewDnsDownActionSpec(),
tc.NewLossActionSpec(),
tc.NewDuplicateActionSpec(),
tc.NewCorruptActionSpec(),
tc.NewReorderActionSpec(),
network.NewOccupyActionSpec(),
},
ExpFlags: []spec.ExpFlagSpec{},
// k8sNetworkActions defines the full set of network actions that are exposed
// via the k8s OS subresource, independent of the current build platform.
// This list is centralized here to reduce the risk of it silently drifting
// from the underlying chaosblade-exec-os network actions.
var k8sNetworkActions = []spec.ExpActionCommandSpec{
tc.NewDelayActionSpec(),
network.NewDropActionSpec(),
network.NewDnsActionSpec(),
network.NewDnsDownActionSpec(),
tc.NewLossActionSpec(),
tc.NewDuplicateActionSpec(),
tc.NewCorruptActionSpec(),
tc.NewReorderActionSpec(),
network.NewOccupyActionSpec(),
}
// K8sNetworkActionSpecs returns a copy of the k8s network action specs.
// It can be used by tests to assert that the k8s-exposed actions stay
// in sync with the expected set of network actions.
func K8sNetworkActionSpecs() []spec.ExpActionCommandSpec {
out := make([]spec.ExpActionCommandSpec, len(k8sNetworkActions))
copy(out, k8sNetworkActions)
return out
}
// newK8sNetworkCommandSpec returns all Linux-compatible network actions
// regardless of the build platform, since k8s pods always run on Linux.
func newK8sNetworkCommandSpec() spec.ExpModelCommandSpec {
return &network.NetworkCommandSpec{
BaseExpModelCommandSpec: spec.BaseExpModelCommandSpec{
ExpActions: k8sNetworkActions,
ExpFlags: []spec.ExpFlagSpec{},

Copilot uses AI. Check for mistakes.
},
}
}
Comment on lines +35 to +54
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

This change is meant to guarantee that the generated k8s spec always includes the tc-based actions even when the spec generator is built on macOS. There’s currently no automated test covering the resulting action set; adding a small unit test (e.g., asserting NewOSSubResourceModelSpec() includes delay/loss/duplicate/corrupt/reorder/dnsdown) would prevent regressions and catch future dependency changes.

Copilot uses AI. Check for mistakes.

func NewOSSubResourceModelSpec() SubResourceExpModelSpec {
modelSpec := &OSSubResourceModelSpec{
BaseSubResourceExpModelSpec{
ExpModelSpecs: []spec.ExpModelCommandSpec{
cpu.NewCpuCommandModelSpec(),
network.NewNetworkCommandSpec(),
newK8sNetworkCommandSpec(),
process.NewProcessCommandModelSpec(),
Comment on lines 56 to 62
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

newK8sNetworkCommandSpec is used by NewOSSubResourceModelSpec() (shared by node/pod/container), so the name is misleading (it’s not pod-only and not purely “k8s network” as a standalone spec). Consider renaming it to reflect that this is the operator’s Linux-targeted network spec used across k8s resources (e.g., newLinuxNetworkCommandSpecForK8sResources).

Copilot uses AI. Check for mistakes.
disk.NewDiskCommandSpec(),
mem.NewMemCommandModelSpec(),
Expand Down
Loading