Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Connection resource map #289

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions retrieval/resource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ var TargetV2ResourceMap = ResourceMap{
},
}

var ConnectionResourceMap = ResourceMap{
Type: "connectors.googleapis.com/Connection",
MatchLabel: "__meta_kubernetes_pod_label_type_connection",
LabelMap: map[string]labelTranslation{
ProjectIDLabel: constValue("resource_container"),
KubernetesLocationLabel: constValue("location"),
"connection": constValue("connection"),
},
}

var AnthosL4LBMap = ResourceMap{
Type: "anthos_l4lb",
MatchLabel: "__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_type",
Expand All @@ -164,6 +174,7 @@ type ResourceMapList []ResourceMap
// When you add new elements, you also probably want to update TestResourceMappingsOrder.
var ResourceMappings = ResourceMapList{
AnthosL4LBMap,
ConnectionResourceMap,
TargetV2ResourceMap,
ProxyV2ResourceMap,
ProxyResourceMap,
Expand Down
31 changes: 31 additions & 0 deletions retrieval/resource_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,36 @@ func TestTranslateProxyV2(t *testing.T) {
}
}

func TestTranslateConnection(t *testing.T) {
discoveredLabels := labels.Labels{
{"__meta_kubernetes_pod_label_type_connection", "true"},
{ProjectIDLabel, "my-project"},
{KubernetesLocationLabel, "us-central1-a"},
}
metricLabels := labels.Labels{
{"connection", "my-connection-name"},
{"extra_label", "my-label"},
}
expectedLabels := map[string]string{
"resource_container": "my-project",
"location": "us-central1-a",
"connection": "my-connection-name",
}
expectedFinalLabels := labels.Labels{
{"extra_label", "my-label"},
}
if labels, finalLabels := ConnectionResourceMap.Translate(discoveredLabels, metricLabels); labels == nil {
t.Errorf("Expected %v, actual nil", expectedLabels)
} else {
if diff := cmp.Diff(expectedLabels, labels); len(diff) > 0 {
t.Error(diff)
}
if diff := cmp.Diff(expectedFinalLabels, finalLabels); len(diff) > 0 {
t.Error(diff)
}
}
}

func TestTranslateAnthosL4LB(t *testing.T) {
discoveredLabels := labels.Labels{
{ProjectIDLabel, "my-project"},
Expand Down Expand Up @@ -357,6 +387,7 @@ func TestResourceMappingsOrder(t *testing.T) {
{"k8s_node", "gce_instance"},
{"k8s_node", "aws_ec2_instance"},
{"anthos_l4lb", "k8s_container"},
{"connectors.googleapis.com/Connection", "k8s_container"},
{"apigee.googleapis.com/TargetV2", "k8s_container"},
{"apigee.googleapis.com/ProxyV2", "k8s_container"},
{"apigee.googleapis.com/Proxy", "k8s_container"},
Expand Down