Skip to content

Commit 7b0c22d

Browse files
feat: add Job workload type support for pod targeting (#794)
This commit adds support for targeting pods owned by Kubernetes Jobs in chaos experiments by updating the GetPodOwnerTypeAndName function to recognize Job as a valid owner. Fixes litmuschaos/litmus#5000 Signed-off-by: Avnish Jaltare <avnishjaltare8@gmail.com> Co-authored-by: Shubham Chaudhary <shubham.chaudhary@harness.io>
1 parent 8933362 commit 7b0c22d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/workloads/workloads.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func GetPodOwnerTypeAndName(pod *kcorev1.Pod, dynamicClient dynamic.Interface) (
7474
for _, owner := range pod.GetOwnerReferences() {
7575
parentName = owner.Name
7676
parentType = strings.ToLower(owner.Kind)
77-
if owner.Kind == "StatefulSet" || owner.Kind == "DaemonSet" {
77+
if owner.Kind == "StatefulSet" || owner.Kind == "DaemonSet" || owner.Kind == "Job" {
7878
return strings.ToLower(owner.Kind), parentName, nil
7979
}
8080

pkg/workloads/workloads_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ func Test_GetPodOwnerTypeAndName(t *testing.T) {
249249
expectErr: false,
250250
dynamicClient: nil,
251251
},
252+
{
253+
name: "Job owner",
254+
pod: &corev1.Pod{
255+
ObjectMeta: metav1.ObjectMeta{
256+
Name: "pod-job",
257+
Namespace: "default",
258+
OwnerReferences: []metav1.OwnerReference{
259+
{Kind: "Job", Name: "my-job"},
260+
},
261+
},
262+
},
263+
expectedKind: "job",
264+
expectedName: "my-job",
265+
expectErr: false,
266+
dynamicClient: nil,
267+
},
252268
{
253269
name: "ReplicaSet with pod-template-hash match",
254270
pod: &corev1.Pod{

0 commit comments

Comments
 (0)