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

feat(instance): add label to distinguish servers from Cloud and Robot #764

Merged
merged 4 commits into from
Oct 29, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ metadata:
node.kubernetes.io/instance-type: cx22
topology.kubernetes.io/region: fsn1
topology.kubernetes.io/zone: fsn1-dc8
instance.hetzner.cloud/provided-by: cloud
name: node
spec:
podCIDR: 10.244.0.0/24
Expand Down
3 changes: 3 additions & 0 deletions docs/robot.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ The Node controller adds information about the server to the Node object. The va
- `topology.kubernetes.io/zone`
- Examples: `hel1-dc5` `fsn1-dc16`
- We use the lowercase variant of the location to match the Cloud Datacenters
- `instance.hetzner.cloud/provided-by`
- Examples: `robot` `cloud`
- We detect if the node is a Robot server or Cloud VM and set the label accordingly
- Provider ID
- We set the field `Node.spec.providerID` to identify the Robot server after the initial adoption.
- The format is `hrobot://$SERVER_NUMBER`, but we can also read from the deprecated format used by [syself/hetzner-cloud-controller-manager](https://github.com/syself/hetzner-cloud-controller-manager): `hcloud://bm-$SERVER_NUMBER`
Expand Down
10 changes: 10 additions & 0 deletions hcloud/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

const (
ProvidedBy = "instance.hetzner.cloud/provided-by"
jooola marked this conversation as resolved.
Show resolved Hide resolved
)

type instances struct {
client *hcloud.Client
robotClient robot.Client
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
6 changes: 6 additions & 0 deletions hcloud/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ func TestInstances_InstanceMetadata(t *testing.T) {
},
Zone: "Test DC",
Region: "Test Location",
AdditionalLabels: map[string]string{
"instance.hetzner.cloud/provided-by": "cloud",
},
}

if !reflect.DeepEqual(metadata, expectedMetadata) {
Expand Down Expand Up @@ -405,6 +408,9 @@ func TestInstances_InstanceMetadataRobotServer(t *testing.T) {
},
Zone: "nbg1-dc1",
Region: "nbg1",
AdditionalLabels: map[string]string{
"instance.hetzner.cloud/provided-by": "robot",
},
}

if !reflect.DeepEqual(metadata, expectedMetadata) {
Expand Down
13 changes: 7 additions & 6 deletions tests/e2e/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions tests/e2e/robot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading