-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix getPodWorkloadObject to work with more workloads names which cont…
…ains hyphens (#1314) …ains hyphens --------- Co-authored-by: Eden Federman <eden@keyval.dev>
- Loading branch information
Showing
5 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package instrumentation_ebpf | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/odigos-io/odigos/common" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestGetPodWorkloadObject(t *testing.T) { | ||
pr := &PodsReconciler{} | ||
cases := []struct{ | ||
name string | ||
pod *corev1.Pod | ||
expectedWorkload common.PodWorkload | ||
}{ | ||
{ | ||
name: "pod in deployment", | ||
pod: &corev1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta { | ||
OwnerReferences: []metav1.OwnerReference{ | ||
{ | ||
Kind: "ReplicaSet", | ||
Name: "deployment-1234", | ||
}, | ||
}, | ||
Namespace: "default", | ||
}, | ||
}, | ||
expectedWorkload: common.PodWorkload{ | ||
Kind: "Deployment", | ||
Name: "deployment", | ||
Namespace: "default", | ||
}, | ||
}, | ||
{ | ||
name: "pod with hyphen in name of deployment", | ||
pod: &corev1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta { | ||
OwnerReferences: []metav1.OwnerReference{ | ||
{ | ||
Kind: "ReplicaSet", | ||
Name: "deployment-foo-5678", | ||
}, | ||
}, | ||
Namespace: "default", | ||
}, | ||
}, | ||
expectedWorkload: common.PodWorkload{ | ||
Kind: "Deployment", | ||
Name: "deployment-foo", | ||
Namespace: "default", | ||
}, | ||
}, | ||
{ | ||
name: "pod in DaemonSet", | ||
pod: &corev1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta { | ||
OwnerReferences: []metav1.OwnerReference{ | ||
{ | ||
Kind: "DaemonSet", | ||
Name: "someDaemonSet", | ||
}, | ||
}, | ||
Namespace: "default", | ||
}, | ||
}, | ||
expectedWorkload: common.PodWorkload{ | ||
Kind: "DaemonSet", | ||
Name: "someDaemonSet", | ||
Namespace: "default", | ||
}, | ||
}, | ||
{ | ||
name: "pod in StatefulSet", | ||
pod: &corev1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta { | ||
OwnerReferences: []metav1.OwnerReference{ | ||
{ | ||
Kind: "StatefulSet", | ||
Name: "someStatefulSet", | ||
}, | ||
}, | ||
Namespace: "default", | ||
}, | ||
}, | ||
expectedWorkload: common.PodWorkload{ | ||
Kind: "StatefulSet", | ||
Name: "someStatefulSet", | ||
Namespace: "default", | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
workload, err := pr.getPodWorkloadObject(context.Background(), c.pod) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if workload.Kind != c.expectedWorkload.Kind { | ||
t.Errorf("expected kind %s, got %s", c.expectedWorkload.Kind, workload.Kind) | ||
} | ||
if workload.Name != c.expectedWorkload.Name { | ||
t.Errorf("expected name %s, got %s", c.expectedWorkload.Name, workload.Name) | ||
} | ||
if workload.Namespace != c.expectedWorkload.Namespace { | ||
t.Errorf("expected namespace %s, got %s", c.expectedWorkload.Namespace, workload.Namespace) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build !linux | ||
|
||
package process | ||
|
||
import procdiscovery "github.com/odigos-io/odigos/procdiscovery/pkg/process" | ||
|
||
// These functions are stubs for non-linux platforms to allow running tests on them. | ||
|
||
func isPodContainerPredicate(_ string, _ string) func(string) bool { | ||
return func(procDirName string) bool { | ||
return false | ||
} | ||
} | ||
|
||
func FindAllInContainer(podUID string, containerName string) ([]procdiscovery.Details, error) { | ||
return nil, nil | ||
} |