Skip to content
Merged
Next Next commit
Add ability to associate metadata tags in k8s processor using pod UID…
… rather than just IP

Signed-off-by: Patryk Matyjasek <[email protected]>
  • Loading branch information
pmatyjasek-sumo committed Jan 28, 2021
commit 972560935b674a794ed4ce31b46aad4fc8ce99f3
31 changes: 17 additions & 14 deletions processor/k8sprocessor/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (

// fakeClient is used as a replacement for WatchClient in test cases.
type fakeClient struct {
Pods map[string]*kube.Pod
Rules kube.ExtractionRules
Filters kube.Filters
Informer cache.SharedInformer
StopCh chan struct{}
Pods map[string]*kube.Pod
Rules kube.ExtractionRules
Filters kube.Filters
Associations kube.Associations
Informer cache.SharedInformer
StopCh chan struct{}
}

func selectors() (labels.Selector, fields.Selector) {
Expand All @@ -40,22 +41,24 @@ func selectors() (labels.Selector, fields.Selector) {
}

// newFakeClient instantiates a new FakeClient object and satisfies the ClientProvider type
func newFakeClient(_ *zap.Logger, apiCfg k8sconfig.APIConfig, rules kube.ExtractionRules, filters kube.Filters, _ kube.APIClientsetProvider, _ kube.InformerProvider) (kube.Client, error) {
func newFakeClient(_ *zap.Logger, apiCfg k8sconfig.APIConfig, rules kube.ExtractionRules, filters kube.Filters, associations kube.Associations, _ kube.APIClientsetProvider, _ kube.InformerProvider) (kube.Client, error) {
cs := fake.NewSimpleClientset()

ls, fs := selectors()
return &fakeClient{
Pods: map[string]*kube.Pod{},
Rules: rules,
Filters: filters,
Informer: kube.NewFakeInformer(cs, "", ls, fs),
StopCh: make(chan struct{}),
Pods: map[string]*kube.Pod{},
Rules: rules,
Filters: filters,
Associations: associations,
Informer: kube.NewFakeInformer(cs, "", ls, fs),
StopCh: make(chan struct{}),
}, nil
}

// GetPodByIP looks up FakeClient.Pods map by the provided string.
func (f *fakeClient) GetPodByIP(ip string) (*kube.Pod, bool) {
p, ok := f.Pods[ip]
// GetPod looks up FakeClient.Pods map by the provided string,
// which might represent either IP address or Pod UID.
func (f *fakeClient) GetPod(identifier string) (*kube.Pod, bool) {
p, ok := f.Pods[identifier]
return p, ok
}

Expand Down
14 changes: 14 additions & 0 deletions processor/k8sprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Config struct {
// Filter section allows specifying filters to filter
// pods by labels, fields, namespaces, nodes, etc.
Filter FilterConfig `mapstructure:"filter"`

Association []PodAssociationConfig `mapstructure:"pod_association"`
}

// ExtractConfig section allows specifying extraction rules to extract
Expand Down Expand Up @@ -173,3 +175,15 @@ type FieldFilterConfig struct {
// equals, not-equals, exists, does-not-exist.
Op string `mapstructure:"op"`
}

// PodAssociationConfig allows specifying rules for associating resources
// with pod metadata
type PodAssociationConfig struct {
// From represents the source of the association.
// Allowed values are connection and label
From string `mapstructure:"from"`

// Name represents the name of the association.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the name of the association or the name of the pod's attribute that is used for association?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is name of association. For example pod_uid, k8s.pod.ip etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the answer below you wrote:

name (representing the extracted key name).

If "name" is extracted key name (which I think means the attribute name if I understand correctly) then what is "name of association"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my bad. You're right it is extracted key name.

// e.g. ip, pod_uid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the possible values? Is "ip" and "pod_uid" the only possible values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there are few more