Skip to content

Commit

Permalink
Separate server ID from location for controller (#385)
Browse files Browse the repository at this point in the history
* Add support to execute the CSI driver without a server ID

* Rename environment variable to "HCLOUD_VOLUME_DEFAULT_LOCATION" and clean up

As requested by @apricote upstream rename the environment variable `HCLOUD_SERVER_OVERRIDE_LOCATION_NAME` to `HCLOUD_VOLUME_DEFAULT_LOCATION` as well as move the `metadataClient` to the `else` branch.
  • Loading branch information
NotTheEvilOne authored Feb 21, 2023
1 parent f5ed56b commit efdda91
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,23 @@ func main() {
os.Exit(1)
}

metadataClient := metadata.NewClient(metadata.WithInstrumentation(m.Registry()))
var location string

server, err := app.GetServer(logger, hcloudClient, metadataClient)
if err != nil {
level.Error(logger).Log(
"msg", "failed to fetch server",
"err", err,
)
os.Exit(1)
if s := os.Getenv("HCLOUD_VOLUME_DEFAULT_LOCATION"); s != "" {
location = s
} else {
metadataClient := metadata.NewClient(metadata.WithInstrumentation(m.Registry()))

server, err := app.GetServer(logger, hcloudClient, metadataClient)
if err != nil {
level.Error(logger).Log(
"msg", "failed to fetch server",
"err", err,
)
os.Exit(1)
}

location = server.Datacenter.Location.Name
}

volumeService := volumes.NewIdempotentService(
Expand All @@ -50,7 +58,7 @@ func main() {
controllerService := driver.NewControllerService(
log.With(logger, "component", "driver-controller-service"),
volumeService,
server.Datacenter.Location.Name,
location,
)
identityService := driver.NewIdentityService(
log.With(logger, "component", "driver-identity-service"),
Expand Down

0 comments on commit efdda91

Please sign in to comment.