Skip to content

Commit

Permalink
Revert "Breaking change for 8.0, namespace_annotations replaced by na…
Browse files Browse the repository at this point in the history
…mespace.annotations (#28230)"

This reverts commit 058c405.
  • Loading branch information
MichaelKatsoulis committed Nov 22, 2021
1 parent 1e762cc commit 2b2d507
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 49 deletions.
22 changes: 12 additions & 10 deletions x-pack/elastic-agent/pkg/composable/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,14 @@ func generatePodData(
return providerData{}
}

ckMeta := kubemetaMap.(common.MapStr).Clone()
if len(namespaceAnnotations) != 0 {
ckMeta.Put("namespace.annotations", namespaceAnnotations)
}
// k8sMapping includes only the metadata that fall under kubernetes.*
// and these are available as dynamic vars through the provider
k8sMapping := map[string]interface{}(ckMeta)
k8sMapping := map[string]interface{}(kubemetaMap.(common.MapStr).Clone())

if len(namespaceAnnotations) != 0 {
// TODO: convert it to namespace.annotations for 8.0
k8sMapping["namespace_annotations"] = namespaceAnnotations
}

// Pass annotations to all events so that it can be used in templating and by annotation builders.
annotations := common.MapStr{}
Expand Down Expand Up @@ -314,13 +315,14 @@ func generateContainerData(
continue
}

ckMeta := kubemetaMap.(common.MapStr).Clone()
if len(namespaceAnnotations) != 0 {
ckMeta.Put("namespace.annotations", namespaceAnnotations)
}
// k8sMapping includes only the metadata that fall under kubernetes.*
// and these are available as dynamic vars through the provider
k8sMapping := map[string]interface{}(ckMeta)
k8sMapping := map[string]interface{}(kubemetaMap.(common.MapStr).Clone())

if len(namespaceAnnotations) != 0 {
// TODO: convert it to namespace.annotations for 8.0
k8sMapping["namespace_annotations"] = namespaceAnnotations
}

// add annotations to be discoverable by templates
k8sMapping["annotations"] = annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ func TestGeneratePodData(t *testing.T) {
data := generatePodData(pod, &Config{}, &podMeta{}, namespaceAnnotations)

mapping := map[string]interface{}{
"namespace": common.MapStr{
"name": pod.GetNamespace(),
"annotations": common.MapStr{
"nsa": "nsb",
},
},
"namespace": pod.GetNamespace(),
"pod": common.MapStr{
"uid": string(pod.GetUID()),
"name": pod.GetName(),
"ip": pod.Status.PodIP,
},
"namespace_annotations": common.MapStr{
"nsa": "nsb",
},
"labels": common.MapStr{
"foo": "bar",
},
Expand All @@ -75,9 +73,7 @@ func TestGeneratePodData(t *testing.T) {
"name": "devcluster",
"url": "8.8.8.8:9090"},
}, "kubernetes": common.MapStr{
"namespace": common.MapStr{
"name": "testns",
},
"namespace": "testns",
"labels": common.MapStr{
"foo": "bar",
},
Expand Down Expand Up @@ -161,12 +157,7 @@ func TestGenerateContainerPodData(t *testing.T) {
})

mapping := map[string]interface{}{
"namespace": common.MapStr{
"name": pod.GetNamespace(),
"annotations": common.MapStr{
"nsa": "nsb",
},
},
"namespace": pod.GetNamespace(),
"pod": common.MapStr{
"uid": string(pod.GetUID()),
"name": pod.GetName(),
Expand All @@ -180,6 +171,9 @@ func TestGenerateContainerPodData(t *testing.T) {
"port": "80",
"port_name": "http",
},
"namespace_annotations": common.MapStr{
"nsa": "nsb",
},
"annotations": common.MapStr{
"app": "production",
},
Expand All @@ -198,9 +192,7 @@ func TestGenerateContainerPodData(t *testing.T) {
"name": "devcluster",
"url": "8.8.8.8:9090"},
}, "kubernetes": common.MapStr{
"namespace": common.MapStr{
"name": "testns",
},
"namespace": "testns",
"annotations": common.MapStr{"app": "production"},
"labels": common.MapStr{"foo": "bar"},
"pod": common.MapStr{
Expand Down Expand Up @@ -280,12 +272,7 @@ func TestEphemeralContainers(t *testing.T) {
})

mapping := map[string]interface{}{
"namespace": common.MapStr{
"name": pod.GetNamespace(),
"annotations": common.MapStr{
"nsa": "nsb",
},
},
"namespace": pod.GetNamespace(),
"pod": common.MapStr{
"uid": string(pod.GetUID()),
"name": pod.GetName(),
Expand All @@ -300,6 +287,9 @@ func TestEphemeralContainers(t *testing.T) {
"image": "nginx:1.120",
"runtime": "crio",
},
"namespace_annotations": common.MapStr{
"nsa": "nsb",
},
"annotations": common.MapStr{
"app": "production",
},
Expand All @@ -315,9 +305,7 @@ func TestEphemeralContainers(t *testing.T) {
"name": "devcluster",
"url": "8.8.8.8:9090"},
}, "kubernetes": common.MapStr{
"namespace": common.MapStr{
"name": "testns",
},
"namespace": "testns",
"labels": common.MapStr{"foo": "bar"},
"annotations": common.MapStr{"app": "production"},
"pod": common.MapStr{
Expand Down Expand Up @@ -393,9 +381,7 @@ func (p *podMeta) GenerateECS(obj kubernetes.Resource) common.MapStr {
func (p *podMeta) GenerateK8s(obj kubernetes.Resource, opts ...metadata.FieldOptions) common.MapStr {
k8sPod := obj.(*kubernetes.Pod)
return common.MapStr{
"namespace": common.MapStr{
"name": k8sPod.GetNamespace(),
},
"namespace": k8sPod.GetNamespace(),
"pod": common.MapStr{
"uid": string(k8sPod.GetUID()),
"name": k8sPod.GetName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,14 @@ func generateServiceData(
return &serviceData{}
}

ckMeta := kubemetaMap.(common.MapStr).Clone()
if len(namespaceAnnotations) != 0 {
ckMeta.Put("namespace.annotations", namespaceAnnotations)
}
// k8sMapping includes only the metadata that fall under kubernetes.*
// and these are available as dynamic vars through the provider
k8sMapping := map[string]interface{}(ckMeta)
k8sMapping := map[string]interface{}(kubemetaMap.(common.MapStr).Clone())

if len(namespaceAnnotations) != 0 {
// TODO: convert it to namespace.annotations for 8.0
k8sMapping["namespace_annotations"] = namespaceAnnotations
}

// Pass annotations to all events so that it can be used in templating and by annotation builders.
annotations := common.MapStr{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ func TestGenerateServiceData(t *testing.T) {
"name": service.GetName(),
"ip": service.Spec.ClusterIP,
},
"namespace": common.MapStr{
"annotations": common.MapStr{
"nsa": "nsb",
},
"namespace_annotations": common.MapStr{
"nsa": "nsb",
},
"annotations": common.MapStr{
"baz": "ban",
Expand Down

0 comments on commit 2b2d507

Please sign in to comment.