Skip to content

Commit

Permalink
adding metadata pod
Browse files Browse the repository at this point in the history
  • Loading branch information
gizas committed Nov 28, 2023
1 parent fe5e376 commit 30f46c6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion kubernetes/metadata/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package metadata

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8s "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"

Expand Down Expand Up @@ -84,9 +86,12 @@ func (p *pod) GenerateECS(obj kubernetes.Resource) mapstr.M {

// GenerateK8s generates pod metadata from a resource object
func (p *pod) GenerateK8s(obj kubernetes.Resource, opts ...FieldOptions) mapstr.M {
po, ok := obj.(*kubernetes.Pod)
var po *v1.Pod
originalPod, ok := obj.(*kubernetes.Pod)
if !ok {
return nil
} else {
po = removeUnnecessaryPodData(originalPod)
}

out := p.resource.GenerateK8s("pod", obj, opts...)
Expand Down Expand Up @@ -156,3 +161,15 @@ func (p *pod) GenerateFromName(name string, opts ...FieldOptions) mapstr.M {

return nil
}

func removeUnnecessaryPodData(pod *v1.Pod) *v1.Pod {
transformernode := &v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: pod.Kind,
APIVersion: pod.APIVersion,
},
ObjectMeta: pod.ObjectMeta,
}

return transformernode
}

0 comments on commit 30f46c6

Please sign in to comment.