Skip to content

Commit e8bb124

Browse files
authored
Support for Pod workloads (#332)
Signed-off-by: ZIV NEVO <[email protected]>
1 parent 242a570 commit e8bb124

File tree

5 files changed

+2443
-1
lines changed

5 files changed

+2443
-1
lines changed

cmd/nettop/main_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ var (
6565
false,
6666
[]string{"onlineboutique", "expected_netpol_output.yaml"},
6767
},
68+
{
69+
"NetpolsFromPodsOnlineBoutiqueYAML",
70+
[][]string{{"onlineboutique-pods"}},
71+
yamlFormat,
72+
true,
73+
nil,
74+
false,
75+
[]string{"onlineboutique-pods", "expected_netpol_output.yaml"},
76+
},
6877
{
6978
"NetpolsMultiplePaths",
7079
[][]string{{"k8s_wordpress_example", "mysql-deployment.yaml"}, {"k8s_wordpress_example", "wordpress-deployment.yaml"}},

pkg/analyzer/info_to_resource.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ func k8sWorkloadObjectFromInfo(info *resource.Info) (*Resource, error) {
3030
var resourceCtx Resource
3131
var metaObj metaV1.Object
3232
resourceCtx.Resource.Kind = info.Object.GetObjectKind().GroupVersionKind().Kind
33-
switch resourceCtx.Resource.Kind { // TODO: handle Pod
33+
switch resourceCtx.Resource.Kind {
34+
case "Pod":
35+
obj := parseResourceFromInfo[v1.Pod](info)
36+
podSpecV1 = &v1.PodTemplateSpec{Spec: obj.Spec, ObjectMeta: obj.ObjectMeta}
37+
metaObj = obj
3438
case "ReplicaSet":
3539
obj := parseResourceFromInfo[appsv1.ReplicaSet](info)
3640
podSpecV1 = &obj.Spec.Template
@@ -162,6 +166,7 @@ func parseDeployResource(podSpec *v1.PodTemplateSpec, obj metaV1.Object, resourc
162166
resourceCtx.Resource.Name = obj.GetName()
163167
resourceCtx.Resource.Namespace = obj.GetNamespace()
164168
resourceCtx.Resource.Labels = podSpec.Labels
169+
delete(resourceCtx.Resource.Labels, "pod-template-hash") // auto-generated - better not use it in netpols
165170
resourceCtx.Resource.ServiceAccountName = podSpec.Spec.ServiceAccountName
166171
for containerIdx := range podSpec.Spec.Containers {
167172
container := &podSpec.Spec.Containers[containerIdx]

0 commit comments

Comments
 (0)