diff --git a/discovery/hetzner/hcloud.go b/discovery/hetzner/hcloud.go index 05471e4537..494321fd52 100644 --- a/discovery/hetzner/hcloud.go +++ b/discovery/hetzner/hcloud.go @@ -47,6 +47,7 @@ const ( hetznerLabelHcloudDiskGB = hetznerHcloudLabelPrefix + "disk_size_gb" hetznerLabelHcloudType = hetznerHcloudLabelPrefix + "server_type" hetznerLabelHcloudLabel = hetznerHcloudLabelPrefix + "label_" + hetznerLabelHcloudLabelPresent = hetznerHcloudLabelPrefix + "labelpresent_" ) // Discovery periodically performs Hetzner Cloud requests. It implements @@ -124,6 +125,9 @@ func (d *hcloudDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, er } } for labelKey, labelValue := range server.Labels { + presentLabel := model.LabelName(hetznerLabelHcloudLabelPresent + strutil.SanitizeLabelName(labelKey)) + labels[presentLabel] = model.LabelValue("true") + label := model.LabelName(hetznerLabelHcloudLabel + strutil.SanitizeLabelName(labelKey)) labels[label] = model.LabelValue(labelValue) } diff --git a/discovery/hetzner/hcloud_test.go b/discovery/hetzner/hcloud_test.go index b6b8300e8e..a4f19cfddd 100644 --- a/discovery/hetzner/hcloud_test.go +++ b/discovery/hetzner/hcloud_test.go @@ -77,6 +77,7 @@ func TestHCloudSDRefresh(t *testing.T) { "__meta_hetzner_hcloud_disk_size_gb": model.LabelValue("25"), "__meta_hetzner_hcloud_server_type": model.LabelValue("cx11"), "__meta_hetzner_hcloud_private_ipv4_mynet": model.LabelValue("10.0.0.2"), + "__meta_hetzner_hcloud_labelpresent_my_key": model.LabelValue("true"), "__meta_hetzner_hcloud_label_my_key": model.LabelValue("my-value"), }, { @@ -99,6 +100,10 @@ func TestHCloudSDRefresh(t *testing.T) { "__meta_hetzner_hcloud_memory_size_gb": model.LabelValue("1"), "__meta_hetzner_hcloud_disk_size_gb": model.LabelValue("50"), "__meta_hetzner_hcloud_server_type": model.LabelValue("cpx11"), + "__meta_hetzner_hcloud_labelpresent_key": model.LabelValue("true"), + "__meta_hetzner_hcloud_labelpresent_other_key": model.LabelValue("true"), + "__meta_hetzner_hcloud_label_key": model.LabelValue(""), + "__meta_hetzner_hcloud_label_other_key": model.LabelValue("value"), }, { "__address__": model.LabelValue("1.2.3.6:80"), diff --git a/discovery/hetzner/mock_test.go b/discovery/hetzner/mock_test.go index 6c374b4bc2..5936d52574 100644 --- a/discovery/hetzner/mock_test.go +++ b/discovery/hetzner/mock_test.go @@ -310,7 +310,10 @@ func (m *SDMock) HandleHcloudServers() { "delete": false, "rebuild": false }, - "labels": {}, + "labels": { + "key": "", + "other-key": "value" + }, "volumes": [], "load_balancers": [] }, diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index ac1368b0ce..23e226d2c3 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1211,6 +1211,7 @@ The labels below are only available for targets with `role` set to `hcloud`: * `__meta_hetzner_hcloud_disk_size_gb`: the disk size of the server (in GB) * `__meta_hetzner_hcloud_private_ipv4_`: the private ipv4 address of the server within a given network * `__meta_hetzner_hcloud_label_`: each label of the server +* `__meta_hetzner_hcloud_labelpresent_`: `true` for each label of the server The labels below are only available for targets with `role` set to `robot`: