Skip to content

Commit

Permalink
Add AnthosL4LB resource map (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
courageJ authored Jul 23, 2020
1 parent ecaede8 commit adcf43c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions retrieval/resource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,23 @@ var ProxyV2ResourceMap = ResourceMap{
},
}

var AnthosL4LBMap = ResourceMap{
Type: "anthos_l4lb",
MatchLabel: "__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_type",
LabelMap: map[string]labelTranslation{
ProjectIDLabel: constValue("project_id"),
KubernetesLocationLabel: constValue("location"),
"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_kind": constValue("kind"),
"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_group_name": constValue("group_name"),
"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_hostname": constValue("hostname"),
},
}

type ResourceMapList []ResourceMap

// When you add new elements, you also probably want to update TestResourceMappingsOrder.
var ResourceMappings = ResourceMapList{
AnthosL4LBMap,
ProxyV2ResourceMap,
ProxyResourceMap,
DevappResourceMap,
Expand Down
41 changes: 41 additions & 0 deletions retrieval/resource_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,46 @@ func TestTranslateProxyV2(t *testing.T) {
}
}

func TestTranslateAnthosL4LB(t *testing.T) {
discoveredLabels := labels.Labels{
{ProjectIDLabel, "my-project"},
{KubernetesLocationLabel, "my-location"},
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_type", "true"},
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_kind", "my-kind"},
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_group_name", "my-group-name"},
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_hostname", "my-hostname"},
{"__meta_kubernetes_namespace", "my-namespace"},
{"__meta_kubernetes_node_name", "my-instance"},
{"__meta_kubernetes_pod_name", "my-pod"},
{"__meta_kubernetes_pod_container_name", "my-container"},
}
metricsLabels := labels.Labels{
{"label_name1", "label1"},
{"label_name2", "label2"},
}
expectedLabels := map[string]string{
"project_id": "my-project",
"location": "my-location",
"kind": "my-kind",
"group_name": "my-group-name",
"hostname": "my-hostname",
}
expectedFinalLabels := labels.Labels{
{"label_name1", "label1"},
{"label_name2", "label2"},
}
if labels, finalLabels := AnthosL4LBMap.Translate(discoveredLabels, metricsLabels); 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 (m *ResourceMapList) getByType(t string) (*ResourceMap, bool) {
for _, m := range *m {
if m.Type == t {
Expand Down Expand Up @@ -274,6 +314,7 @@ func TestResourceMappingsOrder(t *testing.T) {
{"k8s_pod", "k8s_node"},
{"k8s_node", "gce_instance"},
{"k8s_node", "aws_ec2_instance"},
{"anthos_l4lb", "k8s_container"},
{"apigee.googleapis.com/ProxyV2", "k8s_container"},
{"apigee.googleapis.com/Proxy", "k8s_container"},
{"apigee.googleapis.com/Devapp", "k8s_container"},
Expand Down

0 comments on commit adcf43c

Please sign in to comment.