I have been trying to create a pod-network-partition experiment by following the steps mentioned in https://litmuschaos.github.io/litmus/experiments/categories/pods/pod-network-partition/ and by working on the template present in chaoshub.
There are a couple of issues that I have been facing. I have been going through the codebase and found that:
- The experiment itself creates a NetworkPolicy targeting the pods using POD_SELECTOR and NAMESPACE_SELECTOR environment variables
- But the experiment cannot be run without TARGETS environment variable. Without it, the experiment receives the following error:
time="2025-06-11T07:40:56Z" level=info msg="[PreReq]: Getting the ENV for the pod-network-partition experiment"
panic: runtime error: index out of range [0] with length 0
This is due to
|
return app[0].Namespace, app[0].Kind, app[0].Labels[0] |
and
|
experimentDetails.AppNS, experimentDetails.AppKind, experimentDetails.AppLabel = getAppDetails() |
. These three variables are already being picked up separately at
https://github.com/litmuschaos/litmus-go/blob/07de11eeee8e919b930e738f316a1e490aba3b18/pkg/generic/pod-network-partition/environment/environment.go#L19C2-L21C58 , so one of these is redundant.
- Even after setting the TARGETS variable as per format:
kind:namespace:labelKey=labelValue this fails (Note that format kind:namespace:pod1Name,pod2Name also fails since this causes the AppDetails.Labels field to be null which throws nil pointer exception in getAppDetails function execution) chaos fails to get injected as it is unable to determine the target pods even if all the correct details are provided.
- This is due to the fact that in https://github.com/litmuschaos/litmus-go/blob/07de11eeee8e919b930e738f316a1e490aba3b18/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go#L57C5-L57C14 , empty string as target pods is being passed into GetPodList (probably due to the fact that in this experiment chaos is not directly injected into the pods but a networkpolicy is created to implement the effect) which eventually results in execution of
|
podList, err := GetTargetPodsWhenTargetPodsENVNotSet(podAffPerc, clients, chaosDetails) |
calling GetTargetPodsWhenTargetPodsENVNotSet function.
- In GetTargetPodsWhenTargetPodsENVNotSet(), if we have set the kind to
pod, the first switch case is executed at
and since we have passed only labels for AppDetails and not pod names, we receive error ErrorTypeTargetSelection
I am happy to submit a PR for this fix.
I have been trying to create a pod-network-partition experiment by following the steps mentioned in https://litmuschaos.github.io/litmus/experiments/categories/pods/pod-network-partition/ and by working on the template present in chaoshub.
There are a couple of issues that I have been facing. I have been going through the codebase and found that:
This is due to
litmus-go/pkg/generic/pod-network-partition/environment/environment.go
Line 43 in 07de11e
litmus-go/pkg/generic/pod-network-partition/environment/environment.go
Line 36 in 07de11e
kind:namespace:labelKey=labelValuethis fails (Note that formatkind:namespace:pod1Name,pod2Namealso fails since this causes the AppDetails.Labels field to be null which throws nil pointer exception in getAppDetails function execution) chaos fails to get injected as it is unable to determine the target pods even if all the correct details are provided.litmus-go/pkg/utils/common/pods.go
Line 168 in 07de11e
pod, the first switch case is executed atlitmus-go/pkg/utils/common/pods.go
Line 276 in 07de11e
ErrorTypeTargetSelectionI am happy to submit a PR for this fix.