Browse Source

hcloud discovery: Add new labelpresent label (#9028)

* Add new labelpresent label

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
pull/9049/head
Lukas Kämmerling 3 years ago committed by GitHub
parent
commit
263847e64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      discovery/hetzner/hcloud.go
  2. 5
      discovery/hetzner/hcloud_test.go
  3. 5
      discovery/hetzner/mock_test.go
  4. 1
      docs/configuration/configuration.md

4
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)
}

5
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"),

5
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": []
},

1
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_<networkname>`: the private ipv4 address of the server within a given network
* `__meta_hetzner_hcloud_label_<labelname>`: each label of the server
* `__meta_hetzner_hcloud_labelpresent_<labelname>`: `true` for each label of the server
The labels below are only available for targets with `role` set to `robot`:

Loading…
Cancel
Save