Skip to content

Commit fa8a8cf

Browse files
committed
feat(node): disable zone label for cloud servers
1 parent 27253f5 commit fa8a8cf

4 files changed

Lines changed: 101 additions & 102 deletions

File tree

hcloud/cloud_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func newTestEnv() testEnv {
7474

7575
cfg := config.HCCMConfiguration{}
7676
cfg.Instance.AddressFamily = config.AddressFamilyIPv4
77+
cfg.Instance.ZoneLabelEnabled = true
7778

7879
return testEnv{
7980
Server: server,

hcloud/instances.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,23 @@ func (s hcloudServer) IsShutdown() (bool, error) {
356356
}
357357

358358
func (s hcloudServer) Metadata(networkID int64, _ *corev1.Node, cfg config.HCCMConfiguration) (*cloudprovider.InstanceMetadata, error) {
359-
return &cloudprovider.InstanceMetadata{
359+
metadata := &cloudprovider.InstanceMetadata{
360360
ProviderID: providerid.FromCloudServerID(s.ID),
361361
InstanceType: s.ServerType.Name,
362362
NodeAddresses: hcloudNodeAddresses(networkID, s.Server, cfg),
363-
Zone: legacydatacenter.NameFromLocation(s.Location.Name),
364363
Region: s.Location.Name,
365364
AdditionalLabels: map[string]string{
366365
ProvidedBy: "cloud",
367366
},
368-
}, nil
367+
}
368+
369+
// By default, we continue to configure a zone label. The user
370+
// can configure this behavior. We can drop this entirely in a v2.
371+
if cfg.Instance.ZoneLabelEnabled {
372+
metadata.Zone = legacydatacenter.NameFromLocation(s.Location.Name)
373+
}
374+
375+
return metadata, nil
369376
}
370377

371378
type robotServer struct {

internal/config/config.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ const (
2929
robotRateLimitWaitTime = "ROBOT_RATE_LIMIT_WAIT_TIME"
3030
robotForwardInternalIPs = "ROBOT_FORWARD_INTERNAL_IPS"
3131

32-
hcloudInstancesAddressFamily = "HCLOUD_INSTANCES_ADDRESS_FAMILY"
33-
hcloudServerCacheMode = "HCLOUD_SERVER_CACHE_MODE"
34-
hcloudServerCacheMaxAge = "HCLOUD_SERVER_CACHE_MAX_AGE"
32+
hcloudInstancesZoneLabelEnabled = "HCLOUD_INSTANCES_ZONE_LABEL_ENABLED"
33+
hcloudInstancesAddressFamily = "HCLOUD_INSTANCES_ADDRESS_FAMILY"
34+
hcloudServerCacheMode = "HCLOUD_SERVER_CACHE_MODE"
35+
hcloudServerCacheMaxAge = "HCLOUD_SERVER_CACHE_MAX_AGE"
3536

3637
// Disable the "master/server is attached to the network" check against the metadata service.
3738
hcloudNetworkDisableAttachedCheck = "HCLOUD_NETWORK_DISABLE_ATTACHED_CHECK"
@@ -73,7 +74,8 @@ const (
7374
const ServerCacheDefaultMaxAge time.Duration = 10 * time.Second
7475

7576
type InstanceConfiguration struct {
76-
AddressFamily AddressFamily
77+
AddressFamily AddressFamily
78+
ZoneLabelEnabled bool
7779
}
7880

7981
type ServerCacheConfiguration struct {
@@ -185,6 +187,11 @@ func Read() (HCCMConfiguration, error) {
185187
cfg.Instance.AddressFamily = AddressFamilyIPv4
186188
}
187189

190+
cfg.Instance.ZoneLabelEnabled, err = getEnvBool(hcloudInstancesZoneLabelEnabled, true)
191+
if err != nil {
192+
errs = append(errs, err)
193+
}
194+
188195
// ---- Server Cache ----
189196

190197
cfg.ServerCache = ServerCacheConfiguration{

0 commit comments

Comments
 (0)