Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Added mapping for kubernetes pod resource (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
olagacek authored and rghetia committed Aug 6, 2019
1 parent 6850d2e commit 5e806e0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
22 changes: 13 additions & 9 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,22 @@ func defaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResourc
if res == nil || res.Labels == nil {
return result
}
if res.Type == resourcekeys.ContainerType {

switch {
case res.Type == resourcekeys.ContainerType:
result.Type = "k8s_container"
match = k8sResourceMap
} else if v, ok := res.Labels[resourcekeys.CloudKeyProvider]; ok {
if v == resourcekeys.CloudProviderGCP {
result.Type = "gce_instance"
match = gcpResourceMap
} else if v == resourcekeys.CloudProviderAWS {
result.Type = "aws_ec2_instance"
match = awsResourceMap
}
case res.Type == resourcekeys.K8SType:
result.Type = "k8s_pod"
match = k8sResourceMap
case res.Labels[resourcekeys.CloudKeyProvider] == resourcekeys.CloudProviderGCP:
result.Type = "gce_instance"
match = gcpResourceMap
case res.Labels[resourcekeys.CloudKeyProvider] == resourcekeys.CloudProviderAWS:
result.Type = "aws_ec2_instance"
match = awsResourceMap
}

result.Labels = transformResource(match, res.Labels)
if result.Type == "aws_ec2_instance" {
if v, ok := result.Labels["region"]; ok {
Expand Down
22 changes: 22 additions & 0 deletions resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ func TestDefaultMapResource(t *testing.T) {
},
},
},
{
input: &resource.Resource{
Type: resourcekeys.K8SType,
Labels: map[string]string{
stackdriverProjectID: "proj1",
resourcekeys.K8SKeyClusterName: "cluster1",
resourcekeys.K8SKeyPodName: "pod1",
resourcekeys.K8SKeyNamespaceName: "namespace1",
resourcekeys.CloudKeyZone: "zone1",
},
},
want: &monitoredrespb.MonitoredResource{
Type: "k8s_pod",
Labels: map[string]string{
"project_id": "proj1",
"location": "zone1",
"cluster_name": "cluster1",
"namespace_name": "namespace1",
"pod_name": "pod1",
},
},
},
{
input: &resource.Resource{
Type: resourcekeys.CloudType,
Expand Down

0 comments on commit 5e806e0

Please sign in to comment.