Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Distinguish server type via automatic label
Browse files Browse the repository at this point in the history
lukasmetzner committed Oct 22, 2024

Verified

This commit was signed with the committer’s verified signature.
CristhianF7 Cristhian Fernández
1 parent 6b132c1 commit 7f20edf
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 10 additions & 0 deletions hcloud/instances.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,10 @@ import (
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

const (
ProvidedBy = "instance.hetzner.cloud/provided-by"
)

type instances struct {
client *hcloud.Client
robotClient robot.Client
@@ -273,6 +277,9 @@ func (s hcloudServer) Metadata(addressFamily config.AddressFamily, networkID int
NodeAddresses: hcloudNodeAddresses(addressFamily, networkID, s.Server),
Zone: s.Datacenter.Name,
Region: s.Datacenter.Location.Name,
AdditionalLabels: map[string]string{
ProvidedBy: "cloud",
},
}, nil
}

@@ -299,5 +306,8 @@ func (s robotServer) Metadata(addressFamily config.AddressFamily, _ int64) (*clo
NodeAddresses: robotNodeAddresses(addressFamily, s.Server),
Zone: getZoneOfRobotServer(s.Server),
Region: getRegionOfRobotServer(s.Server),
AdditionalLabels: map[string]string{
ProvidedBy: "robot",
},
}, nil
}
13 changes: 7 additions & 6 deletions tests/e2e/cloud_test.go
Original file line number Diff line number Diff line change
@@ -35,12 +35,13 @@ func TestNodeSetCorrectNodeLabelsAndIPAddresses(t *testing.T) {

labels := node.Labels
expectedLabels := map[string]string{
"node.kubernetes.io/instance-type": server.ServerType.Name,
"topology.kubernetes.io/region": server.Datacenter.Location.Name,
"topology.kubernetes.io/zone": server.Datacenter.Name,
"kubernetes.io/hostname": server.Name,
"kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
"node.kubernetes.io/instance-type": server.ServerType.Name,
"topology.kubernetes.io/region": server.Datacenter.Location.Name,
"topology.kubernetes.io/zone": server.Datacenter.Name,
"kubernetes.io/hostname": server.Name,
"kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
"instance.hetzner.cloud/provided-by": "cloud",
}
for expectedLabel, expectedValue := range expectedLabels {
if labelValue, ok := labels[expectedLabel]; !ok || labelValue != expectedValue {
7 changes: 4 additions & 3 deletions tests/e2e/robot_test.go
Original file line number Diff line number Diff line change
@@ -41,9 +41,10 @@ func TestNodeSetCorrectNodeLabelsAndIPAddressesRobot(t *testing.T) {

labels := node.Labels
expectedLabels := map[string]string{
"kubernetes.io/hostname": server.Name,
"kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
"kubernetes.io/hostname": server.Name,
"kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
"instance.hetzner.cloud/provided-by": "robot",
}
for expectedLabel, expectedValue := range expectedLabels {
assert.Equal(t, expectedValue, labels[expectedLabel], "node does not have expected label %s", expectedLabel)

0 comments on commit 7f20edf

Please sign in to comment.